|
| 1 | +name: Release PR Maintenance |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [opened, synchronize, reopened, labeled] |
| 6 | + branches: |
| 7 | + - main |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + pull-requests: read |
| 12 | + |
| 13 | +jobs: |
| 14 | + bump-readme: |
| 15 | + if: startsWith(github.event.pull_request.head.ref, 'release-please--') |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout release branch |
| 19 | + uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v4.1.1 |
| 20 | + with: |
| 21 | + ref: ${{ github.event.pull_request.head.ref }} |
| 22 | + fetch-depth: 0 |
| 23 | + |
| 24 | + - name: Sync README dependency versions |
| 25 | + id: sync |
| 26 | + uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7 |
| 27 | + with: |
| 28 | + script: | |
| 29 | + const fs = require('fs'); |
| 30 | + const core = require('@actions/core'); |
| 31 | + const version = fs.readFileSync('VERSION', 'utf8').trim(); |
| 32 | + if (!version) { |
| 33 | + throw new Error('VERSION file is empty'); |
| 34 | + } |
| 35 | +
|
| 36 | + const readmePath = 'README.md'; |
| 37 | + const original = fs.readFileSync(readmePath, 'utf8'); |
| 38 | +
|
| 39 | + const gradlePattern = /(implementation\("com\.sumup:sumup-sdk:)([^"]+)("\))/; |
| 40 | + let gradleUpdated = false; |
| 41 | + const afterGradle = original.replace(gradlePattern, (_, prefix, _current, suffix) => { |
| 42 | + gradleUpdated = true; |
| 43 | + return `${prefix}${version}${suffix}`; |
| 44 | + }); |
| 45 | + if (!gradleUpdated) { |
| 46 | + throw new Error('Gradle dependency snippet not found in README.md'); |
| 47 | + } |
| 48 | +
|
| 49 | + const mavenPattern = /(<version>)([^<]+)(<\/version>)/; |
| 50 | + let mavenUpdated = false; |
| 51 | + const updated = afterGradle.replace(mavenPattern, (_, prefix, _current, suffix) => { |
| 52 | + mavenUpdated = true; |
| 53 | + return `${prefix}${version}${suffix}`; |
| 54 | + }); |
| 55 | + if (!mavenUpdated) { |
| 56 | + throw new Error('Maven dependency snippet not found in README.md'); |
| 57 | + } |
| 58 | +
|
| 59 | + if (updated === original) { |
| 60 | + core.setOutput('updated', 'false'); |
| 61 | + return; |
| 62 | + } |
| 63 | +
|
| 64 | + fs.writeFileSync(readmePath, updated); |
| 65 | + core.setOutput('updated', 'true'); |
| 66 | +
|
| 67 | + - name: Commit changes |
| 68 | + if: steps.sync.outputs.updated == 'true' |
| 69 | + run: | |
| 70 | + git config user.name "github-actions[bot]" |
| 71 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 72 | + git add README.md |
| 73 | + git commit -m "chore: update README dependency versions" |
| 74 | +
|
| 75 | + - name: Push changes |
| 76 | + if: steps.sync.outputs.updated == 'true' |
| 77 | + run: git push |
0 commit comments