version_update #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Sync Version – wysiwyg-rails | |
| on: | |
| repository_dispatch: | |
| types: [version_update] | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| sync: | |
| runs-on: ubuntu-latest | |
| steps: | |
| # -------------------------------------------- | |
| # Checkout repository | |
| # -------------------------------------------- | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.PAT }} | |
| fetch-depth: 0 | |
| # -------------------------------------------- | |
| # Load & validate version | |
| # -------------------------------------------- | |
| - name: Load & validate version | |
| run: | | |
| VERSION="${{ github.event.client_payload.version }}" | |
| VERSION="${VERSION//,/\.}" | |
| if ! [[ "$VERSION" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then | |
| echo "Invalid version: $VERSION" | |
| exit 1 | |
| fi | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| # -------------------------------------------- | |
| # Prepare release branch | |
| # -------------------------------------------- | |
| - 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 | |
| # -------------------------------------------- | |
| # Update version.rb | |
| # -------------------------------------------- | |
| - name: Update version.rb | |
| run: | | |
| sed -i -E \ | |
| "s/VERSION\s*=\s*['\"][^'\"]+['\"]/VERSION = '${VERSION}'/" \ | |
| lib/wysiwyg-rails/version.rb | |
| # -------------------------------------------- | |
| # Sync assets from primary repo | |
| # -------------------------------------------- | |
| - name: Sync assets | |
| env: | |
| GIT_TOKEN: ${{ secrets.PAT }} | |
| run: | | |
| git clone --depth 1 \ | |
| "https://x-access-token:${GIT_TOKEN}@github.com/froala-travis-bot/wysiwyg-editor.git" \ | |
| /tmp/wysiwyg-main | |
| rsync -av --delete /tmp/wysiwyg-main/js/ app/assets/javascripts/ | |
| rsync -av --delete /tmp/wysiwyg-main/css/ app/assets/stylesheets/ | |
| # -------------------------------------------- | |
| # Commit & push | |
| # -------------------------------------------- | |
| - name: Commit & push | |
| run: | | |
| git config user.name "froala-travis-bot" | |
| git config user.email "froala_git_travis_bot@idera.com" | |
| git add \ | |
| lib/wysiwyg-rails/version.rb \ | |
| app/assets/javascripts \ | |
| app/assets/stylesheets | |
| git commit -m "chore: release v${VERSION}" || echo "Nothing to commit" | |
| git push origin "$BRANCH" | |
| # -------------------------------------------- | |
| # Create Pull Request (YAML-SAFE) | |
| # -------------------------------------------- | |
| - name: Create Pull Request | |
| env: | |
| GH_TOKEN: ${{ secrets.PAT }} | |
| RELEASE_NOTES: ${{ github.event.client_payload.release_notes }} | |
| run: | | |
| 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" |