|
| 1 | +name: CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + pull_request: |
| 7 | + branches: [main] |
| 8 | + |
| 9 | +# Restrict all jobs to read-only by default; grant write only where needed. |
| 10 | +permissions: |
| 11 | + contents: read |
| 12 | + |
| 13 | +env: |
| 14 | + REGISTRY: ghcr.io |
| 15 | + IMAGE_NAME: ${{ github.repository }} |
| 16 | + |
| 17 | +jobs: |
| 18 | + test: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 22 | + |
| 23 | + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 |
| 24 | + with: |
| 25 | + node-version: '20' |
| 26 | + cache: 'npm' |
| 27 | + |
| 28 | + - run: npm ci |
| 29 | + - run: npm test |
| 30 | + |
| 31 | + build-and-push: |
| 32 | + needs: test |
| 33 | + runs-on: ubuntu-latest |
| 34 | + # Only push the image on pushes to main, not on PRs |
| 35 | + if: github.event_name == 'push' && github.ref == 'refs/heads/main' |
| 36 | + permissions: |
| 37 | + contents: read |
| 38 | + packages: write |
| 39 | + |
| 40 | + steps: |
| 41 | + - uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 |
| 42 | + |
| 43 | + - uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3 |
| 44 | + |
| 45 | + - name: Log in to GitHub Container Registry |
| 46 | + uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3 |
| 47 | + with: |
| 48 | + registry: ${{ env.REGISTRY }} |
| 49 | + username: ${{ github.actor }} |
| 50 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 51 | + |
| 52 | + - name: Extract image metadata |
| 53 | + id: meta |
| 54 | + uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5 |
| 55 | + with: |
| 56 | + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
| 57 | + tags: | |
| 58 | + type=sha,prefix= |
| 59 | + type=raw,value=latest,enable={{is_default_branch}} |
| 60 | +
|
| 61 | + - name: Build and push Docker image |
| 62 | + uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6 |
| 63 | + with: |
| 64 | + context: . |
| 65 | + push: true |
| 66 | + platforms: linux/amd64,linux/arm64 |
| 67 | + tags: ${{ steps.meta.outputs.tags }} |
| 68 | + labels: ${{ steps.meta.outputs.labels }} |
| 69 | + cache-from: type=gha |
| 70 | + cache-to: type=gha,mode=max |
0 commit comments