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