Skip to content

Commit bf6c99c

Browse files
authored
Improve release workflow (#1227)
2 parents f9c0413 + 199f665 commit bf6c99c

2 files changed

Lines changed: 60 additions & 8 deletions

File tree

.github/workflows/release.yml

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,67 @@ on:
55
branches:
66
- main
77

8+
concurrency:
9+
group: release
10+
cancel-in-progress: false
11+
812
permissions:
913
id-token: write # Required for OIDC. See https://docs.npmjs.com/trusted-publishers#step-2-configure-your-cicd-workflow
1014
contents: read
1115

1216
jobs:
17+
release-decision:
18+
runs-on: ubuntu-latest
19+
outputs:
20+
should-release: ${{ steps.decision.outputs.should-release }}
21+
steps:
22+
- name: Decide release
23+
id: decision
24+
env:
25+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
COMMITTER_EMAIL: ${{ github.event.head_commit.committer.email }}
27+
COMMITTER_NAME: ${{ github.event.head_commit.committer.name }}
28+
COMMIT_SHA: ${{ github.sha }}
29+
shell: bash
30+
run: |
31+
echo "Commit: $COMMIT_SHA"
32+
echo "Committer: $COMMITTER_NAME <$COMMITTER_EMAIL>"
33+
34+
# Skip if commit is from release bot (avoid infinite loop)
35+
if [[ "$COMMITTER_EMAIL" == '[email protected]' ]]; then
36+
echo "→ Skipping: commit is from release bot"
37+
echo "should-release=false" >> "$GITHUB_OUTPUT"
38+
exit 0
39+
fi
40+
41+
# Check if commit comes from a PR merged to main
42+
PR_JSON=$(gh pr list \
43+
--repo "${{ github.repository }}" \
44+
--search "$COMMIT_SHA is:merged base:main" \
45+
--state merged \
46+
--json number,title,url)
47+
48+
PR_COUNT=$(echo "$PR_JSON" | jq 'length')
49+
50+
if [[ "$PR_COUNT" -gt 0 ]]; then
51+
echo "$PR_JSON" | jq -r '.[] | "→ Found PR #\(.number): \(.title)"'
52+
echo "→ Release will proceed"
53+
echo "should-release=true" >> "$GITHUB_OUTPUT"
54+
else
55+
echo "→ No merged PR found for this commit"
56+
echo "should-release=false" >> "$GITHUB_OUTPUT"
57+
fi
58+
1359
changelog:
60+
needs: release-decision
61+
if: ${{ needs.release-decision.outputs.should-release == 'true' }}
1462
uses: "./.github/workflows/changelog.yml"
1563
test:
64+
needs: changelog
65+
if: ${{ needs.changelog.outputs.release-type != 'no-release' }}
1666
uses: "OpenTermsArchive/engine/.github/workflows/test.yml@main"
1767
release:
18-
needs: [ changelog, test ]
19-
if: needs.changelog.outputs.release-type != 'no-release'
68+
needs: test
2069
runs-on: ubuntu-latest
2170
steps:
2271
- name: Checkout
@@ -50,8 +99,7 @@ jobs:
5099
git commit -m "Release v${{ steps.release-changelog.outputs.version }}"
51100
git tag v${{ steps.release-changelog.outputs.version }}
52101
53-
# Publish to NPM first, before pushing to repository
54-
# If this fails, no changes are pushed to the repository, ensuring consistency
102+
# Publish to NPM first, before pushing to repository. If this fails, no changes are pushed to the repository, ensuring consistency
55103
- name: Publish to NPM public repository
56104
run: npm publish --provenance
57105

@@ -60,23 +108,23 @@ jobs:
60108
run: git push origin main && git push --tags
61109

62110
- name: Create GitHub release
63-
uses: softprops/action-gh-release@v2
111+
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2
64112
with:
65113
tag_name: v${{ steps.release-changelog.outputs.version }}
66114
body: ${{ steps.release-changelog.outputs.content }}
67115
token: ${{ secrets.RELEASE_BOT_GITHUB_TOKEN }}
68116

69117
- name: Trigger documentation deploy
70-
uses: peter-evans/repository-dispatch@v2
118+
uses: peter-evans/repository-dispatch@bf47d102fdb849e755b0b0023ea3e81a44b6f570 # v2
71119
with:
72120
token: ${{ secrets.TRIGGER_DOCS_DEPLOY_TOKEN }}
73121
event-type: engine-release
74122
repository: OpenTermsArchive/docs
75123
client-payload: '{"version": "v${{ steps.release-changelog.outputs.version }}"}'
76124

77125
clean_changelog:
78-
if: needs.changelog.outputs.release-type == 'no-release'
79-
needs: [ changelog ]
126+
needs: changelog
127+
if: ${{ needs.changelog.outputs.release-type == 'no-release' }}
80128
runs-on: ubuntu-latest
81129
steps:
82130
- uses: actions/checkout@v4

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## Unreleased [no-release]
6+
7+
_Modifications made in this changeset do not add, remove or alter any behavior, dependency, API or functionality of the software. They only change non-functional parts of the repository, such as the README file or CI workflows._
8+
59
## 10.3.1 - 2026-01-13
610

711
> Development of this release was supported by [Reset Tech](https://www.reset.tech).

0 commit comments

Comments
 (0)