|
| 1 | +name: Summarize changes to source plugins docs |
| 2 | + |
| 3 | +on: |
| 4 | + # Using pull_request_target works on forked PRs too. This is safe since we don't checkout the PR code (we only use the diff) |
| 5 | + pull_request_target: |
| 6 | + branches: |
| 7 | + - main |
| 8 | + types: |
| 9 | + - opened |
| 10 | + - edited |
| 11 | + - synchronize |
| 12 | + - reopened |
| 13 | +jobs: |
| 14 | + doc-changes: |
| 15 | + defaults: |
| 16 | + run: |
| 17 | + working-directory: scripts/table_diff |
| 18 | + timeout-minutes: 15 |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + breaking: ${{ steps.breaking.outputs.status }} |
| 22 | + steps: |
| 23 | + - name: Checkout |
| 24 | + uses: actions/checkout@v3 |
| 25 | + - name: Get PR diff |
| 26 | + run: | |
| 27 | + curl -L ${{ github.event.pull_request.diff_url }} > pr.diff |
| 28 | + - name: Set up Go 1.x |
| 29 | + uses: actions/setup-go@v3 |
| 30 | + with: |
| 31 | + go-version-file: scripts/table_diff/go.mod |
| 32 | + cache: true |
| 33 | + cache-dependency-path: scripts/table_diff/go.sum |
| 34 | + - name: Generate docs changes file |
| 35 | + run: | |
| 36 | + go run main.go pr.diff changes.json |
| 37 | + - uses: actions/github-script@v6 |
| 38 | + name: Get doc changes string |
| 39 | + id: get-changes |
| 40 | + with: |
| 41 | + result-encoding: string |
| 42 | + script: | |
| 43 | + const { promises: fs } = require('fs') |
| 44 | + const changes = JSON.parse(await fs.readFile('scripts/table_diff/changes.json', 'utf8')) |
| 45 | + if (changes.length === 0) { |
| 46 | + console.log('No changes to docs') |
| 47 | + return "" |
| 48 | + } |
| 49 | + const changesList = changes.map(change => { |
| 50 | + const { breaking, text } = change |
| 51 | + if (breaking) { |
| 52 | + return `- :warning: BREAKING CHANGE: ${text}` |
| 53 | + } |
| 54 | + return `- ${text}` |
| 55 | + }).join('\n') |
| 56 | + return changesList |
| 57 | + - name: Find Comment |
| 58 | + uses: peter-evans/find-comment@f4499a714d59013c74a08789b48abe4b704364a0 |
| 59 | + if: steps.get-changes.outputs.result != '' |
| 60 | + id: find-comment |
| 61 | + with: |
| 62 | + issue-number: ${{ github.event.pull_request.number }} |
| 63 | + comment-author: 'github-actions[bot]' |
| 64 | + body-includes: '### This PR has the following changes to source plugin(s) tables:' |
| 65 | + - name: Create or update comment |
| 66 | + uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808 |
| 67 | + if: steps.get-changes.outputs.result != '' |
| 68 | + with: |
| 69 | + comment-id: ${{ steps.find-comment.outputs.comment-id }} |
| 70 | + issue-number: ${{ github.event.pull_request.number }} |
| 71 | + body: | |
| 72 | + ### This PR has the following changes to source plugin(s) tables: |
| 73 | +
|
| 74 | + ${{steps.get-changes.outputs.result}} |
| 75 | + edit-mode: replace |
| 76 | + - name: Mark as breaking |
| 77 | + id: breaking |
| 78 | + if: contains(steps.get-changes.outputs.result, 'BREAKING CHANGE') |
| 79 | + run: echo "status=true" >> $GITHUB_OUTPUT |
| 80 | + ensure-breaking-changes-released-as-major-bump: |
| 81 | + runs-on: ubuntu-latest |
| 82 | + needs: [doc-changes] |
| 83 | + steps: |
| 84 | + - name: Should enforce check |
| 85 | + id: enforce |
| 86 | + # Only enforce this check for renovate PRs that update dependencies |
| 87 | + if: needs.doc-changes.outputs.breaking == 'true' && github.event.pull_request.user.login == 'cq-bot' && startsWith(github.event.pull_request.title, 'fix(deps)') && startsWith(github.head_ref, 'renovate/') |
| 88 | + run: echo "status=true" >> $GITHUB_OUTPUT |
| 89 | + - name: Install commit message parser |
| 90 | + if: steps.enforce.outputs.status == 'true' |
| 91 | + run: npm install @conventional-commits/parser |
| 92 | + - uses: actions/github-script@v6 |
| 93 | + if: steps.enforce.outputs.status == 'true' |
| 94 | + with: |
| 95 | + script: | |
| 96 | + const { |
| 97 | + parser, |
| 98 | + toConventionalChangelogFormat, |
| 99 | + } = require("@conventional-commits/parser"); |
| 100 | + const { title } = context.payload.pull_request |
| 101 | + try { |
| 102 | + const ast = parser(title); |
| 103 | + const { notes } = toConventionalChangelogFormat(ast); |
| 104 | + const isBreaking = notes.some(({ title }) => |
| 105 | + title.includes("BREAKING CHANGE") |
| 106 | + ); |
| 107 | + if (!isBreaking) { |
| 108 | + const titleParts = title.split(":"); |
| 109 | + const expectedTitle = `${titleParts[0]}!:${titleParts[1]}`; |
| 110 | + throw new Error(`PR title does not contain a breaking change, please update the title to '${expectedTitle}'`); |
| 111 | + } |
| 112 | + } catch (e) { |
| 113 | + throw new Error(`PR title does not follow conventional commits format. Error: ${e}`); |
| 114 | + } |
0 commit comments