|
| 1 | +name: release |
| 2 | + |
| 3 | +# Only do the release on x.y.z tags. |
| 4 | +on: |
| 5 | + push: |
| 6 | + tags: |
| 7 | + - "[0-9]+.[0-9]+.[0-9]+" |
| 8 | + |
| 9 | +permissions: {} |
| 10 | + |
| 11 | +jobs: |
| 12 | + # The create-release job runs purely to initialize the GitHub release itself, |
| 13 | + # and names the release after the `x.y.z` tag that was pushed. It's separate |
| 14 | + # from building the release so that we only create the release once. |
| 15 | + create-release: |
| 16 | + name: create-release |
| 17 | + runs-on: ubuntu-latest |
| 18 | + # We need this to be able to create releases. |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + persist-credentials: false |
| 25 | + - name: Get the release version from the tag |
| 26 | + if: env.VERSION == '' |
| 27 | + run: echo "VERSION=$REFNAME" >> $GITHUB_ENV |
| 28 | + env: |
| 29 | + REFNAME: ${{ github.ref_name }} |
| 30 | + - name: Check that tag version and Cargo.toml version are the same |
| 31 | + shell: bash |
| 32 | + run: | |
| 33 | + if ! grep -q "version = \"$VERSION\"" Cargo.toml; then |
| 34 | + echo "version does not match Cargo.toml" >&2 |
| 35 | + exit 1 |
| 36 | + fi |
| 37 | + - name: Create GitHub release |
| 38 | + env: |
| 39 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 40 | + run: gh release create $VERSION --draft --verify-tag --title $VERSION |
| 41 | + outputs: |
| 42 | + version: ${{ env.VERSION }} |
| 43 | + |
| 44 | + build-release: |
| 45 | + name: build-release |
| 46 | + needs: ['create-release'] |
| 47 | + runs-on: ${{ matrix.os }} |
| 48 | + # We need this to upload the artifacts |
| 49 | + permissions: |
| 50 | + contents: write |
| 51 | + strategy: |
| 52 | + fail-fast: false |
| 53 | + matrix: |
| 54 | + include: |
| 55 | + - build: linux-amd64 |
| 56 | + os: ubuntu-latest |
| 57 | + rust: stable |
| 58 | + target: x86_64-unknown-linux-musl |
| 59 | + # - build: linux-arm64 |
| 60 | + # os: ubuntu-latest |
| 61 | + # rust: stable |
| 62 | + # target: aarch64-unknown-linux-musl |
| 63 | + steps: |
| 64 | + - uses: actions/checkout@v4 |
| 65 | + with: |
| 66 | + persist-credentials: false |
| 67 | + - uses: dtolnay/rust-toolchain@e97e2d8cc328f1b50210efc529dca0028893a2d9 |
| 68 | + with: |
| 69 | + toolchain: ${{ matrix.rust }} |
| 70 | + target: ${{ matrix.target }} |
| 71 | + |
| 72 | + - name: Build release binary |
| 73 | + shell: bash |
| 74 | + run: | |
| 75 | + cargo build --workspace --target ${{ matrix.target }} --release |
| 76 | + echo "BIN=$PWD/target/${{ matrix.target }}/release/randstream" >> $GITHUB_ENV |
| 77 | +
|
| 78 | + - name: Get the release version from the tag |
| 79 | + run: echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 80 | + env: |
| 81 | + VERSION: ${{ needs.create-release.outputs.version }} |
| 82 | + |
| 83 | + - name: Determine archive name |
| 84 | + shell: bash |
| 85 | + run: | |
| 86 | + echo "VERSION=$VERSION" >> $GITHUB_ENV |
| 87 | + echo "ARCHIVE=randstream-$VERSION-${{ matrix.target }}" >> $GITHUB_ENV |
| 88 | + env: |
| 89 | + VERSION: ${{ needs.create-release.outputs.version }} |
| 90 | + |
| 91 | + - name: Build archive |
| 92 | + shell: bash |
| 93 | + run: | |
| 94 | + mkdir archive |
| 95 | + cd archive |
| 96 | + cp $BIN . |
| 97 | + cp ../README.md ../LICENSE . |
| 98 | + tar czf "../$ARCHIVE.tar.gz" . |
| 99 | + cd .. |
| 100 | + shasum -a 256 "$ARCHIVE.tar.gz" > "$ARCHIVE.tar.gz.sha256" |
| 101 | + echo "ASSET=$ARCHIVE.tar.gz" >> $GITHUB_ENV |
| 102 | + echo "ASSET_SUM=$ARCHIVE.tar.gz.sha256" >> $GITHUB_ENV |
| 103 | +
|
| 104 | + - name: Upload release archive |
| 105 | + env: |
| 106 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 107 | + shell: bash |
| 108 | + run: gh release upload "$VERSION" $ASSET $ASSET_SUM |
0 commit comments