Skip to content
Open
85 changes: 85 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Auto Release – node

on:
pull_request:
types: [closed]
branches:
- master

permissions:
contents: write

jobs:
release:
# Run only when PR is merged
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Validate release intent
id: intent
uses: actions/github-script@v6
with:
script: |
const body = context.payload.pull_request.body || '';
const title = context.payload.pull_request.title || '';
const text = `${title}\n${body}`;

core.setOutput(
'release',
/release:\s*yes/i.test(text) ? 'true' : 'false'
);

- name: Stop if not a release PR
if: steps.intent.outputs.release == 'false'
run: |
echo "Not a release PR. Skipping auto-release."
exit 0


- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}
fetch-depth: 0


- name: Read version from bower.json
run: |
VERSION=$(jq -r '.version' ./Examples/bower.json)

if [ -z "$VERSION" ] || [ "$VERSION" = "null" ]; then
echo "Failed to determine version from bower.json"
exit 1
fi

if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi

echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Releasing version $VERSION"


- name: Prepare release notes
run: |
PR_BODY="${{ github.event.pull_request.body }}"

CLEAN_NOTES=$(echo "$PR_BODY" | sed \
-e '/^release:\s*/Id' \
-e '/^## Release Notes.*$/Id')

echo "RELEASE_NOTES<<EOF" >> $GITHUB_ENV
echo "$CLEAN_NOTES" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV


- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.PAT }}
run: |
gh release create "v${VERSION}" \
--title "Release ${VERSION}" \
--notes "$RELEASE_NOTES" \
--latest
104 changes: 104 additions & 0 deletions .github/workflows/sync-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: Sync Version – Java SDK

on:
repository_dispatch:
types: [version_update]

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.PAT }}

- name: Load version
run: |
VERSION="${{ github.event.client_payload.version }}"

if [ -z "$VERSION" ]; then
echo "Version is missing"
exit 1
fi

if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid version format: $VERSION"
exit 1
fi

echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "Using version $VERSION"

- name: Compare current version
run: |
CURRENT_VERSION=$(jq -r '.version' ./Examples/bower.json)

if [ -z "$CURRENT_VERSION" ] || [ "$CURRENT_VERSION" = "null" ]; then
echo "Could not read the current version from bower.json"
exit 1
fi

echo "Current version: $CURRENT_VERSION"
echo "Incoming version: $VERSION"

if [ "$CURRENT_VERSION" = "$VERSION" ]; then
echo "The version is already up to date. No changes needed."
exit 0
fi

echo "New version detected. Continuing with release process."

- name: Prepare release branch
run: |
BRANCH="release-v${VERSION}"
echo "BRANCH=$BRANCH" >> $GITHUB_ENV

git fetch origin

if git ls-remote --heads origin "$BRANCH" | grep -q "$BRANCH"; then
git checkout "$BRANCH"
git pull origin "$BRANCH"
else
git checkout -b "$BRANCH"
fi

- name: Update ./Examples/bower.json
run: |
jq --arg VERSION "$VERSION" '.version = $VERSION' ./Examples/bower.json > tmp.json
mv tmp.json ./Examples/bower.json

- name: Commit changes
run: |
git config user.name "froala-travis-bot"
git config user.email "froala_git_travis_bot@idera.com"
git add ./Examples/bower.json
git commit -m "chore: update Examples/bower.json to v${VERSION}" || echo "Nothing to commit"
git push origin "$BRANCH"

- name: Create Pull Request
env:
GH_TOKEN: ${{ secrets.PAT }}
RELEASE_NOTES: ${{ github.event.client_payload.release_notes }}
run: |
git fetch origin master

if git diff --quiet origin/master..."$BRANCH"; then
echo "No commits between $BRANCH and master. Skipping PR creation."
exit 0
fi

PR_BODY=$(printf \
"release: yes\n\n## Release Notes (from primary repo)\n\n%s\n" \
"$RELEASE_NOTES")

gh pr create \
--base master \
--head "$BRANCH" \
--title "Release v${VERSION}" \
--body "$PR_BODY" \
|| echo "Pull request already exists"