fix: strict tag check on cliff.toml and tag fetch before git cliff #391
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: Build and Test for all targets | |
| on: | |
| push: | |
| tags: ['v*.*.*'] # run only when a tag like v1.2.3 is pushed | |
| workflow_dispatch: | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| # Generate changelog (runs once) | |
| changelog: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| outputs: | |
| content: ${{ steps.changelog.outputs.content }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Ensure all tags are present | |
| run: git fetch --tags --force --prune | |
| - name: Generate changelog | |
| uses: orhun/git-cliff-action@v4 | |
| id: changelog | |
| with: | |
| config: cliff.toml | |
| # Use the latest tag vs previous tag automatically | |
| args: --latest --strip header --output CHANGELOG.md | |
| env: | |
| GITHUB_REPOSITORY: ${{ github.repository }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| GITHUB_REF: ${{ github.ref }} | |
| # Test the code | |
| test: | |
| runs-on: ubuntu-latest | |
| needs: changelog | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cargo | |
| uses: Swatinem/rust-cache@v2 | |
| with: { cache-on-failure: true } | |
| - name: cargo test | |
| run: cargo test --locked | |
| # Prepare matrix of targets from archs file | |
| matrix: | |
| runs-on: ubuntu-latest | |
| needs: test | |
| outputs: | |
| targets: ${{ steps.set-matrix.outputs.targets }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - id: set-matrix | |
| name: Read targets from archs | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| targets=$(grep -v '^\s*$' archs | jq -R -s -c 'split("\n") | map(select(length>0))') | |
| echo "targets=$targets" >> "$GITHUB_OUTPUT" | |
| # Build binaries for all targets using cross | |
| build: | |
| runs-on: ubuntu-latest | |
| needs: matrix | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: ${{ fromJSON(needs.matrix.outputs.targets) }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Install Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Cache cross binary | |
| id: cache-cross | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/.cargo/bin/cross | |
| key: cross-${{ runner.os }}-0.2.5 | |
| - name: Install cross ( pinned version for reproducibility ) | |
| if: steps.cache-cross.outputs.cache-hit != 'true' | |
| run: cargo install cross --version 0.2.5 | |
| - name: Build release | |
| run: cross build --release --locked --target ${{ matrix.target }} | |
| - name: Prepare conventional artifact name | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| outdir="artifacts" | |
| mkdir -p "$outdir" | |
| case "${{ matrix.target }}" in | |
| *-pc-windows-*) src="target/${{ matrix.target }}/release/mostro-cli.exe"; dst="$outdir/mostro-cli-${{ matrix.target }}.exe";; | |
| *) src="target/${{ matrix.target }}/release/mostro-cli"; dst="$outdir/mostro-cli-${{ matrix.target }}";; | |
| esac | |
| cp "$src" "$dst" | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: artifact-${{ matrix.target }} | |
| path: artifacts/* | |
| # Create release with all artifacts | |
| release: | |
| runs-on: ubuntu-latest | |
| needs: [changelog, build] | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| - name: Generate checksums manifest | |
| shell: bash | |
| run: | | |
| set -euo pipefail | |
| shopt -s globstar nullglob | |
| # Compute SHA256 for all produced binaries | |
| : > manifest.txt | |
| for f in $(ls -1 artifact-*/mostro-cli* | sort); do | |
| sha256sum "$f" >> manifest.txt | |
| done | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ github.ref_name }} | |
| name: Release ${{ github.ref_name }} | |
| body: ${{ needs.changelog.outputs.content }} | |
| files: | | |
| artifact-*/mostro-cli* | |
| manifest.txt | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |