Skip to content

Commit 3a4f0fc

Browse files
authored
Release automation scripts (#37)
* Release automation scripts
1 parent 458f7c3 commit 3a4f0fc

File tree

2 files changed

+202
-0
lines changed

2 files changed

+202
-0
lines changed

.github/workflows/auto-release.yml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Auto Release – node
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
release:
14+
# Run only when PR is merged
15+
if: github.event.pull_request.merged == true
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Validate release intent
20+
id: intent
21+
uses: actions/github-script@v6
22+
with:
23+
script: |
24+
const body = context.payload.pull_request.body || '';
25+
const title = context.payload.pull_request.title || '';
26+
const text = `${title}\n${body}`;
27+
28+
core.setOutput(
29+
'release',
30+
/release:\s*yes/i.test(text) ? 'true' : 'false'
31+
);
32+
33+
- name: Stop if not a release PR
34+
if: steps.intent.outputs.release == 'false'
35+
run: |
36+
echo "Not a release PR. Skipping auto-release."
37+
exit 0
38+
39+
40+
- name: Checkout repository
41+
uses: actions/checkout@v4
42+
with:
43+
token: ${{ secrets.PAT }}
44+
fetch-depth: 0
45+
46+
47+
- name: Read version from bower.json
48+
run: |
49+
VERSION=$(jq -r '.version' bower.json)
50+
51+
if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
52+
echo "Failed to determine version from bower.json"
53+
exit 1
54+
fi
55+
56+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
57+
echo "Invalid version format: $VERSION"
58+
exit 1
59+
fi
60+
61+
echo "VERSION=$VERSION" >> $GITHUB_ENV
62+
echo "Releasing version $VERSION"
63+
64+
65+
- name: Prepare release notes
66+
run: |
67+
PR_BODY="${{ github.event.pull_request.body }}"
68+
69+
CLEAN_NOTES=$(echo "$PR_BODY" | sed \
70+
-e '/^release:\s*/Id' \
71+
-e '/^## Release Notes.*$/Id')
72+
73+
echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
74+
echo "$CLEAN_NOTES" >> $GITHUB_ENV
75+
echo "EOF" >> $GITHUB_ENV
76+
77+
78+
- name: Create GitHub Release
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.PAT }}
81+
run: |
82+
gh release create "v${VERSION}" \
83+
--title "Release ${VERSION}" \
84+
--notes "$RELEASE_NOTES" \
85+
--latest

.github/workflows/sync-version.yml

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
name: Release
2+
3+
on:
4+
repository_dispatch:
5+
types: [version_update]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
release:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
token: ${{ secrets.PAT }}
18+
19+
- name: Load version
20+
run: |
21+
VERSION="${{ github.event.client_payload.version }}"
22+
23+
if [ -z "$VERSION" ]; then
24+
echo "Version is missing"
25+
exit 1
26+
fi
27+
28+
if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
29+
echo "Invalid version format: $VERSION"
30+
exit 1
31+
fi
32+
33+
echo "VERSION=$VERSION" >> $GITHUB_ENV
34+
echo "Using version $VERSION"
35+
36+
- name: Compare current version
37+
run: |
38+
CURRENT_VERSION=$(jq -r '.version' bower.json)
39+
40+
if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" = "null" ]; then
41+
echo "Could not read the current version from bower.json"
42+
exit 1
43+
fi
44+
45+
echo "Current version: $CURRENT_VERSION"
46+
echo "Incoming version: $VERSION"
47+
48+
if [ "$CURRENT_VERSION" = "$VERSION" ]; then
49+
echo "The version is already up to date. No changes needed."
50+
exit 0
51+
fi
52+
53+
echo "New version detected. Continuing with release process."
54+
55+
- name: Prepare release branch
56+
run: |
57+
BRANCH="release-v${VERSION}"
58+
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
59+
60+
git fetch origin
61+
62+
if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
63+
git checkout "$BRANCH"
64+
git pull origin "$BRANCH"
65+
else
66+
git checkout -b "$BRANCH"
67+
fi
68+
69+
- name: Update package.json
70+
run: |
71+
jq --arg VERSION "$VERSION" '.version = $VERSION' package.json > tmp.json
72+
mv tmp.json package.json
73+
74+
- name: Update bower.json
75+
run: |
76+
jq --arg VERSION "$VERSION" '.version = $VERSION' bower.json > tmp.json
77+
mv tmp.json bower.json
78+
79+
- name: Commit changes
80+
run: |
81+
git config user.name "froala-travis-bot"
82+
git config user.email "froala_git_travis_bot@idera.com"
83+
git add .
84+
git commit -m "chore: release v${VERSION}" || echo "Nothing to commit"
85+
git push origin "$BRANCH"
86+
87+
- name: Commit & push
88+
run: |
89+
git config user.name "froala-travis-bot"
90+
git config user.email "froala_git_travis_bot@idera.com"
91+
92+
git add package.json bower.json
93+
git commit -m "chore: release v${VERSION}" || echo "Nothing to commit"
94+
git push origin "$BRANCH"
95+
96+
- name: Create Pull Request
97+
env:
98+
GH_TOKEN: ${{ secrets.PAT }}
99+
RELEASE_NOTES: ${{ github.event.client_payload.release_notes }}
100+
run: |
101+
git fetch origin master
102+
103+
if git diff --quiet origin/master..."$BRANCH"; then
104+
echo "No commits between $BRANCH and master. Skipping PR creation."
105+
exit 0
106+
fi
107+
108+
PR_BODY=$(printf \
109+
"release: yes\n\n## Release Notes (from primary repo)\n\n%s\n" \
110+
"$RELEASE_NOTES")
111+
112+
gh pr create \
113+
--base master \
114+
--head "$BRANCH" \
115+
--title "Release v${VERSION}" \
116+
--body "$PR_BODY" \
117+
|| echo "Pull request already exists"

0 commit comments

Comments
 (0)