|
| 1 | +# .github/workflows/ci.yml |
1 | 2 | name: CI (Build & Push Docker + Auto Release) |
2 | 3 |
|
3 | 4 | on: |
|
12 | 13 | DOCKERFILE: ./Dockerfile |
13 | 14 |
|
14 | 15 | permissions: |
15 | | - contents: write |
| 16 | + contents: write # required to create and push tags |
16 | 17 |
|
17 | 18 | jobs: |
18 | 19 | build-and-push: |
@@ -42,12 +43,12 @@ jobs: |
42 | 43 | uses: docker/metadata-action@v5 |
43 | 44 | with: |
44 | 45 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} |
45 | | - # 👉 Only semver tags when triggered by a tag event |
| 46 | + # 👇 Only push semver tags on tag events |
46 | 47 | tags: | |
47 | 48 | type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/') }} |
48 | | - type=raw,value=latest,enable=${{ github.ref_name == 'main' && !startsWith(github.ref, 'refs/tags/') }} |
49 | | - type=ref,event=branch,enable=${{ !startsWith(github.ref, 'refs/tags/') }} |
50 | | - type=sha,enable=${{ !startsWith(github.ref, 'refs/tags/') }} |
| 49 | + type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }} |
| 50 | + type=ref,event=branch,enable=${{ github.ref == 'refs/heads/main' }} |
| 51 | + type=sha,enable=${{ github.ref == 'refs/heads/main' }} |
51 | 52 | labels: | |
52 | 53 | org.opencontainers.image.title=${{ github.event.repository.name }} |
53 | 54 | org.opencontainers.image.source=${{ github.repository }} |
|
71 | 72 |
|
72 | 73 | auto-release: |
73 | 74 | needs: build-and-push |
74 | | - if: contains(github.event.head_commit.message, '#release') |
| 75 | + # Fire only on main branch pushes containing '#release' |
| 76 | + if: ${{ github.ref == 'refs/heads/main' && contains(join(github.event.commits.*.message, ' '), '#release') }} |
75 | 77 | runs-on: ubuntu-latest |
76 | 78 | steps: |
77 | 79 | - uses: actions/checkout@v4 |
|
87 | 89 | VER=${LAST#v} |
88 | 90 | IFS='.' read -r MA MI PA <<<"$VER" |
89 | 91 | NEW_TAG="v$MA.$MI.$((PA+1))" |
90 | | - echo "New tag: $NEW_TAG" |
| 92 | + echo "Creating $NEW_TAG" |
91 | 93 | git config user.name "github-actions[bot]" |
92 | 94 | git config user.email "github-actions[bot]@users.noreply.github.com" |
93 | 95 | git tag -a "$NEW_TAG" -m "release $NEW_TAG" |
|
0 commit comments