Skip to content

.github/workflows/release.yml #14

.github/workflows/release.yml

.github/workflows/release.yml #14

Workflow file for this run

name: Release
on:
workflow_run:
workflows: ["CI"]
types:
- completed
branches:
- main
permissions:
contents: write
issues: write
pull-requests: write
jobs:
# Check that CI passed before proceeding
check-ci:
name: Check CI Status
runs-on: ubuntu-latest
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: CI passed
run: echo "CI workflow completed successfully"
release:
name: Semantic Release
runs-on: ubuntu-latest
needs: check-ci
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'
cache: true
- name: Set up Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Install semantic-release
run: |
npm install -g \
semantic-release@23 \
@semantic-release/changelog@6 \
@semantic-release/git@10 \
@semantic-release/github@10 \
@semantic-release/exec@6 \
conventional-changelog-conventionalcommits@7
- name: Run semantic release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: github-actions[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: github-actions[bot]
GIT_COMMITTER_EMAIL: github-actions[bot]@users.noreply.github.com
run: npx semantic-release
# Go library release artifacts
go-release:
name: Go Release Artifacts
runs-on: ubuntu-latest
needs: release
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v6
with:
go-version: '1.25'
- name: Get latest tag
id: get_tag
run: |
git fetch --tags
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=${TAG#v}" >> $GITHUB_OUTPUT
- name: Run tests one final time
run: go test -v ./...
- name: Verify module
run: |
go mod verify
go mod tidy
if [ -n "$(git status --porcelain go.mod go.sum)" ]; then
echo "go.mod or go.sum is not tidy"
exit 1
fi
- name: Build examples
run: |
cd examples/basic
go build -v -ldflags="-X 'github.com/xraph/farp.ProtocolVersion=${{ steps.get_tag.outputs.version }}'" -o farp-basic-example .
- name: Upload example binary
uses: actions/upload-artifact@v4
with:
name: go-example-binary
path: examples/basic/farp-basic-example
# Rust library release
rust-release:
name: Rust Release Artifacts
runs-on: ubuntu-latest
needs: release
if: github.event.workflow_run.conclusion == 'success'
steps:
- name: Check out code
uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0
- name: Check if Cargo.toml exists
id: check_cargo
run: |
if [ -f "farp-rust/Cargo.toml" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Set up Rust
if: steps.check_cargo.outputs.exists == 'true'
uses: dtolnay/rust-toolchain@stable
- name: Cache Rust dependencies
if: steps.check_cargo.outputs.exists == 'true'
uses: Swatinem/rust-cache@v2
with:
workspaces: farp-rust
- name: Get latest tag
if: steps.check_cargo.outputs.exists == 'true'
id: get_tag
run: |
git fetch --tags
TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "version=${TAG#v}" >> $GITHUB_OUTPUT
- name: Verify Cargo.toml version matches tag
if: steps.check_cargo.outputs.exists == 'true'
working-directory: farp-rust
run: |
CARGO_VERSION=$(grep "^version" Cargo.toml | head -1 | sed 's/.*"\(.*\)".*/\1/')
TAG_VERSION="${{ steps.get_tag.outputs.version }}"
echo "Cargo.toml version: $CARGO_VERSION"
echo "Git tag version: $TAG_VERSION"
if [ "$CARGO_VERSION" != "$TAG_VERSION" ]; then
echo "ERROR: Version mismatch! Cargo.toml has $CARGO_VERSION but tag is $TAG_VERSION"
echo "The semantic-release process should have updated Cargo.toml to match."
exit 1
fi
- name: Build Rust library
if: steps.check_cargo.outputs.exists == 'true'
working-directory: farp-rust
run: cargo build --release --all-features
- name: Run tests
if: steps.check_cargo.outputs.exists == 'true'
working-directory: farp-rust
run: cargo test --release --all-features
- name: Build documentation
if: steps.check_cargo.outputs.exists == 'true'
working-directory: farp-rust
run: cargo doc --release --all-features --no-deps
- name: Check if crates.io token is available
id: check_token
if: steps.check_cargo.outputs.exists == 'true'
run: |
if [ -n "${{ secrets.CARGO_REGISTRY_TOKEN }}" ]; then
echo "available=true" >> $GITHUB_OUTPUT
else
echo "available=false" >> $GITHUB_OUTPUT
fi
- name: Publish to crates.io
if: steps.check_cargo.outputs.exists == 'true' && steps.check_token.outputs.available == 'true'
working-directory: farp-rust
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
echo "Publishing farp v${{ steps.get_tag.outputs.version }} to crates.io..."
cargo publish --token ${{ secrets.CARGO_REGISTRY_TOKEN }} --allow-dirty
continue-on-error: true
- name: Upload Rust library artifacts
if: steps.check_cargo.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: rust-library
path: farp-rust/target/release/libfarp*
- name: Upload documentation artifacts
if: steps.check_cargo.outputs.exists == 'true'
uses: actions/upload-artifact@v4
with:
name: rust-docs
path: farp-rust/target/doc/