Skip to content

Commit a862819

Browse files
authored
Add a workflow to create the changelog (#806)
* Add a workflow to create the changelog This generates the changelog and creates a PR to update our file. * Lint * Fix ref * Make it required
1 parent 7dfd763 commit a862819

File tree

2 files changed

+87
-5
lines changed

2 files changed

+87
-5
lines changed

.github/workflows/prepare_release.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Prepare release
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
tag:
7+
description: New version tag
8+
required: true
9+
10+
jobs:
11+
prepare_release:
12+
name: Create release PR
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Get GitHub App token
16+
id: get_token
17+
uses: tibdex/github-app-token@v1
18+
with:
19+
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
20+
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
21+
- name: Create PR
22+
uses: actions/github-script@v5
23+
env:
24+
RELEASE_TAG: ${{ github.event.inputs.tag }}
25+
with:
26+
github-token: ${{ steps.get_token.outputs.token }}
27+
script: |
28+
const { data: notes } = await github.rest.repos.generateReleaseNotes({
29+
owner: context.repo.owner,
30+
repo: context.repo.repo,
31+
tag_name: process.env.RELEASE_TAG,
32+
});
33+
34+
const today = new Date().toJSON().slice(0, 10);
35+
const header = [`# Changelog\n\n## ${process.env.RELEASE_TAG} / ${today}\n`];
36+
const changes = header.concat(notes.body.split("\n").slice(3));
37+
38+
const { data: content } = await github.rest.repos.getContent({
39+
owner: context.repo.owner,
40+
repo: context.repo.repo,
41+
path: "CHANGELOG.md",
42+
});
43+
44+
const rawContent = Buffer.from(content.content, "base64")
45+
.toString("utf-8")
46+
.split("\n");
47+
const newContent = changes.concat(rawContent.slice(1)).join("\n");
48+
49+
const { data: master } = await github.rest.git.getRef({
50+
owner: context.repo.owner,
51+
repo: context.repo.repo,
52+
ref: "heads/master",
53+
});
54+
await github.rest.git.createRef({
55+
owner: context.repo.owner,
56+
repo: context.repo.repo,
57+
ref: `refs/heads/release/${process.env.RELEASE_TAG}`,
58+
sha: master.object.sha,
59+
});
60+
61+
const { data: commit } = await github.rest.repos.createOrUpdateFileContents({
62+
owner: context.repo.owner,
63+
repo: context.repo.repo,
64+
message: "Update CHANGELOG",
65+
content: Buffer.from(newContent).toString("base64"),
66+
path: "CHANGELOG.md",
67+
branch: `release/${process.env.RELEASE_TAG}`,
68+
sha: content.sha,
69+
});
70+
71+
const { data: pr } = await github.rest.pulls.create({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
head: `release/${process.env.RELEASE_TAG}`,
75+
base: "master",
76+
title: `Release ${process.env.RELEASE_TAG}`,
77+
body: "Update CHANGELOG",
78+
});
79+
await github.rest.issues.addLabels({
80+
issue_number: pr.number,
81+
owner: context.repo.owner,
82+
repo: context.repo.repo,
83+
labels: ["changelog/no-changelog"],
84+
});

.github/workflows/release.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
1-
name: Build
1+
name: Release
22

33
on:
4-
pull_request:
54
release:
65
types:
76
- published
87

98
jobs:
10-
build_wheels:
11-
name: Build wheels on ${{ matrix.os }}
9+
upload_release:
10+
name: Upload release
1211
runs-on: ubuntu-20.04
13-
if: github.event_name == 'release' && github.event.action == 'published'
1412
steps:
1513
- uses: actions/checkout@v2
1614
# Include all history and tags, needed for building the right version

0 commit comments

Comments
 (0)