-
Notifications
You must be signed in to change notification settings - Fork 20
108 lines (100 loc) · 3.84 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
name: Prepare release
env:
GIT_AUTHOR_EMAIL: "packages@datadoghq.com"
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
on:
workflow_dispatch:
inputs:
version:
description: New version number (e.g. '1.2.3' without the 'v' prefix)
jobs:
prepare_release:
name: Create release PR
runs-on: ubuntu-latest
steps:
- name: Get GitHub App token
id: get_token
uses: tibdex/github-app-token@v1
with:
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
- uses: actions/checkout@v3
with:
fetch-depth: 0
token: ${{ steps.get_token.outputs.token }}
- name: Setup Git
run: |
git config user.name "${GIT_AUTHOR_NAME}"
git config user.email "${GIT_AUTHOR_EMAIL}"
- name: Set up Ruby 2.6
uses: ruby/setup-ruby@v1
with:
ruby-version: 2.6
- name: Calculate version
id: get_version
run: |
if [ "${VERSION}" = "" ] ; then
LATEST_TAG=$(git describe --tags --abbrev=0)
NEXT_TAG=$(echo ${LATEST_TAG#v} | awk '{split($0, a, "."); print a[1] "." a[2] + 1 "." a[3]}')
echo "version=$NEXT_TAG" >> $GITHUB_OUTPUT
else
echo "version=$VERSION" >> $GITHUB_OUTPUT
fi
env:
VERSION: ${{ github.event.inputs.version }}
- name: Bump version
run: |
git switch -c "release/${RELEASE_VERSION}"
bundle install
bundle exec gem bump -v "${RELEASE_VERSION}"
git push -f --set-upstream origin "release/${RELEASE_VERSION}"
env:
RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
- name: Create PR
uses: actions/github-script@v6
env:
RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
BASE: ${{ github.event.ref }}
with:
github-token: ${{ steps.get_token.outputs.token }}
script: |
const { data: notes } = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `v${process.env.RELEASE_VERSION}`,
});
const today = new Date().toJSON().slice(0, 10);
const header = [`# CHANGELOG\n\n## ${process.env.RELEASE_VERSION} / ${today}\n`];
const changes = header.concat(notes.body.split("\n").slice(3));
const { data: content } = await github.rest.repos.getContent({
owner: context.repo.owner,
repo: context.repo.repo,
path: "CHANGELOG.md",
});
const rawContent = Buffer.from(content.content, "base64")
.toString("utf-8")
.split("\n");
const newContent = changes.concat(rawContent.slice(1)).join("\n");
await github.rest.repos.createOrUpdateFileContents({
owner: context.repo.owner,
repo: context.repo.repo,
message: "Update CHANGELOG",
content: Buffer.from(newContent).toString("base64"),
path: "CHANGELOG.md",
branch: `release/${process.env.RELEASE_VERSION}`,
sha: content.sha,
});
const { data: pr } = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
head: `release/${process.env.RELEASE_VERSION}`,
base: process.env.BASE,
title: `Release ${process.env.RELEASE_VERSION}`,
body: "Update CHANGELOG",
});
await github.rest.issues.addLabels({
issue_number: pr.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["changelog/no-changelog"],
});