-
Notifications
You must be signed in to change notification settings - Fork 3
135 lines (127 loc) · 6.1 KB
/
release-process.yaml
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
name: Run release process
on:
pull_request:
types: [edited, synchronize]
workflow_call:
secrets:
RENOVATE_GITHUB_TOKEN: { required: true }
RENOVATE_PRIVATE_KEY: { required: true }
jobs:
checkbox_action:
runs-on: ubuntu-latest
steps:
- name: Check release process checkbox
id: checkbox
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const checkboxText = "[x] Check to trigger automatic release process";
const checkboxChecked = pr.data.body.includes(checkboxText);
console.log(checkboxChecked);
return checkboxChecked;
- name: Check if PR is up-to-date with main
id: up_to_date
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const baseRef = context.payload.pull_request.base.ref;
const headRef = context.payload.pull_request.head.ref;
const mainCommits = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 25,
sha: baseRef
}).then(response => response.data.map(commit => commit.sha));
const prCommits = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 300,
sha: headRef
}).then(response => response.data.map(commit => commit.sha));
const containsAllCommits = mainCommits.every(commitSHA =>
prCommits.includes(commitSHA)
);
console.log(`PR contains all commits from main branch: ${containsAllCommits}`);
console.log(`Main Commits: ${mainCommits}`);
console.log(`PR Commits: ${prCommits}`);
console.log(`Result: ${containsAllCommits}`);
return containsAllCommits;
- name: Check PR Approval
id: pr_approval
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: reviews } = await github.rest.pulls.listReviews({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.payload.pull_request.number
});
const approved = reviews.some(review => review.state === 'APPROVED');
console.log(`PR has been ${approved ? 'approved' : 'not approved'}`);
return approved;
- name: Checkout
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
- name: Set up Git and import GPG key
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
env:
GPG_PRIVATE_KEY: ${{ secrets.RENOVATE_PRIVATE_KEY }}
run: |
echo "${GPG_PRIVATE_KEY}" | gpg --import
git config user.name "CCBC Service Account"
git config user.email "[email protected]"
git config user.signingkey "$(gpg --list-secret-keys --with-colons | awk -F: '/sec:/ {print $5}')"
git config commit.gpgsign true
- name: dev env setup
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: ./.github/actions/dev-env-setup
- name: Setup Sqitch User
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
run: |
sqitch config --user user.name 'CCBC Service Account'
sqitch config --user user.email '[email protected]'
- name: Make Release
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
run: |
yarn
git checkout "${GITHUB_HEAD_REF}"
yarn run release-it --ci --branch="${GITHUB_HEAD_REF}" --git.commitArgs=-n
- name: Enable Auto-Merge
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
run: |
PR_URL="${{ github.event.pull_request.html_url }}"
gh pr merge --auto --merge "$PR_URL"
env:
GITHUB_TOKEN: ${{ secrets.RENOVATE_GITHUB_TOKEN }}
continue-on-error: true
- name: Uncheck the checkbox
if: steps.checkbox.outputs.result == 'true' && steps.up_to_date.outputs.result == 'true' && steps.pr_approval.outputs.result == 'true' && !github.event.pull_request.draft
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const checkboxText = "[x] Check to trigger automatic release process";
const prNumber = context.payload.pull_request.number;
const currentPR = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber
});
const updatedBody = currentPR.data.body.replace(checkboxText, "[ ] Check to trigger automatic release process");
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: updatedBody
});