-
Notifications
You must be signed in to change notification settings - Fork 0
Automate release with GoReleaser #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
leynos
merged 5 commits into
main
from
codex/automate-release-workflow-with-github-actions
Aug 1, 2025
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2819329
Document Linux-only release
leynos e2dd357
Update release workflow and tests
leynos c280d27
Update release workflow and promote serde_yaml
leynos ddb5065
Merge branch 'main' into codex/automate-release-workflow-with-github-…
leynos 1d3c8dd
More liberal tagging pattern
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,116 +1,35 @@ | ||
|
|
||
| name: Release Binary | ||
| name: Release | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| # Match semantic version tags (e.g. v1.2.3, v10.11.12, v12.3.7-beta7) | ||
| - 'v*.*.*' | ||
|
|
||
| env: | ||
| REPO_NAME: ${{ github.event.repository.name }} | ||
|
|
||
| jobs: | ||
| build: | ||
| goreleaser: | ||
| runs-on: ubuntu-latest | ||
| strategy: | ||
| matrix: | ||
| include: | ||
| - os: linux | ||
| arch: x86_64 | ||
| target: x86_64-unknown-linux-gnu | ||
| ext: "" | ||
| - os: linux | ||
| arch: aarch64 | ||
| target: aarch64-unknown-linux-gnu | ||
| ext: "" | ||
| - os: windows | ||
| arch: x86_64 | ||
| target: x86_64-pc-windows-msvc | ||
| ext: ".exe" | ||
| - os: windows | ||
| arch: aarch64 | ||
| target: aarch64-pc-windows-msvc | ||
| ext: ".exe" | ||
| - os: macos | ||
| arch: x86_64 | ||
| target: x86_64-apple-darwin | ||
| ext: "" | ||
| - os: macos | ||
| arch: aarch64 | ||
| target: aarch64-apple-darwin | ||
| ext: "" | ||
| - os: freebsd | ||
| arch: x86_64 | ||
| target: x86_64-unknown-freebsd | ||
| ext: "" | ||
| - os: freebsd | ||
| arch: aarch64 | ||
| target: aarch64-unknown-freebsd | ||
| ext: "" | ||
| - os: openbsd | ||
| arch: x86_64 | ||
| target: x86_64-unknown-openbsd | ||
| ext: "" | ||
| - os: openbsd | ||
| arch: aarch64 | ||
| target: aarch64-unknown-openbsd | ||
| ext: "" | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: actions-rust-lang/setup-rust-toolchain@9d7e65c320fdb52dcd45ffaa68deb6c02c8754d9 | ||
| with: | ||
| toolchain: stable | ||
| profile: minimal | ||
| override: true | ||
| - name: Cache cross binary | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: ~/.cargo/bin/cross | ||
| key: cross-${{ runner.os }} | ||
| - name: Install cross | ||
| run: cargo install cross --git https://github.com/cross-rs/cross | ||
| - name: Cache cargo registry | ||
| uses: actions/cache@v4 | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| path: | | ||
| ~/.cargo/registry | ||
| ~/.cargo/git | ||
| target | ||
| key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | ||
| restore-keys: | | ||
| ${{ runner.os }}-cargo- | ||
| - name: Build release binary | ||
| run: cross +stable build --release --target ${{ matrix.target }} | ||
| - name: Prepare artifact | ||
| run: | | ||
| mkdir -p artifacts/${{ matrix.os }}-${{ matrix.arch }} | ||
| cp target/${{ matrix.target }}/release/${{ env.REPO_NAME }}${{ matrix.ext }} \ | ||
| artifacts/${{ matrix.os }}-${{ matrix.arch }}/${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} | ||
| sha256sum artifacts/${{ matrix.os }}-${{ matrix.arch }}/${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }} > \ | ||
| artifacts/${{ matrix.os }}-${{ matrix.arch }}/${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }}${{ matrix.ext }}.sha256 | ||
| - name: Upload release artifact | ||
| uses: actions/upload-artifact@v4 | ||
| fetch-depth: 0 | ||
| - name: Set up Rust | ||
| uses: dtolnay/rust-toolchain@stable | ||
| with: | ||
| name: ${{ env.REPO_NAME }}-${{ matrix.os }}-${{ matrix.arch }} | ||
| path: artifacts/${{ matrix.os }}-${{ matrix.arch }} | ||
|
|
||
| release: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| - uses: softprops/action-gh-release@v1 | ||
| toolchain: stable | ||
| targets: x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu | ||
| cache: cargo | ||
| - name: Set up Go | ||
| uses: actions/setup-go@v5 | ||
| with: | ||
| generate_release_notes: true | ||
| - uses: actions/download-artifact@v4 | ||
| go-version: '1.21' | ||
| - name: Run GoReleaser | ||
| uses: goreleaser/goreleaser-action@v5 | ||
| with: | ||
| path: artifacts | ||
| - run: | | ||
| for dir in artifacts/${{ env.REPO_NAME }}-*; do | ||
| for file in "$dir"/*; do | ||
| gh release upload "${{ github.ref_name }}" "$file" | ||
| done | ||
| done | ||
| distribution: goreleaser | ||
| # Use a fixed version to ensure reproducibility | ||
| version: v1.24.0 | ||
| args: release --clean | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| //! Utilities for inspecting GitHub workflow files. | ||
|
|
||
| use serde_yaml::Value; | ||
|
|
||
| /// Return `true` if the workflow steps include the `GoReleaser` action. | ||
| /// | ||
| /// # Errors | ||
| /// | ||
| /// Returns an error if the YAML cannot be parsed. | ||
| pub fn uses_goreleaser(yaml: &str) -> Result<bool, serde_yaml::Error> { | ||
| let doc: Value = serde_yaml::from_str(yaml)?; | ||
| let Some(jobs) = doc.get("jobs") else { | ||
| return Ok(false); | ||
| }; | ||
| let Some(map) = jobs.as_mapping() else { | ||
| return Ok(false); | ||
| }; | ||
| for job in map.values() { | ||
| let Some(steps) = job.get("steps") else { | ||
| continue; | ||
| }; | ||
| let Some(arr) = steps.as_sequence() else { | ||
| continue; | ||
| }; | ||
| for step in arr { | ||
| if step | ||
| .get("uses") | ||
| .and_then(|u| u.as_str()) | ||
| .is_some_and(|s| s.starts_with("goreleaser/goreleaser-action")) | ||
| { | ||
| return Ok(true); | ||
| } | ||
| } | ||
| } | ||
| Ok(false) | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| #![expect(clippy::expect_used, reason = "simplify test output")] | ||
|
leynos marked this conversation as resolved.
|
||
| use super::uses_goreleaser; | ||
|
|
||
| #[test] | ||
| fn detects_goreleaser() { | ||
| let yaml = r" | ||
| jobs: | ||
| goreleaser: | ||
| steps: | ||
| - uses: goreleaser/goreleaser-action@v5 | ||
| "; | ||
| assert!(uses_goreleaser(yaml).expect("parse")); | ||
| } | ||
|
|
||
| #[test] | ||
| fn missing_goreleaser() { | ||
| let yaml = "jobs: {}"; | ||
| assert!(!uses_goreleaser(yaml).expect("parse")); | ||
| } | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| Feature: Release workflow | ||
|
leynos marked this conversation as resolved.
|
||
|
|
||
| Scenario: goreleaser step present | ||
| Given the release workflow file | ||
| When it is parsed as YAML | ||
| Then the workflow uses goreleaser | ||
|
|
||
| Scenario: triggers on version tags | ||
| Given the release workflow file | ||
| When it is parsed as YAML | ||
| Then the workflow triggers on tags | ||
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.