-
Notifications
You must be signed in to change notification settings - Fork 0
131 lines (122 loc) · 4.18 KB
/
bot.yml
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
# More documentation here
# https://docs.github.com/en/actions
---
name: Create new release
on:
workflow_dispatch:
inputs:
app_version:
description: 'app_version eg: 1.2.3'
required: true
type: string
env:
ENV_1: X
jobs:
remove-branch-protection:
runs-on: ubuntu-latest
steps:
- name: Remove branch protection
uses: actions/github-script@v6
with:
github-token: "${{ secrets.PAT }}"
script: |
github.rest.repos.updateBranchProtection({
owner: context.repo.owner,
repo: context.repo.repo,
branch: "main",
required_status_checks: null,
enforce_admins: null,
required_pull_request_reviews: null,
restrictions: null,
})
bump-version:
runs-on: ubuntu-latest
needs: remove-branch-protection
steps:
- name: Checkout
uses: actions/checkout@v3
- run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
> VERSION.md
echo "${{ github.event.inputs.app_version }}" > VERSION.md
git add .
git commit -m "Bump version to ${{ github.event.inputs.app_version }}"
git push origin ${GITHUB_REF##*/}
add-branch-protection:
runs-on: ubuntu-latest
needs: bump-version
steps:
- name: Add branch protection
uses: actions/github-script@v6
with:
github-token: "${{ secrets.PAT }}"
script: |
github.rest.repos.updateBranchProtection({
owner: context.repo.owner,
repo: context.repo.repo,
branch: "main",
required_status_checks: null,
enforce_admins: null,
required_pull_request_reviews: {},
restrictions: null,
})
generate-tag:
runs-on: ubuntu-latest
needs: bump-version
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Pull
run: git pull origin ${GITHUB_REF##*/}
- name: Generate tag
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git tag ${{ github.event.inputs.app_version }}
git push origin ${{ github.event.inputs.app_version }}
generate-release:
runs-on: ubuntu-latest
needs: generate-tag
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Create release notes
uses: actions/github-script@v6
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "${{ github.event.inputs.app_version }}",
name: "${{ github.event.inputs.app_version }}",
generate_release_notes: true
})
comment-on-each-pr:
runs-on: ubuntu-latest
needs: generate-release
steps:
- name: Comment on each PR
uses: actions/github-script@v6
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: "${{ github.event.inputs.app_version }}"
})
const body = release.data.body
const strings = body.split('\n')
const prs = strings.filter(i => i.includes('/pull/'))
const pr_ids = prs.map(i => i.split('/pull/').pop())
const unique_pr_ids = pr_ids.filter((v, i, a) => pr_ids.indexOf(v) === i)
unique_pr_ids.map(id => {
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: id,
body: "This PR has been included in version [${{ github.event.inputs.app_version }}](https://github.com/paulo9mv/release-notes/releases/tag/${{github.event.inputs.app_version}}) 🎉"
})
})