Skip to content

Commit 2afa003

Browse files
Release automation scripts
Release automation scripts
2 parents 6fd83a4 + eb38db3 commit 2afa003

2 files changed

Lines changed: 189 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)