Skip to content

Commit 9809195

Browse files
authored
Release automation (#82)
1 parent 254d608 commit 9809195

File tree

6 files changed

+241
-1
lines changed

6 files changed

+241
-1
lines changed

Diff for: .github/release.yml

+23
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

Diff for: .github/workflows/prepare_release.yml

+113
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
version:
11+
description: New version number (e.g. '1.2.3' without the 'v' prefix)
12+
13+
jobs:
14+
prepare_release:
15+
name: Create release PR
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Get GitHub App token
19+
id: get_token
20+
uses: tibdex/github-app-token@v1
21+
with:
22+
app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }}
23+
private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }}
24+
- uses: actions/checkout@v3
25+
26+
- name: Setup Git
27+
run: |
28+
git config user.name "${GIT_AUTHOR_NAME}"
29+
git config user.email "${GIT_AUTHOR_EMAIL}"
30+
31+
- name: Checkout code
32+
uses: actions/checkout@v3
33+
with:
34+
fetch-depth: 0
35+
36+
- name: Calculate version
37+
id: get_version
38+
run: |
39+
if [ "${VERSION}" = "" ] ; then
40+
LATEST_TAG=$(git describe --tags --abbrev=0)
41+
NEXT_TAG=$(echo ${LATEST_TAG#v} | awk '{split($0, a, "."); print a[1] "." a[2] + 1 "." a[3]}')
42+
echo "version=$NEXT_TAG" >> $GITHUB_OUTPUT
43+
else
44+
echo "version=$VERSION" >> $GITHUB_OUTPUT
45+
fi
46+
env:
47+
VERSION: ${{ github.event.inputs.version }}
48+
49+
- name: Install Rust
50+
uses: dtolnay/rust-toolchain@v1
51+
with:
52+
toolchain: "stable"
53+
- uses: Swatinem/rust-cache@v2
54+
- name: Install cargo-release
55+
run: cargo install cargo-release
56+
57+
- name: Bump version
58+
run: |
59+
git switch -c "release/${RELEASE_VERSION}"
60+
cargo release version "${RELEASE_VERSION}" --execute --no-confirm
61+
git commit -a -m "Version bump ${RELEASE_VERSION}"
62+
git push -f --set-upstream origin "release/${RELEASE_VERSION}"
63+
env:
64+
RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
65+
66+
- name: Create PR
67+
uses: actions/github-script@v6
68+
env:
69+
RELEASE_VERSION: ${{ steps.get_version.outputs.version }}
70+
BASE: ${{ github.event.ref }}
71+
with:
72+
github-token: ${{ steps.get_token.outputs.token }}
73+
script: |
74+
const { data: notes } = await github.rest.repos.generateReleaseNotes({
75+
owner: context.repo.owner,
76+
repo: context.repo.repo,
77+
tag_name: `v${process.env.RELEASE_VERSION}`,
78+
});
79+
const today = new Date().toJSON().slice(0, 10);
80+
const header = [`# CHANGELOG\n\n## ${process.env.RELEASE_VERSION} / ${today}\n`];
81+
const changes = header.concat(notes.body.split("\n").slice(3));
82+
const { data: content } = await github.rest.repos.getContent({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
path: "CHANGELOG.md",
86+
});
87+
const rawContent = Buffer.from(content.content, "base64")
88+
.toString("utf-8")
89+
.split("\n");
90+
const newContent = changes.concat(rawContent.slice(1)).join("\n");
91+
await github.rest.repos.createOrUpdateFileContents({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
message: "Update CHANGELOG",
95+
content: Buffer.from(newContent).toString("base64"),
96+
path: "CHANGELOG.md",
97+
branch: `release/${process.env.RELEASE_VERSION}`,
98+
sha: content.sha,
99+
});
100+
const { data: pr } = await github.rest.pulls.create({
101+
owner: context.repo.owner,
102+
repo: context.repo.repo,
103+
head: `release/${process.env.RELEASE_VERSION}`,
104+
base: process.env.BASE,
105+
title: `Release ${process.env.RELEASE_VERSION}`,
106+
body: "Update CHANGELOG",
107+
});
108+
await github.rest.issues.addLabels({
109+
issue_number: pr.number,
110+
owner: context.repo.owner,
111+
repo: context.repo.repo,
112+
labels: ["changelog/no-changelog"],
113+
});

Diff for: .github/workflows/publish.yml

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Publish
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
upload_release:
10+
name: Upload release
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- uses: actions/checkout@v3
14+
# Include all history and tags, needed for building the right version
15+
with:
16+
ref: ${{ github.event.release.tag_name }}
17+
fetch-depth: 0
18+
- name: Install Rust
19+
uses: dtolnay/rust-toolchain@v1
20+
with:
21+
toolchain: "stable"
22+
- uses: Swatinem/rust-cache@v2
23+
- name: Publish a Rust crate to crates.io
24+
env:
25+
CARGO_REGISTRY_TOKEN: "${{secrets.CRATES_IO_TOKEN}}"
26+
run: |
27+
cargo publish --registry crates-io

Diff for: .github/workflows/release.yml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- master
8+
9+
jobs:
10+
create_release:
11+
name: Create release
12+
runs-on: ubuntu-latest
13+
if: github.event.pull_request.merged == true && startsWith(github.head_ref, 'release/')
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 release
22+
uses: actions/github-script@v6
23+
env:
24+
RELEASE_BRANCH: ${{ github.head_ref }}
25+
with:
26+
github-token: ${{ steps.get_token.outputs.token }}
27+
script: |
28+
const tagName = process.env.RELEASE_BRANCH.split("/")[1];
29+
await github.rest.git.createRef({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo,
32+
ref: `refs/tags/${tagName}`,
33+
sha: context.payload.pull_request.merge_commit_sha,
34+
});
35+
await github.rest.repos.createRelease({
36+
owner: context.repo.owner,
37+
repo: context.repo.repo,
38+
generate_release_notes: true,
39+
tag_name: tagName,
40+
});

Diff for: CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# CHANGELOG
2+
3+
## 0.0.1 / 2024-03-28
4+
5+
Initial crate release.

Diff for: RELEASING.md

+33-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,33 @@
1-
//TODO
1+
# Releasing
2+
This document summarizes the process of doing a new release of this project.
3+
Release can only be performed by Datadog maintainers of this repository.
4+
5+
## Schedule
6+
This project does not have a strict release schedule. However, we would make a release at least every 2 months.
7+
- No release will be done if no changes got merged to the `master` branch during the above mentioned window.
8+
- Releases may be done more frequently than the above mentioned window.
9+
10+
### Prerequisites
11+
- Ensure all CIs are passing on the master branch that we're about to release.
12+
13+
## Release Process
14+
15+
The release process is controlled and run by GitHub Actions.
16+
17+
### Prerequisite
18+
19+
1. Make sure you have `write_repo` access.
20+
1. Share your plan for the release with other maintainers to avoid conflicts during the release process.
21+
22+
### Update Changelog
23+
24+
1. Open [prepare release](https://github.com/DataDog/datadog-api-client-rust/actions/workflows/prepare_release.yml) and click on `Run workflow` dropdown.
25+
1. If needed, enter new version identifier in the `New version number` input box (e.g. `1.10.0`). The default updates the previous minor.
26+
1. Trigger the action by clicking on `Run workflow` button.
27+
28+
### Review
29+
30+
1. Review the generated pull-request for `release/<New version number>` branch.
31+
1. If everything is fine, merge the pull-request.
32+
1. Check that the [release](https://github.com/DataDog/datadog-api-client-rust/actions/workflows/release.yml) action created a new release on GitHub.
33+
1. A GitHub action will kick off that builds and publishes this tag to crates.io. Confirm the [release is available](https://crates.io/crates/datadog-api-client)

0 commit comments

Comments
 (0)