Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 – angular

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' 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
117 changes: 117 additions & 0 deletions .github/workflows/sync-version.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
name: Release

on:
repository_dispatch:
types: [version_update]

permissions:
contents: write

jobs:
release:
runs-on: ubuntu-latest

steps:
- 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]+(-[0-9A-Za-z.-]+)?$ ]]; 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' 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 package.json
run: |
jq --arg VERSION "$VERSION" '.version = $VERSION' package.json > tmp.json
mv tmp.json package.json

- name: Update bower.json
run: |
jq --arg VERSION "$VERSION" '.version = $VERSION' bower.json > tmp.json
mv tmp.json 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 .
git commit -m "chore: release v${VERSION}" || echo "Nothing to commit"
git push origin "$BRANCH"

- name: Commit & push
run: |
git config user.name "froala-travis-bot"
git config user.email "froala_git_travis_bot@idera.com"

git add package.json bower.json
git commit -m "chore: release 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"
Loading