Skip to content

Commit a0cfad1

Browse files
authored
feat: Add semantic release release-created (#7)
1 parent 71e8445 commit a0cfad1

4 files changed

Lines changed: 67 additions & 6 deletions

File tree

.github/workflows/release.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,10 @@ jobs:
1212
node-version: '20'
1313
secrets: inherit
1414

15+
confirm-release:
16+
needs: release
17+
if: needs.release.outputs.release-created == 'true'
18+
runs-on: ubuntu-latest
19+
steps:
20+
- run: echo "A new release was created!"
21+

.github/workflows/semantic-release.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
required: false
99
default: '24'
1010
type: string
11+
outputs:
12+
release-created:
13+
description: 'Whether semantic-release created a new release/tag'
14+
value: ${{ jobs.release.outputs.release-created }}
1115

1216
permissions:
1317
contents: write
@@ -17,10 +21,17 @@ permissions:
1721
jobs:
1822
release:
1923
runs-on: ubuntu-latest
24+
concurrency:
25+
group: semantic-release-${{ github.repository }}
26+
cancel-in-progress: false
27+
outputs:
28+
release-created: ${{ steps.release-check.outputs.release-created }}
2029

2130
steps:
2231
- name: Checkout code
2332
uses: actions/checkout@v4
33+
with:
34+
fetch-depth: 0
2435

2536
- name: Set up Node.js
2637
uses: actions/setup-node@v4
@@ -36,8 +47,35 @@ jobs:
3647
@semantic-release/changelog \
3748
@semantic-release/github
3849
50+
- name: Capture tags before release
51+
run: |
52+
git fetch --tags --force
53+
git tag -l | sort > /tmp/tags-before.txt
54+
3955
- name: Run Semantic Release
4056
env:
4157
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4258
run: semantic-release
4359

60+
- name: Capture tags after release
61+
run: |
62+
git fetch --tags --force
63+
git tag -l | sort > /tmp/tags-after.txt
64+
65+
- name: Determine whether release was created
66+
id: release-check
67+
run: |
68+
head_sha=$(git rev-parse HEAD)
69+
new_tags=$(comm -13 /tmp/tags-before.txt /tmp/tags-after.txt)
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"
81+

.github/workflows/semver-container.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,10 @@ on:
1212
required: false
1313
default: 'ghcr.io'
1414
type: string
15-
release-name-prefix:
16-
description: 'Prefix for the GitHub Release title'
17-
required: false
18-
default: ''
19-
type: string
2015

2116
env:
2217
image-name: ${{ inputs.image-name }}
2318
registry: ${{ inputs.registry }}
24-
release-name-prefix: ${{ inputs.release-name-prefix }}
2519

2620
jobs:
2721
version-tag:

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)