From a95583b9e0810cba81797bfd8bcf2b8ed3453727 Mon Sep 17 00:00:00 2001 From: Ludy Date: Thu, 22 Jan 2026 20:23:52 +0100 Subject: [PATCH] Add sync-versions job to GitHub Actions workflow (#5228) # Description of Changes This pull request updates the `.github/workflows/build.yml` file to improve automation and consistency in the build process. The most significant change is the addition of a new `sync-versions` job that automatically checks for and synchronizes version differences across key files, and posts a comment on the pull request if mismatches are detected. Additionally, there are minor formatting updates for consistency. **Automation and version synchronization:** * Added a new `sync-versions` job that runs after the build, checks for version mismatches between `build.gradle` and several frontend files, and posts or updates a comment on the pull request to notify contributors if differences are found. This job uses a GitHub App bot for authentication and ensures that versioning remains consistent across the project. **Formatting consistency:** * Updated the YAML formatting for `node-version`, `cache`, and `python-version` fields to use double quotes for consistency in the `build.yml` workflow. [[1]](diffhunk://#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721L150-R151) [[2]](diffhunk://#diff-5c3fa597431eda03ac3339ae6bf7f05e1a50d6fc7333679ec38e21b337cb6721L244-R338) image --- ## Checklist ### General - [ ] I have read the [Contribution Guidelines](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/CONTRIBUTING.md) - [ ] I have read the [Stirling-PDF Developer Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md) (if applicable) - [ ] I have read the [How to add new languages to Stirling-PDF](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md) (if applicable) - [ ] I have performed a self-review of my own code - [ ] My changes generate no new warnings ### Documentation - [ ] I have updated relevant docs on [Stirling-PDF's doc repo](https://github.com/Stirling-Tools/Stirling-Tools.github.io/blob/main/docs/) (if functionality has heavily changed) - [ ] I have read the section [Add New Translation Tags](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/HowToAddNewLanguage.md#add-new-translation-tags) (for new translation tags only) ### UI Changes (if applicable) - [ ] Screenshots or videos demonstrating the UI changes are attached (e.g., as comments or direct attachments in the PR) ### Testing (if applicable) - [ ] I have tested my changes locally. Refer to the [Testing Guide](https://github.com/Stirling-Tools/Stirling-PDF/blob/main/devGuide/DeveloperGuide.md#6-testing) for more details. --- .github/workflows/build.yml | 98 +++++++++++++++++++++++++++++++++++++ build.gradle | 2 +- 2 files changed, 99 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bacbd120e..52e40db51 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -196,6 +196,104 @@ jobs: path: frontend/dist/ retention-days: 3 + sync-versions: + if: needs.files-changed.outputs.build == 'true' + needs: [files-changed, build] + runs-on: ubuntu-latest + steps: + - name: Harden Runner + uses: step-security/harden-runner@f4a75cfd619ee5ce8d5b864b0d183aff3c69b55a # v2.13.1 + with: + egress-policy: audit + + - name: Checkout repository + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 + with: + fetch-depth: 0 + + - name: Setup GitHub App Bot + id: setup-bot + uses: ./.github/actions/setup-bot + with: + app-id: ${{ secrets.GH_APP_ID }} + private-key: ${{ secrets.GH_APP_PRIVATE_KEY }} + + - name: Set up JDK 21 + uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0 + with: + java-version: "21" + distribution: "temurin" + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0 + with: + gradle-version: 8.14 + + - name: Run version sync + run: ./gradlew syncAppVersion --build-cache + + - name: Check if version files have changed + id: git-check + run: | + if [[ -n $(git status --porcelain) ]]; then + echo "changes=true" >> $GITHUB_OUTPUT + else + echo "changes=false" >> $GITHUB_OUTPUT + fi + + - name: Post comment on PR + if: steps.git-check.outputs.changes == 'true' && github.event_name != 'workflow_dispatch' + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ steps.setup-bot.outputs.token }} + script: | + const { GITHUB_REPOSITORY } = process.env; + const [repoOwner, repoName] = GITHUB_REPOSITORY.split('/'); + const issueNumber = context.issue.number; + + // Find existing comment + const comments = await github.rest.issues.listComments({ + owner: repoOwner, + repo: repoName, + issue_number: issueNumber + }); + + const comment = comments.data.find(c => c.body.includes("## ⚠️ Version Differences")); + + const commentBody = `## ⚠️ Version Differences + + The versions in the following files do not match the version defined in \`build.gradle\`. + + Running \`./gradlew syncAppVersion\` or \`./gradlew build\` will automatically update these files: + + \`frontend/src-tauri/tauri.conf.json\`, \`frontend/src/proprietary/testing/serverExperienceSimulations.ts\`, \`frontend/src/core/testing/serverExperienceSimulations.ts\` + + Please run \`./gradlew syncAppVersion\` or \`./gradlew build\`!`; + + // Only update or create comments by the action user + const expectedActor = "${{ steps.setup-bot.outputs.app-slug }}[bot]"; + + if (comment && comment.user.login === expectedActor) { + // Update existing comment + await github.rest.issues.updateComment({ + owner: repoOwner, + repo: repoName, + comment_id: comment.id, + body: commentBody + }); + console.log("Updated existing comment."); + } else if (!comment) { + // Create new comment if no existing comment is found + await github.rest.issues.createComment({ + owner: repoOwner, + repo: repoName, + issue_number: issueNumber, + body: commentBody + }); + } else { + console.log("Comment update attempt denied. Actor does not match."); + } + check-licence: if: needs.files-changed.outputs.build == 'true' needs: [files-changed, build] diff --git a/build.gradle b/build.gradle index 75a9e2632..2a5384e24 100644 --- a/build.gradle +++ b/build.gradle @@ -533,4 +533,4 @@ tasks.register('buildRestartHelper', Jar) { doLast { println "restart-helper.jar created at: ${destinationDirectory.get()}/restart-helper.jar" } -} +} \ No newline at end of file