release: 0.2.0 (#1) #2
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| permissions: | |
| contents: read | |
| jobs: | |
| verify-version: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| release_tag: ${{ steps.version.outputs.release_tag }} | |
| release_version: ${{ steps.version.outputs.release_version }} | |
| steps: | |
| - name: Check out tagged revision | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Verify tag matches Cargo.toml and main ancestry | |
| id: version | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| release_tag="${GITHUB_REF_NAME}" | |
| [[ "$release_tag" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] || { | |
| echo "invalid release tag: $release_tag" >&2 | |
| exit 1 | |
| } | |
| release_version="${release_tag#v}" | |
| cargo_version="$(python3 - <<'PY' | |
| from pathlib import Path | |
| import tomllib | |
| data = tomllib.loads(Path('Cargo.toml').read_text()) | |
| print(data['package']['version']) | |
| PY | |
| )" | |
| [[ "$release_version" == "$cargo_version" ]] || { | |
| echo "release tag $release_tag does not match Cargo.toml version $cargo_version" >&2 | |
| exit 1 | |
| } | |
| git fetch origin main | |
| git merge-base --is-ancestor "$GITHUB_SHA" origin/main || { | |
| echo "tag commit is not merged into main" >&2 | |
| exit 1 | |
| } | |
| echo "release_tag=$release_tag" >> "$GITHUB_OUTPUT" | |
| echo "release_version=$release_version" >> "$GITHUB_OUTPUT" | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: verify-version | |
| steps: | |
| - name: Check out verified tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.verify-version.outputs.release_tag }} | |
| - name: Install stable Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Run cargo test | |
| run: cargo test | |
| build: | |
| needs: | |
| - verify-version | |
| - test | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - os: macos-latest | |
| target: aarch64-apple-darwin | |
| suffix: "" | |
| - os: windows-latest | |
| target: x86_64-pc-windows-msvc | |
| suffix: ".exe" | |
| - os: ubuntu-latest | |
| target: x86_64-unknown-linux-musl | |
| suffix: "" | |
| steps: | |
| - name: Check out verified tag | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: ${{ needs.verify-version.outputs.release_tag }} | |
| - name: Install stable Rust target | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Install musl tooling | |
| if: matrix.target == 'x86_64-unknown-linux-musl' | |
| run: sudo apt-get update && sudo apt-get install -y musl-tools | |
| - name: Build release binary | |
| shell: bash | |
| env: | |
| CC_x86_64_unknown_linux_musl: musl-gcc | |
| run: cargo build --release --target "${{ matrix.target }}" | |
| - name: Rename release binary | |
| id: asset | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| asset_name="electrotest-v${{ needs.verify-version.outputs.release_version }}-${{ matrix.target }}${{ matrix.suffix }}" | |
| mkdir -p dist | |
| cp "target/${{ matrix.target }}/release/electrotest${{ matrix.suffix }}" "dist/${asset_name}" | |
| echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT" | |
| - name: Upload release asset | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.asset.outputs.asset_name }} | |
| path: dist/${{ steps.asset.outputs.asset_name }} | |
| checksums: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - verify-version | |
| - build | |
| steps: | |
| - name: Download release binaries | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: electrotest-v${{ needs.verify-version.outputs.release_version }}-* | |
| path: release-assets | |
| merge-multiple: true | |
| - name: Generate SHA256SUMS.txt | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| find release-assets -maxdepth 1 -type f -print0 | sort -z | xargs -0 sha256sum > release-assets/SHA256SUMS.txt | |
| - name: Upload checksum artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-checksums | |
| path: release-assets/SHA256SUMS.txt | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: | |
| - verify-version | |
| - build | |
| - checksums | |
| permissions: | |
| contents: write | |
| env: | |
| GITHUB_TOKEN: ${{ github.token }} | |
| GH_TOKEN: ${{ github.token }} | |
| steps: | |
| - name: Download release binaries | |
| uses: actions/download-artifact@v4 | |
| with: | |
| pattern: electrotest-v${{ needs.verify-version.outputs.release_version }}-* | |
| path: release-assets | |
| merge-multiple: true | |
| - name: Download checksum artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: release-checksums | |
| path: release-assets | |
| - name: Publish GitHub Release assets | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| release_tag="${{ needs.verify-version.outputs.release_tag }}" | |
| gh auth status | |
| gh release view "$release_tag" >/dev/null 2>&1 || \ | |
| gh release create "$release_tag" --title "$release_tag" --generate-notes | |
| find release-assets -maxdepth 1 -type f -print0 | \ | |
| xargs -0 gh release upload "$release_tag" --clobber |