|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + push-to-registry: |
| 7 | + description: "Whether to push images to the container registry" |
| 8 | + required: false |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + |
| 12 | +env: |
| 13 | + REGISTRY: ghcr.io |
| 14 | + IMAGE_NAME: ${{ github.repository }} |
| 15 | + |
| 16 | +jobs: |
| 17 | + build: |
| 18 | + runs-on: ${{ matrix.runner }} |
| 19 | + strategy: |
| 20 | + fail-fast: false |
| 21 | + matrix: |
| 22 | + include: |
| 23 | + - platform: linux/amd64 |
| 24 | + arch: amd64 |
| 25 | + runner: ubuntu-latest |
| 26 | + test: true |
| 27 | + - platform: linux/arm64 |
| 28 | + arch: arm64 |
| 29 | + runner: ubuntu-24.04-arm |
| 30 | + test: true |
| 31 | + - platform: linux/arm/v7 |
| 32 | + arch: armv7 |
| 33 | + runner: ubuntu-24.04-arm |
| 34 | + test: false |
| 35 | + |
| 36 | + steps: |
| 37 | + - name: Checkout repository |
| 38 | + uses: actions/checkout@v4 |
| 39 | + |
| 40 | + - name: Set up QEMU |
| 41 | + uses: docker/setup-qemu-action@v3 |
| 42 | + |
| 43 | + - name: Set up Docker Buildx |
| 44 | + uses: docker/setup-buildx-action@v3 |
| 45 | + |
| 46 | + - name: Log in to the Container registry |
| 47 | + if: inputs.push-to-registry |
| 48 | + uses: docker/login-action@v3 |
| 49 | + with: |
| 50 | + registry: ${{ env.REGISTRY }} |
| 51 | + username: ${{ github.actor }} |
| 52 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 53 | + |
| 54 | + - name: Extract metadata (tags, labels) for Docker |
| 55 | + if: inputs.push-to-registry |
| 56 | + id: meta |
| 57 | + uses: docker/metadata-action@v5 |
| 58 | + with: |
| 59 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 60 | + |
| 61 | + - name: Build Docker image |
| 62 | + id: build |
| 63 | + uses: docker/build-push-action@v6 |
| 64 | + with: |
| 65 | + context: . |
| 66 | + platforms: ${{ matrix.platform }} |
| 67 | + labels: ${{ steps.meta.outputs.labels }} |
| 68 | + load: ${{ matrix.test }} |
| 69 | + tags: hypermind-test:${{ github.sha }} |
| 70 | + cache-from: type=gha |
| 71 | + cache-to: type=gha,mode=max |
| 72 | + |
| 73 | + - name: Run container for testing |
| 74 | + if: matrix.test |
| 75 | + run: docker run -d --name hypermind-test -p 3000:3000 hypermind-test:${{ github.sha }} |
| 76 | + |
| 77 | + - name: Wait for server to be ready |
| 78 | + if: matrix.test |
| 79 | + run: | |
| 80 | + for i in {1..30}; do |
| 81 | + if curl -sf http://localhost:3000/api/stats; then |
| 82 | + echo "Server is ready" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | + echo "Waiting for server... ($i/30)" |
| 86 | + sleep 1 |
| 87 | + done |
| 88 | + echo "Server failed to start" |
| 89 | + docker logs hypermind-test |
| 90 | + exit 1 |
| 91 | +
|
| 92 | + - name: Verify API response |
| 93 | + if: matrix.test |
| 94 | + run: | |
| 95 | + response=$(curl -sf http://localhost:3000/api/stats) |
| 96 | + echo "Response: $response" |
| 97 | + echo "$response" | jq -e '.count != null and .id != null' |
| 98 | +
|
| 99 | + - name: Cleanup test container |
| 100 | + if: always() && matrix.test |
| 101 | + run: docker rm -f hypermind-test || true |
| 102 | + |
| 103 | + - name: Push by digest |
| 104 | + if: inputs.push-to-registry |
| 105 | + id: push |
| 106 | + uses: docker/build-push-action@v6 |
| 107 | + with: |
| 108 | + context: . |
| 109 | + platforms: ${{ matrix.platform }} |
| 110 | + labels: ${{ steps.meta.outputs.labels }} |
| 111 | + outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true |
| 112 | + cache-from: type=gha |
| 113 | + |
| 114 | + - name: Export digest |
| 115 | + if: inputs.push-to-registry |
| 116 | + run: | |
| 117 | + mkdir -p ${{ runner.temp }}/digests |
| 118 | + digest="${{ steps.push.outputs.digest }}" |
| 119 | + touch "${{ runner.temp }}/digests/${digest#sha256:}" |
| 120 | +
|
| 121 | + - name: Upload digest |
| 122 | + if: inputs.push-to-registry |
| 123 | + uses: actions/upload-artifact@v4 |
| 124 | + with: |
| 125 | + name: digests-${{ matrix.arch }} |
| 126 | + path: ${{ runner.temp }}/digests/* |
| 127 | + if-no-files-found: error |
| 128 | + retention-days: 1 |
0 commit comments