Skip to content

Commit a82bc33

Browse files
committed
feat: Enhance semantic-release workflow with concurrency and output handling
1 parent 000c3bc commit a82bc33

2 files changed

Lines changed: 37 additions & 5 deletions

File tree

.github/workflows/semantic-release.yml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ permissions:
2121
jobs:
2222
release:
2323
runs-on: ubuntu-latest
24+
concurrency:
25+
group: semantic-release-${{ github.repository }}
26+
cancel-in-progress: false
2427
outputs:
2528
release-created: ${{ steps.release-check.outputs.release-created }}
2629

@@ -62,10 +65,17 @@ jobs:
6265
- name: Determine whether release was created
6366
id: release-check
6467
run: |
68+
head_sha=$(git rev-parse HEAD)
6569
new_tags=$(comm -13 /tmp/tags-before.txt /tmp/tags-after.txt)
66-
if [ -n "$new_tags" ]; then
67-
echo "release-created=true" >> "$GITHUB_OUTPUT"
68-
else
69-
echo "release-created=false" >> "$GITHUB_OUTPUT"
70-
fi
70+
release_created=false
71+
72+
while IFS= read -r tag; do
73+
tag_sha=$(git rev-parse "${tag}^{}" 2>/dev/null || git rev-parse "$tag")
74+
if [ "$tag_sha" = "$head_sha" ]; then
75+
release_created=true
76+
break
77+
fi
78+
done <<< "$new_tags"
79+
80+
echo "release-created=$release_created" >> "$GITHUB_OUTPUT"
7181

docs/semantic-release.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@ Reusable workflow that runs [semantic-release](https://github.com/semantic-relea
88
|----------------|----------|---------|----------------------------|
99
| `node-version` | No | `'24'` | Node.js version to use. |
1010

11+
## Outputs
12+
13+
| Output | Description |
14+
|-------------------|----------------------------------------------------------|
15+
| `release-created` | `'true'` if a new release was created, `'false'` if not. |
16+
17+
Use this to conditionally run downstream jobs (e.g. re-tag a container, publish to PyPI) only when a release actually happened:
18+
19+
```yaml
20+
jobs:
21+
release:
22+
uses: health-informatics-uon/workflows/.github/workflows/semantic-release.yml@main
23+
secrets: inherit
24+
25+
publish:
26+
needs: release
27+
if: needs.release.outputs.release-created == 'true'
28+
...
29+
```
30+
31+
> **Note:** If the workflow itself errors, `release-created` will be an empty string rather than `'false'`. Always use `== 'true'` rather than `!= 'false'` in conditions.
32+
1133
## Secrets
1234

1335
- `GITHUB_TOKEN` — Pass with `secrets: inherit` (or set explicitly) so the workflow can create releases and comment on PRs/issues.

0 commit comments

Comments
 (0)