Release #50
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: | |
| workflow_dispatch: | |
| 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_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' | |
| steps: | |
| - name: CI passed | |
| run: 'echo "CI workflow completed successfully (trigger: ${{ github.event_name }})"' | |
| release: | |
| name: Semantic Release | |
| runs-on: ubuntu-latest | |
| needs: check-ci | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.23' | |
| 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 | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.23' | |
| - 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@v5 | |
| 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 | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v6 | |
| 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@v5 | |
| 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@v5 | |
| with: | |
| name: rust-docs | |
| path: farp-rust/target/doc/ | |
| # Go discovery module release | |
| discovery-release: | |
| name: Discovery Module Release | |
| runs-on: ubuntu-latest | |
| needs: release | |
| steps: | |
| - name: Check out code | |
| uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Set up Go | |
| uses: actions/setup-go@v6 | |
| with: | |
| go-version: '1.23' | |
| - name: Check if discovery module exists | |
| id: check_discovery | |
| run: | | |
| if [ -f "discovery/go.mod" ]; then | |
| echo "exists=true" >> $GITHUB_OUTPUT | |
| else | |
| echo "exists=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Get latest tag | |
| if: steps.check_discovery.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: Test discovery base module | |
| if: steps.check_discovery.outputs.exists == 'true' | |
| working-directory: discovery | |
| run: | | |
| go mod tidy | |
| go vet ./... | |
| go test -v -race ./... | |
| - name: Test discovery sub-modules | |
| if: steps.check_discovery.outputs.exists == 'true' | |
| run: | | |
| for dir in discovery/redis discovery/consul discovery/etcd discovery/kubernetes discovery/mdns; do | |
| if [ -f "$dir/go.mod" ]; then | |
| echo "=== Testing $dir ===" | |
| cd "$dir" | |
| go mod tidy | |
| go vet ./... | |
| go test -v -race ./... | |
| cd "$GITHUB_WORKSPACE" | |
| fi | |
| done | |
| - name: Verify all discovery modules | |
| if: steps.check_discovery.outputs.exists == 'true' | |
| run: | | |
| for dir in discovery discovery/redis discovery/consul discovery/etcd discovery/kubernetes discovery/mdns; do | |
| if [ -f "$dir/go.mod" ]; then | |
| echo "=== Verifying $dir ===" | |
| cd "$dir" | |
| go mod verify | |
| cd "$GITHUB_WORKSPACE" | |
| fi | |
| done | |
| - name: Create discovery sub-module tags | |
| if: steps.check_discovery.outputs.exists == 'true' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| TAG="${{ steps.get_tag.outputs.tag }}" | |
| if [ "$TAG" = "v0.0.0" ]; then | |
| echo "No release tag found, skipping sub-module tagging" | |
| exit 0 | |
| fi | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git remote set-url origin "https://x-access-token:${GITHUB_TOKEN}@github.com/${{ github.repository }}.git" | |
| for dir in discovery discovery/redis discovery/consul discovery/etcd discovery/kubernetes discovery/mdns; do | |
| if [ -f "$dir/go.mod" ]; then | |
| SUB_TAG="${dir}/${TAG}" | |
| if git rev-parse "$SUB_TAG" >/dev/null 2>&1; then | |
| echo "Tag $SUB_TAG already exists, skipping" | |
| else | |
| echo "Creating tag $SUB_TAG" | |
| git tag "$SUB_TAG" | |
| git push origin "$SUB_TAG" | |
| fi | |
| fi | |
| done | |