|
| 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