|
| 1 | +name: build |
| 2 | +on: |
| 3 | + workflow_call: |
| 4 | + inputs: |
| 5 | + push-image: |
| 6 | + required: false |
| 7 | + type: boolean |
| 8 | + default: false |
| 9 | + create-release: |
| 10 | + required: false |
| 11 | + type: boolean |
| 12 | + default: false |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + IMAGE_NAME: ${{ github.repository }}-server |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + permissions: |
| 20 | + contents: write |
| 21 | + packages: write |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + - uses: nixbuild/nix-quick-install-action@v34 |
| 25 | + with: |
| 26 | + nix_conf: | |
| 27 | + keep-env-derivations = true |
| 28 | + keep-outputs = true |
| 29 | + - name: Restore and save Nix store |
| 30 | + uses: nix-community/cache-nix-action@v6 |
| 31 | + with: |
| 32 | + primary-key: nix-${{ runner.os }}-${{ hashFiles('**/*.nix', '**/flake.lock') }} |
| 33 | + restore-prefixes-first-match: nix-${{ runner.os }}- |
| 34 | + gc-max-store-size-linux: 5G |
| 35 | + purge: true |
| 36 | + purge-prefixes: nix-${{ runner.os }}- |
| 37 | + purge-created: 0 |
| 38 | + purge-last-accessed: 0 |
| 39 | + purge-primary-key: never |
| 40 | + - name: Run checks |
| 41 | + run: nix flake check --impure |
| 42 | + - name: Build binaries |
| 43 | + run: nix build --impure .#webhook-relay |
| 44 | + - name: Build image |
| 45 | + run: nix build --impure .#server-image |
| 46 | + - name: Prepare release artifacts |
| 47 | + if: inputs.create-release |
| 48 | + run: | |
| 49 | + mkdir -p release-artifacts |
| 50 | +
|
| 51 | + # Linux binaries |
| 52 | + cp result/bin/x86_64-unknown-linux-musl/server release-artifacts/server-x86_64-linux |
| 53 | + cp result/bin/x86_64-unknown-linux-musl/client release-artifacts/client-x86_64-linux |
| 54 | + cp result/bin/x86_64-unknown-linux-musl/mcp-client release-artifacts/mcp-client-x86_64-linux |
| 55 | +
|
| 56 | + # Windows binaries |
| 57 | + cp result/bin/x86_64-pc-windows-gnu/server.exe release-artifacts/server-x86_64-windows.exe |
| 58 | + cp result/bin/x86_64-pc-windows-gnu/client.exe release-artifacts/client-x86_64-windows.exe |
| 59 | + cp result/bin/x86_64-pc-windows-gnu/mcp-client.exe release-artifacts/mcp-client-x86_64-windows.exe |
| 60 | +
|
| 61 | + # macOS binaries |
| 62 | + cp result/bin/x86_64-apple-darwin/server release-artifacts/server-x86_64-darwin |
| 63 | + cp result/bin/x86_64-apple-darwin/client release-artifacts/client-x86_64-darwin |
| 64 | + cp result/bin/x86_64-apple-darwin/mcp-client release-artifacts/mcp-client-x86_64-darwin |
| 65 | + - name: Create GitHub Release |
| 66 | + if: inputs.create-release |
| 67 | + uses: softprops/action-gh-release@v2 |
| 68 | + with: |
| 69 | + files: release-artifacts/* |
| 70 | + generate_release_notes: true |
| 71 | + - name: Generate image tag |
| 72 | + if: inputs.push-image |
| 73 | + id: image-info |
| 74 | + run: | |
| 75 | + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then |
| 76 | + TAG="${{ github.ref_name }}" |
| 77 | + else |
| 78 | + TAG="latest" |
| 79 | + fi |
| 80 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 81 | + - name: Load and tag image |
| 82 | + if: inputs.push-image |
| 83 | + run: | |
| 84 | + IMAGE_ID=$(podman load --quiet < ./result | cut -d ' ' -f 3) |
| 85 | + podman tag "$IMAGE_ID" "${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.image-info.outputs.tag }}" |
| 86 | + - name: Push image to GHCR |
| 87 | + if: inputs.push-image |
| 88 | + uses: redhat-actions/push-to-registry@v2 |
| 89 | + with: |
| 90 | + image: ${{ env.IMAGE_NAME }} |
| 91 | + tags: ${{ steps.image-info.outputs.tag }} |
| 92 | + registry: ${{ env.REGISTRY }} |
| 93 | + username: ${{ github.actor }} |
| 94 | + password: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments