Skip to content

Commit 99fb27f

Browse files
authored
Automatize release process (#533)
* Automatize release process * release process
1 parent dd1d78d commit 99fb27f

File tree

5 files changed

+246
-25
lines changed

5 files changed

+246
-25
lines changed

.github/release.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
changelog:
2+
exclude:
3+
labels:
4+
- changelog/no-changelog
5+
categories:
6+
- title: Fixed
7+
labels:
8+
- changelog/Fixed
9+
- title: Added
10+
labels:
11+
- changelog/Added
12+
- title: Changed
13+
labels:
14+
- changelog/Changed
15+
- title: Removed
16+
labels:
17+
- changelog/Removed
18+
- title: Deprecated
19+
labels:
20+
- changelog/Deprecated
21+
- title: Security
22+
labels:
23+
- changelog/Security

.github/workflows/prepare_release.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Prepare release
2+
3+
env:
4+
GIT_AUTHOR_EMAIL: "[email protected]"
5+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
6+
7+
on:
8+
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: New version tag
12+
required: true
13+
14+
jobs:
15+
prepare_release:
16+
name: Create release PR
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Get GitHub App token
20+
id: get_token
21+
uses: tibdex/github-app-token@v1
22+
with:
23+
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
24+
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
25+
- uses: actions/checkout@v2
26+
with:
27+
fetch-depth: 0
28+
token: ${{ steps.get_token.outputs.token }}
29+
30+
- name: Setup Git
31+
run: |
32+
git config user.name "${GIT_AUTHOR_NAME}"
33+
git config user.email "${GIT_AUTHOR_EMAIL}"
34+
35+
- name: Set up Node
36+
uses: actions/setup-node@v2
37+
with:
38+
node-version: 14
39+
40+
- name: Bump Gem version
41+
run: |
42+
git switch -c "release/${RELEASE_TAG}"
43+
npm version --allow-same-version --no-git-tag-version "${RELEASE_TAG#v}"
44+
git commit -a -m "Bump version to ${RELEASE_TAG}"
45+
git push -f --set-upstream origin "release/${RELEASE_TAG}"
46+
env:
47+
RELEASE_TAG: ${{ github.event.inputs.tag }}
48+
49+
- name: Create PR
50+
uses: actions/github-script@v5
51+
env:
52+
RELEASE_TAG: ${{ github.event.inputs.tag }}
53+
BASE: ${{ github.event.ref }}
54+
with:
55+
github-token: ${{ steps.get_token.outputs.token }}
56+
script: |
57+
const { data: notes } = await github.rest.repos.generateReleaseNotes({
58+
owner: context.repo.owner,
59+
repo: context.repo.repo,
60+
tag_name: process.env.RELEASE_TAG,
61+
});
62+
const today = new Date().toJSON().slice(0, 10);
63+
const header = [`# CHANGELOG\n\n## ${process.env.RELEASE_TAG.replace(/^v/, '')} / ${today}\n`];
64+
const changes = header.concat(notes.body.split("\n").slice(3));
65+
const { data: content } = await github.rest.repos.getContent({
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
path: "CHANGELOG.md",
69+
});
70+
const rawContent = Buffer.from(content.content, "base64")
71+
.toString("utf-8")
72+
.split("\n");
73+
const newContent = changes.concat(rawContent.slice(1)).join("\n");
74+
const { data: head } = await github.rest.git.getRef({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
ref: `heads/release/${process.env.RELEASE_TAG}`,
78+
});
79+
const { data: commit } = await github.rest.repos.createOrUpdateFileContents({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
message: "Update CHANGELOG",
83+
content: Buffer.from(newContent).toString("base64"),
84+
path: "CHANGELOG.md",
85+
branch: `release/${process.env.RELEASE_TAG}`,
86+
sha: content.sha,
87+
});
88+
const { data: pr } = await github.rest.pulls.create({
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
head: `release/${process.env.RELEASE_TAG}`,
92+
base: process.env.BASE,
93+
title: `Release ${process.env.RELEASE_TAG}`,
94+
body: "Update CHANGELOG",
95+
});
96+
await github.rest.issues.addLabels({
97+
issue_number: pr.number,
98+
owner: context.repo.owner,
99+
repo: context.repo.repo,
100+
labels: ["changelog/no-changelog"],
101+
});

.github/workflows/publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Publish package on NPM
2+
on:
3+
release:
4+
types: [released]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- uses: actions/setup-node@v1
11+
with:
12+
node-version: "12.x"
13+
- run: yarn
14+
- run: yarn publish --tag=latest
15+
env:
16+
NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}

.github/workflows/release.yml

Lines changed: 85 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,92 @@
1-
name: Publish package on NPM
1+
name: Release
2+
3+
env:
4+
GIT_AUTHOR_EMAIL: "[email protected]"
5+
GIT_AUTHOR_NAME: "ci.datadog-api-spec"
6+
27
on:
3-
release:
4-
types: [released]
8+
pull_request:
9+
types: [closed]
10+
branches:
11+
- master
12+
513
jobs:
6-
build:
14+
create_release:
15+
name: Create release
716
runs-on: ubuntu-latest
17+
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
818
steps:
19+
- name: Get GitHub App token
20+
id: get_token
21+
uses: tibdex/github-app-token@v1
22+
with:
23+
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
24+
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
25+
26+
- name: Create release
27+
uses: actions/github-script@v5
28+
env:
29+
RELEASE_BRANCH: ${{ github.head_ref }}
30+
with:
31+
github-token: ${{ steps.get_token.outputs.token }}
32+
script: |
33+
const tagName = process.env.RELEASE_BRANCH.split("/")[1];
34+
await github.rest.git.createRef({
35+
owner: context.repo.owner,
36+
repo: context.repo.repo,
37+
ref: `refs/tags/${tagName}`,
38+
sha: context.payload.pull_request.merge_commit_sha,
39+
});
40+
await github.rest.repos.createRelease({
41+
owner: context.repo.owner,
42+
repo: context.repo.repo,
43+
generate_release_notes: true,
44+
tag_name: tagName,
45+
});
46+
947
- uses: actions/checkout@v2
10-
- uses: actions/setup-node@v1
1148
with:
12-
node-version: "12.x"
13-
- run: yarn
14-
- run: yarn publish --tag=latest
49+
fetch-depth: 0
50+
token: ${{ steps.get_token.outputs.token }}
51+
52+
- name: Setup Git
53+
run: |
54+
git config user.name "${GIT_AUTHOR_NAME}"
55+
git config user.email "${GIT_AUTHOR_EMAIL}"
56+
57+
- name: Set up Node
58+
uses: actions/setup-node@v2
59+
with:
60+
node-version: 14
61+
62+
- name: Bump Gem version
63+
run: |
64+
git switch -c "${POST_RELEASE_BRANCH}"
65+
# TODO remove beta after 1.0.0 release
66+
npm version --no-git-tag-version --preid beta prerelease
67+
git push -f --set-upstream origin "${POST_RELEASE_BRANCH}"
68+
env:
69+
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
70+
71+
- name: Create PR
72+
uses: actions/github-script@v5
1573
env:
16-
NPM_AUTH_TOKEN: ${{ secrets.YARN_NPM_AUTH_TOKEN }}
74+
POST_RELEASE_BRANCH: post-${{ github.head_ref }}
75+
BASE: master
76+
with:
77+
github-token: ${{ steps.get_token.outputs.token }}
78+
script: |
79+
const { data: pr } = await github.rest.pulls.create({
80+
owner: context.repo.owner,
81+
repo: context.repo.repo,
82+
head: process.env.POST_RELEASE_BRANCH,
83+
base: process.env.BASE,
84+
title: "Post release",
85+
body: "Bump to dev version",
86+
});
87+
await github.rest.issues.addLabels({
88+
issue_number: pr.number,
89+
owner: context.repo.owner,
90+
repo: context.repo.repo,
91+
labels: ["changelog/no-changelog"],
92+
});

RELEASING.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@ This project does not have a strict release schedule. However, we would make a r
99
- Releases may be done more frequently than the above mentioned window.
1010

1111
### Prerequisites
12-
- Install [datadog_checks_dev](https://datadog-checks-base.readthedocs.io/en/latest/datadog_checks_dev.cli.html#installation) using Python 3
1312
- Have [Node.js 12+](https://nodejs.org/en/)
1413
- Ensure all CIs are passing on the master branch that we're about to release.
1514

16-
## Release
17-
Note that once the release process is started, nobody should be merging/pushing anything.
15+
## Release Process
1816

19-
### Commands
17+
The release process is controlled and run by GitHub Actions.
18+
### Prerequisite
2019

21-
Releasing a new version of `@datadog/datadog-api-client` unfolds as follow:
20+
1. Make sure you have `write_repo` access.
21+
1. Share your plan for the release with other maintainers to avoid conflicts during the release process.
2222

23-
- See changes ready for release by running `ddev release show changes . --tag-prefix v` at the root of this project. Add any missing labels to PRs if needed.
24-
- Run `ddev release changelog . <NEW_VERSION> --tag-prefix v` to update the `CHANGELOG.md` file at the root of this repository
25-
- Update the version in `package.json` you want to release, following semver (`yarn version --no-git-tag-version --set-version 1.0.0-beta.4`).
26-
- Commit the changes to the repository in a release branch and get it approved/merged after you:
27-
- Make sure that all CIs are passing, as this is the commit we will be releasing!
28-
- Merge the Pull Request.
29-
- Create a Github Release from the [Releases page](https://github.com/DataDog/datadog-api-client-typescript/releases) with the description of changes introduced.
30-
- Set the tag and the release name to new version e.g. `v1.0.0-beta.3`.
31-
- Paste the changelog in the description.
32-
- Check pre-release box for alpha/beta releases.
33-
- Once the release has been created, a Github Action will publish the package.
23+
### Update Changelog
24+
25+
1. Open [prepare release](https://github.com/DataDog/datadog-api-client-typescript/actions/workflows/prepare_release.yml) and click on `Run workflow` dropdown.
26+
1. Enter new version identifier in the `New version tag` input box (e.g. `v1.0.0-beta.9`).
27+
1. Trigger the action by clicking on `Run workflow` button.
28+
29+
### Review
30+
31+
1. Review the generated pull-request for `release/<New version tag>` branch.
32+
1. If everything is fine, merge the pull-request.
33+
1. Check that the [release](https://github.com/DataDog/datadog-api-client-typescript/actions/workflows/release.yml) action created new release on GitHub.
34+
35+
### Publish
36+
37+
1. A github action will kick off that builds and publishes this tag to NPM. Check that the [NPM package is published](https://www.npmjs.com/package/@datadog/datadog-api-client).
38+
1. Review and merge generated `Post release` pull-request with `dev` version bump.

0 commit comments

Comments
 (0)