ci: shard + cache for faster runs #165
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: Publish Docker Images | |
| on: | |
| push: | |
| branches: [main] | |
| paths-ignore: | |
| - 'docs/**' | |
| - 'k8s/**' | |
| - 'tests/**' | |
| - '**/*.md' | |
| pull_request: | |
| branches: [main] | |
| paths-ignore: | |
| - 'docs/**' | |
| - 'k8s/**' | |
| - 'tests/**' | |
| - '**/*.md' | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-docker | |
| cancel-in-progress: true | |
| jobs: | |
| discover: | |
| name: Discover functions | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix: ${{ steps.find.outputs.matrix }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Find functions from handler.json | |
| id: find | |
| run: | | |
| entries=$( | |
| for f in functions/*/handler.json; do | |
| [ -f "$f" ] || continue | |
| name=$(jq -r .name "$f") | |
| dir=$(basename "$(dirname "$f")") | |
| echo "{\"name\":\"$name\",\"dir\":\"$dir\"}" | |
| done | jq -s -c '.' | |
| ) | |
| echo "matrix={\"include\":$entries}" >> "$GITHUB_OUTPUT" | |
| echo "Discovered functions: $entries" | |
| build: | |
| name: Build ${{ matrix.name }}-fn | |
| needs: discover | |
| runs-on: ubuntu-latest | |
| if: ${{ needs.discover.outputs.matrix != '{"include":[]}' }} | |
| strategy: | |
| fail-fast: false | |
| matrix: ${{ fromJSON(needs.discover.outputs.matrix) }} | |
| env: | |
| REGISTRY: ghcr.io | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v5 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v6 | |
| # Pinned to v4: setup-node@v5 auto-detects pnpm via the | |
| # packageManager field in package.json and tries to cache the | |
| # store, which fails here because this workflow doesn't run | |
| # `pnpm install` on the runner — the store path doesn't exist | |
| # and v5 promotes the "missing path" warning to an error. | |
| # Sticking to v4 until v5's auto-cache can be opted out cleanly. | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| - name: Generate Dockerfile | |
| run: | | |
| node --experimental-strip-types scripts/generate.ts --only=${{ matrix.dir }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v4 | |
| - name: Log in to GHCR | |
| if: github.event_name != 'pull_request' | |
| uses: docker/login-action@v4 | |
| with: | |
| registry: ${{ env.REGISTRY }} | |
| username: ${{ github.actor }} | |
| password: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Docker meta | |
| id: meta | |
| uses: docker/metadata-action@v6 | |
| with: | |
| images: ${{ env.REGISTRY }}/${{ github.repository_owner }}/${{ matrix.name }}-fn | |
| tags: | | |
| type=ref,event=tag | |
| type=semver,pattern={{version}} | |
| type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) }} | |
| type=sha,format=short,prefix= | |
| - name: Build and push | |
| uses: docker/build-push-action@v7 | |
| with: | |
| context: . | |
| file: generated/${{ matrix.dir }}/Dockerfile | |
| push: ${{ github.event_name != 'pull_request' }} | |
| tags: ${{ steps.meta.outputs.tags }} | |
| cache-from: type=gha,scope=${{ matrix.name }} | |
| cache-to: type=gha,mode=max,scope=${{ matrix.name }} |