From 7068f5aba59fc1d8ee6725d6590e2daaa7ca2509 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Fri, 19 Apr 2024 16:04:31 +0200 Subject: [PATCH] Add release workflow --- .github/workflows/release.yml | 88 +++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..820208c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,88 @@ +name: Release + +permissions: + contents: write + +on: + push: + tags: + - v[0-9]+.* + +jobs: + create-release: + name: Create GH release draft + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + + - name: Check that tag version and Cargo.toml version are the same + shell: bash + run: | + if ! grep -q "version = \"${{ github.ref_name }}\"" Cargo.toml; then + echo "version does not match Cargo.toml" >&2 + exit 1 + fi + + - name: Create the release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release create ${{ github.ref_name }} --draft --verify-tag --title ${{ github.ref_name }} + + upload-binary: + needs: create-release + name: ${{ matrix.target }} + runs-on: ${{ matrix.os }} + + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + use-cross: false + + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + use-cross: false + + - os: ubuntu-latest + target: aarch64-unknown-linux-gnu + use-cross: true + + - os: macos-latest + target: x86_64-apple-darwin + use-cross: false + + - os: macos-latest + target: aarch64-apple-darwin + use-cross: false + + env: + CARGO: cargo + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target }} + + - name: Install cross + if: matrix.use-cross + uses: taiki-e/install-action@v2 + with: + tool: cross + + - name: Overwrite build command env variable + if: matrix.use-cross + shell: bash + run: echo "CARGO=cross" >> $GITHUB_ENV + + - name: Build release binary + run: ${{ env.CARGO }} build --release --locked --target ${{ matrix.target }} + + - name: Upload the binary to the release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: gh release upload ${{ github.ref_name }} target/release/asciinema#asciinema-${{ matrix.target }}