|
1 | 1 | name: ci |
| 2 | + |
| 3 | +# Trigger configuration |
2 | 4 | on: |
| 5 | + # Run on pushes to master branch and tags |
3 | 6 | push: |
| 7 | + branches: |
| 8 | + - master |
| 9 | + tags: |
| 10 | + - 'v*' |
| 11 | + # Run on PRs targeting master branch |
4 | 12 | pull_request: |
5 | | - create: |
6 | | - tags: '*' |
| 13 | + branches: |
| 14 | + - master |
| 15 | + # Support manual trigger from Actions tab |
| 16 | + workflow_dispatch: |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + packages: write # Needed for pushing to container registries |
7 | 21 |
|
8 | 22 | jobs: |
9 | 23 | build: |
10 | 24 | name: Build |
11 | 25 | runs-on: ubuntu-latest |
12 | 26 | steps: |
13 | | - - uses: actions/checkout@v4 |
14 | | - - uses: actions/setup-go@v5 |
| 27 | + - name: Checkout code |
| 28 | + uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + fetch-depth: 0 # Needed for proper versioning |
| 31 | + |
| 32 | + - name: Set up Go |
| 33 | + uses: actions/setup-go@v5 |
15 | 34 | with: |
16 | 35 | go-version: '^1.22' |
17 | | - - run: go install github.com/mattn/goveralls@latest |
18 | | - - run: | |
19 | | - make test |
20 | | - make |
21 | | - make build.docker |
22 | | - - run: goveralls -coverprofile=profile.cov -service=github |
| 36 | + cache: true |
| 37 | + |
| 38 | + - name: Run tests |
| 39 | + run: make test |
| 40 | + |
| 41 | + - name: Build binary |
| 42 | + run: make |
| 43 | + |
| 44 | + - name: Set up QEMU |
| 45 | + uses: docker/setup-qemu-action@v3 |
| 46 | + |
| 47 | + - name: Set up Docker Buildx |
| 48 | + uses: docker/setup-buildx-action@v3 |
| 49 | + with: |
| 50 | + install: true |
| 51 | + |
| 52 | + - name: Setup code coverage tooling |
| 53 | + run: go install github.com/mattn/goveralls@latest |
| 54 | + |
| 55 | + - name: Submit code coverage |
| 56 | + run: goveralls -coverprofile=profile.cov -service=github |
23 | 57 | env: |
24 | 58 | COVERALLS_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
25 | | - - name: Push the latest Docker image |
26 | | - run: | |
27 | | - echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin |
28 | | - VERSION=latest make build.push |
29 | | - if: github.ref == 'refs/heads/master' |
30 | | - - name: Push the release Docker image |
31 | | - run: | |
32 | | - echo ${{ secrets.DOCKERHUB_PASSWORD }} | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin |
33 | | - VERSION=${{ github.ref_name }} make build.push |
34 | | - if: startsWith(github.ref, 'refs/tags/') |
| 59 | + |
| 60 | + - name: Docker metadata |
| 61 | + id: meta |
| 62 | + uses: docker/metadata-action@v5 |
| 63 | + with: |
| 64 | + images: | |
| 65 | + mikkeloscar/pdb-controller |
| 66 | + ghcr.io/${{ github.repository }} |
| 67 | + # Generate tags for: |
| 68 | + # - latest for master branch |
| 69 | + # - git tags |
| 70 | + # - branch name for other branches |
| 71 | + tags: | |
| 72 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }} |
| 73 | + type=semver,pattern={{version}} |
| 74 | + type=ref,event=branch |
| 75 | + |
| 76 | + - name: Login to Docker Hub |
| 77 | + if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') |
| 78 | + uses: docker/login-action@v3 |
| 79 | + with: |
| 80 | + # Note: You need to add these secrets in your GitHub repository settings |
| 81 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 82 | + password: ${{ secrets.DOCKERHUB_PASSWORD }} |
| 83 | + |
| 84 | + - name: Login to GitHub Container Registry |
| 85 | + if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') |
| 86 | + uses: docker/login-action@v3 |
| 87 | + with: |
| 88 | + registry: ghcr.io |
| 89 | + username: ${{ github.actor }} |
| 90 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 91 | + |
| 92 | + - name: Build and push Docker image |
| 93 | + if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/') |
| 94 | + uses: docker/bake-action@v4 |
| 95 | + with: |
| 96 | + files: ./docker-bake.hcl |
| 97 | + push: true |
| 98 | + set: | |
| 99 | + *.tags=${{ steps.meta.outputs.tags }} |
| 100 | + *.platforms=linux/amd64,linux/arm64 |
0 commit comments