Skip to content

Commit 4c2f35e

Browse files
committed
fix: issues with docker build/publish not being triggered
1 parent 3a84de3 commit 4c2f35e

File tree

3 files changed

+58
-19
lines changed

3 files changed

+58
-19
lines changed
Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: Build and Publish Docker Image
22

33
on:
4-
release:
5-
types: [created]
4+
workflow_call:
5+
inputs:
6+
version:
7+
required: true
8+
type: string
69

710
env:
811
REGISTRY: ghcr.io
@@ -13,7 +16,7 @@ jobs:
1316
name: Build and Push Docker Image
1417
runs-on: ubuntu-latest
1518
permissions:
16-
contents: read
19+
contents: write
1720
packages: write
1821
steps:
1922
- name: Checkout repository
@@ -29,24 +32,44 @@ jobs:
2932
username: ${{ github.actor }}
3033
password: ${{ secrets.GITHUB_TOKEN }}
3134

32-
- name: Extract metadata
33-
id: meta
34-
uses: docker/metadata-action@v5
35-
with:
36-
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
37-
tags: |
38-
type=semver,pattern={{version}}
39-
type=semver,pattern={{major}}.{{minor}}
40-
type=semver,pattern={{major}}
41-
type=raw,value=latest
42-
4335
- name: Build and push Docker image
36+
id: docker_build
4437
uses: docker/build-push-action@v5
4538
with:
4639
context: .
4740
push: true
48-
tags: ${{ steps.meta.outputs.tags }}
49-
labels: ${{ steps.meta.outputs.labels }}
41+
tags: |
42+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ inputs.version }}
43+
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
44+
labels: |
45+
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
46+
org.opencontainers.image.revision=${{ github.sha }}
5047
cache-from: type=gha
5148
cache-to: type=gha,mode=max
5249
platforms: linux/amd64,linux/arm64
50+
51+
- name: Add Docker image info to release
52+
uses: actions/github-script@v7
53+
with:
54+
script: |
55+
const tag = 'v${{ inputs.version }}';
56+
const { data: release } = await github.rest.repos.getReleaseByTag({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
tag: tag
60+
});
61+
62+
const imageUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}/pkgs/container/${context.repo.repo}`;
63+
const body = `## Docker Image\n\n` +
64+
`**Published:** ✅\n` +
65+
`**Image:** \`ghcr.io/${context.repo.owner}/${context.repo.repo}:${{ inputs.version }}\`\n` +
66+
`**Latest:** \`ghcr.io/${context.repo.owner}/${context.repo.repo}:latest\`\n\n` +
67+
`Pull: \`docker pull ghcr.io/${context.repo.owner}/${context.repo.repo}:${{ inputs.version }}\`\n\n` +
68+
`[View on GitHub Container Registry](${imageUrl})`;
69+
70+
await github.rest.repos.createReleaseComment({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
release_id: release.id,
74+
body: body
75+
});

.github/workflows/release.yml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ permissions:
1212
jobs:
1313
release:
1414
runs-on: ubuntu-latest
15+
outputs:
16+
new-release-published: ${{ steps.semantic.outputs.new-release-published }}
17+
release-version: ${{ steps.semantic.outputs.release-version }}
1518
steps:
1619
- uses: actions/checkout@v4
1720
with:
@@ -21,8 +24,18 @@ jobs:
2124
with:
2225
node-version: "lts/*"
2326

24-
- run: npm install -g semantic-release conventional-changelog-conventionalcommits
27+
- run: npm install -g semantic-release conventional-changelog-conventionalcommits @semantic-release/exec
2528

26-
- env:
29+
- name: Create Release
30+
id: semantic
31+
env:
2732
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2833
run: npx semantic-release
34+
35+
docker:
36+
needs: release
37+
if: ${{ needs.release.outputs.new-release-published == 'true' }}
38+
uses: ./.github/workflows/docker-publish.yml
39+
with:
40+
version: ${{ needs.release.outputs.release-version }}
41+
secrets: inherit

.releaserc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
["@semantic-release/release-notes-generator", {
1212
"preset": "conventionalcommits"
1313
}],
14-
"@semantic-release/github"
14+
"@semantic-release/github",
15+
["@semantic-release/exec", {
16+
"successCmd": "echo 'new-release-published=true' >> $GITHUB_OUTPUT && echo 'release-version=${nextRelease.version}' >> $GITHUB_OUTPUT"
17+
}]
1518
]
1619
}

0 commit comments

Comments
 (0)