-
Notifications
You must be signed in to change notification settings - Fork 545
148 lines (145 loc) · 6.07 KB
/
docs_changes_summary.yml
File metadata and controls
148 lines (145 loc) · 6.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Summarize changes to source plugins docs
on:
# 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)
pull_request_target:
branches:
- main
types:
- opened
- edited
- synchronize
- reopened
permissions:
contents: read
jobs:
doc-changes:
permissions:
contents: read
pull-requests: write
defaults:
run:
working-directory: scripts/table_diff
timeout-minutes: 15
runs-on: ubuntu-latest
outputs:
breaking: ${{ steps.breaking.outputs.status }}
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3
with:
app-id: ${{ secrets.CQ_APP_ID }}
private-key: ${{ secrets.CQ_APP_PRIVATE_KEY }}
permission-pull-requests: write
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Get PR diff
run: |
curl -L ${{ github.event.pull_request.diff_url }} > pr.diff
- name: Set up Go 1.x
id: setup-go
uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6
with:
go-version-file: scripts/table_diff/go.mod
cache: false
- uses: actions/cache@668228422ae6a00e4ad889ee87cd7109ec5666a7 # v5
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ steps.setup-go.outputs.go-version }}-test-scripts-table-diff-${{ hashFiles('scripts/table_diff/go.sum') }}
restore-keys: |
${{ runner.os }}-go-${{ steps.setup-go.outputs.go-version }}-test-scripts-table-diff-
- name: Generate docs changes file
run: |
go run main.go pr.diff changes.json
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
name: Get doc changes string
id: get-changes
with:
result-encoding: string
script: |
const { promises: fs } = require('fs')
const changes = JSON.parse(await fs.readFile('scripts/table_diff/changes.json', 'utf8'))
if (changes.length === 0) {
console.log('No changes to docs')
return ""
}
const changesList = changes.map(change => {
const { breaking, text } = change
if (breaking) {
return `- :warning: BREAKING CHANGE: ${text}`
}
return `- ${text}`
}).join('\n')
return changesList
- name: Find Comment
uses: peter-evans/find-comment@1a5d78cf05602d9070d859ad658461737f7b45c1
id: find-comment
with:
token: ${{ steps.app-token.outputs.token }}
issue-number: ${{ github.event.pull_request.number }}
comment-author: "cloudquery-ci[bot]"
body-includes: "### This PR has the following changes to source plugin(s) tables:"
- name: Create or update comment
uses: peter-evans/create-or-update-comment@57232238742e38b2ccc27136ce596ccae7ca28b4
if: steps.get-changes.outputs.result != ''
with:
token: ${{ steps.app-token.outputs.token }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
### This PR has the following changes to source plugin(s) tables:
${{steps.get-changes.outputs.result}}
edit-mode: replace
# Inspired by https://github.com/peter-evans/create-or-update-comment/issues/110#issuecomment-1086997843
- if: steps.get-changes.outputs.result == '' && steps.find-comment.outputs.comment-id != ''
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
name: Delete existing comment if there are no changes
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |
github.rest.issues.deleteComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: ${{ steps.find-comment.outputs.comment-id }}
})
- name: Mark as breaking
id: breaking
if: contains(steps.get-changes.outputs.result, 'BREAKING CHANGE')
run: echo "status=true" >> $GITHUB_OUTPUT
ensure-breaking-changes-released-as-major-bump:
runs-on: ubuntu-latest
needs: [doc-changes]
steps:
- name: Should enforce check
id: enforce
# Only enforce this check for renovate PRs that update dependencies
if: needs.doc-changes.outputs.breaking == 'true' && github.event.pull_request.user.login == 'cloudquery-ci[bot]' && startsWith(github.event.pull_request.title, 'fix(deps)') && startsWith(github.head_ref, 'renovate/')
run: echo "status=true" >> $GITHUB_OUTPUT
- name: Install commit message parser
if: steps.enforce.outputs.status == 'true'
run: npm install @conventional-commits/parser
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8
if: steps.enforce.outputs.status == 'true'
with:
script: |
const {
parser,
toConventionalChangelogFormat,
} = require("@conventional-commits/parser");
const { title } = context.payload.pull_request
try {
const ast = parser(title);
const { notes } = toConventionalChangelogFormat(ast);
const isBreaking = notes.some(({ title }) =>
title.includes("BREAKING CHANGE")
);
if (!isBreaking) {
const titleParts = title.split(":");
const expectedTitle = `${titleParts[0]}!:${titleParts[1]}`;
throw new Error(`PR title does not contain a breaking change, please update the title to '${expectedTitle}'`);
}
} catch (e) {
throw new Error(`PR title does not follow conventional commits format. Error: ${e}`);
}