Skip to content

Commit 3077f7b

Browse files
committed
[fix] Fix release github workflow
1 parent f4f9960 commit 3077f7b

File tree

1 file changed

+8
-34
lines changed

1 file changed

+8
-34
lines changed

.github/workflows/publish-release.yaml

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Publish flant/shell-operator image on hub.docker.com.
2-
# Build 'latest' tag when release is published.
2+
# Build 'latest' tag if started manually on default branch.
3+
# Build 'v*.*.*' and 'latest' tags when release is published.
34
name: Publish release image
45

56
on:
@@ -18,18 +19,15 @@ jobs:
1819
name: Check
1920
runs-on: ubuntu-latest
2021
outputs:
21-
run_publish: ${{ steps.check.outputs.run_publish }}
2222
image_tag: ${{ steps.check.outputs.image_tag }}
2323
additional_tag: ${{ steps.check.outputs.additional_tag }}
2424
steps:
2525
- uses: actions/github-script@v7
2626
id: check
2727
with:
2828
script: |
29-
const SKIP_LATEST_LABEL_NAME = 'skip/image/latest';
3029
const event = context.payload;
3130
const eventName = context.eventName;
32-
let runPublish = false;
3331
let imageTag = '';
3432
let additionalTag = ''; // Also push additional tag when building a released tag.
3533
@@ -39,40 +37,16 @@ jobs:
3937
return core.setFailed(`Detect manual execution for '${event.ref}'. Use only default branch. Skip 'publish latest image'.`);
4038
}
4139
console.log(`Detect manual execution for default branch. Run 'publish latest image'.`);
42-
runPublish = true;
4340
imageTag = 'latest';
4441
}
4542
46-
// Check for 'skip' label on pull request merge.
47-
if (eventName == 'pull_request' && event.action == 'closed') {
48-
if (!event.pull_request.merged) {
49-
return console.log(`PR ${event.number} not merged. Skip 'publish latest image'.`);
50-
}
51-
const hasSkipLabel = event.pull_request.labels.some(l => l.name === SKIP_LATEST_LABEL_NAME);
52-
if (hasSkipLabel) {
53-
return console.log(`Detect skip label '${SKIP_LATEST_LABEL_NAME}' on merged PR ${event.number}. Skip 'publish latest image'.`);
54-
}
55-
console.log(`No skip labels on merged PR ${event.number}. Run 'publish latest image'.`);
56-
runPublish = true;
57-
imageTag = 'latest';
58-
}
59-
60-
// Check if tag is pushed.
61-
if (eventName == 'push') {
62-
if (!event.ref.startsWith('refs/tags/')) {
63-
return console.log(`Detect non-release ref: ${event.ref}. Skip 'publish latest image'.`);
64-
}
65-
runPublish = true;
66-
imageTag = context.ref.replace('refs/tags/', '');
43+
if (eventName === 'release' && event.action === 'published') {
44+
console.log(`Detected release publication: ${event.release.tag_name}. Run 'publish latest image'.`);
45+
imageTag = event.release.tag_name;
6746
additionalTag = 'latest';
6847
}
6948
70-
console.log(`Outputs: run_publish=${runPublish} image_tag=${imageTag} additional_tag=${additionalTag}`);
71-
if (!runPublish) {
72-
console.log(`DEBUG: eventName=${eventName} action=${event.action} ref=${event.ref} merged=${event.pull_request && event.pull_request.merged} prLabels=${JSON.stringify(event.pull_request && event.pull_request.labels)}`)
73-
return console.log(`Skip 'publish latest image'.`);
74-
}
75-
core.setOutput('run_publish', runPublish.toString());
49+
console.log(`Outputs: image_tag=${imageTag} additional_tag=${additionalTag}`);
7650
core.setOutput('image_tag', imageTag);
7751
core.setOutput('additional_tag', additionalTag);
7852
@@ -81,7 +55,7 @@ jobs:
8155
runs-on: [ubuntu-latest]
8256
needs:
8357
- check
84-
if: needs.check.outputs.run_publish == 'true'
58+
if: ${{ needs.check.outputs.image_tag != '' }}
8559
steps:
8660
- uses: actions/checkout@v4
8761

@@ -166,7 +140,7 @@ jobs:
166140
echo "Ignore image for non-runnable platform ${platform}"
167141
echo " ${image}"
168142
echo "====================================="
169-
continue
143+
continue
170144
fi
171145
image=${GHCR_IO_IMAGE_NAME}@${digest}
172146
echo "====================================="

0 commit comments

Comments
 (0)