-
Notifications
You must be signed in to change notification settings - Fork 44
191 lines (159 loc) · 6.77 KB
/
prepare-release.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Prepare Release PR
on:
push:
branches:
- 'release-*'
jobs:
setup:
runs-on: ubuntu-latest
outputs:
name: ${{ steps.vars.outputs.name }}
old-version: ${{ steps.vars.outputs.old-version }}
new-version: ${{ steps.vars.outputs.new-version }}
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Set variables
id: vars
run: |
NAME=$(cargo metadata -q --no-deps | jq -r '.packages[0].name')
OLD_VERSION=$(cargo metadata -q --no-deps | jq -r '.packages[0].version')
NEW_VERSION=$(echo ${{ github.ref }} | cut -d '-' -f 2-)
echo "Version from Cargo: $OLD_VERSION"
echo "Version from branch: $NEW_VERSION"
echo "name=$NAME" >> $GITHUB_OUTPUT
echo "old-version=$OLD_VERSION" >> $GITHUB_OUTPUT
echo "new-version=$NEW_VERSION" >> $GITHUB_OUTPUT
- name: Verify version format
run: |
echo '${{ steps.vars.outputs.new-version }}' | grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+$'
pull-request:
needs: setup
if: needs.setup.outputs.old-version != needs.setup.outputs.new-version
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Configure Git user
run: |
git config user.name "Martin Geisler"
git config user.email "martin@geisler.net"
- name: Install Graphviz
uses: ts-graphviz/setup-graphviz@v1
# We use debug builds since they compile a little faster.
- name: Install cargo-depgraph
run: |
cargo install --debug cargo-depgraph
- name: Install svgcleaner
run: |
cargo install --debug svgcleaner
- name: Generate dependency graph
run: |
cargo depgraph \
| dot -Tsvg -Nfontname=monospace \
| sed 's/stroke="transparent"/stroke="none"/' \
| svgcleaner --indent 0 --stdout - \
> images/textwrap-${{ needs.setup.outputs.new-version }}.svg
- name: Update dependency graph
run: |
import fileinput, re, sys
NAME = '${{ needs.setup.outputs.name }}'
NEW_VERSION = '${{ needs.setup.outputs.new-version }}'
for line in fileinput.input(inplace=True):
sys.stdout.write(
re.sub(f'/images/{NAME}-.+\\.svg',
f'/images/{NAME}-{NEW_VERSION}.svg', line))
shell: python3 {0} src/lib.rs
- name: Commit dependency graph
run: |
git add images/textwrap-${{ needs.setup.outputs.new-version }}.svg src/lib.rs
git commit -m "Add dependency graph for version ${{ needs.setup.outputs.new-version }}"
- name: Update changelog for version ${{ needs.setup.outputs.new-version }}
id: changelog
uses: actions/github-script@v3
with:
script: |
var fs = require('fs')
const old_version = '${{ needs.setup.outputs.old-version }}'
const new_version = '${{ needs.setup.outputs.new-version }}'
let cutoff = '1970-01-01'
const releases = await github.repos.listReleases(context.repo)
for (const release of releases.data) {
if (release.tag_name == old_version) {
cutoff = release.published_at
break
}
}
core.info(`Finding merged PRs after ${cutoff}`)
let q = [`repo:${context.repo.owner}/${context.repo.repo}`,
'is:pr', 'is:merged', `merged:>${cutoff}`]
const prs = await github.paginate(github.search.issuesAndPullRequests, {
q: q.join(' '),
sort: 'created',
order: 'asc',
})
core.info(`Found ${prs.length} merged PRs`)
const changelog = prs.map(
pr => `* [#${pr.number}](${pr.html_url}): ${pr.title}`
).join('\n')
core.exportVariable('CHANGELOG', changelog)
var content = fs.readFileSync('CHANGELOG.md', 'utf8')
const today = new Date().toISOString().split('T')[0]
const heading = `## Version ${new_version} (${today})\n`
if (content.match('## Unreleased')) {
content = content.replace('## Unreleased', `${heading}\n${changelog}`)
} else {
content = content.replace('## Version', `${heading}\n${changelog}\n\n## Version`)
}
fs.writeFileSync('CHANGELOG.md', content)
- name: Commit changelog
run: |
git commit --all -m "Update changelog for version ${{ needs.setup.outputs.new-version }}"
- name: Update TOML code blocks
run: |
import fileinput, re, sys
NAME = '${{ needs.setup.outputs.name }}'
NEW_VERSION = '${{ needs.setup.outputs.new-version }}'
MAJOR_MINOR = '.'.join(NEW_VERSION.split('.')[:2])
for line in fileinput.input(inplace=True):
line = re.sub(f'{NAME} = "[^"]+"',
f'{NAME} = "{MAJOR_MINOR}"', line)
line = re.sub(f'{NAME} = {{ version = "[^"]+"',
f'{NAME} = {{ version = "{MAJOR_MINOR}"', line)
sys.stdout.write(line)
shell: python3 {0} README.md
- name: Update html_root_url
run: |
import fileinput, re, sys
NAME = '${{ needs.setup.outputs.name }}'
NEW_VERSION = '${{ needs.setup.outputs.new-version }}'
for line in fileinput.input(inplace=True):
sys.stdout.write(
re.sub(f'html_root_url = "https://docs.rs/{NAME}/[^"]+"',
f'html_root_url = "https://docs.rs/{NAME}/{NEW_VERSION}"', line))
shell: python3 {0} src/lib.rs
- name: Update crate version to ${{ needs.setup.outputs.new-version }}
uses: thomaseizinger/set-crate-version@1.0.0
with:
version: ${{ needs.setup.outputs.new-version }}
- name: Build and test
run: |
cargo test
- name: Commit version bump
run: |
git commit --all -m "Bump version to ${{ needs.setup.outputs.new-version }}"
- name: Push version bump
run: git push origin
- name: Create pull request
uses: actions/github-script@v3
with:
script: |
const pr = await github.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: 'release-${{ needs.setup.outputs.new-version }}',
base: 'master',
title: 'Release ${{ needs.setup.outputs.new-version }}',
body: process.env.CHANGELOG,
})
core.info(`Created PR: ${pr.data.html_url}`)