Skip to content

Commit 05faf5d

Browse files
fuzzypixelzwyfo
authored andcommitted
feat: Automate Release (eclipse-zenoh#165)
* build: Get Read the Docs release number from Cargo manifest This avoids hardcoding the release number in the documentation build config, making it easier to bump the version by only modifying the manifest. * build: Require Python 3.11 in Read the Docs configuration Python 3.11 is needed to access tomllib; useful for parsing the Cargo manifest file. * feat: Create branch, bump version and tag in release workflow * feat: Add publish-github job * fix: Broken tag dependencies * chore: Remove enforce-linking-issues workflow * fix: Bump version in pyproject.toml * chore: Upgrade artifact actions from v3 to v4 * fix: Typo in git-commit command * fix: Support jq 1.6 ubuntu-22.04 runners use jq 1.6 which doesn't recognize a dot for `[]` value iterator. See: jqlang/jq#1168. * Revert "chore: Upgrade artifact actions from v3 to v4" This reverts commit a535971. * fix: Build wheels from release branch * fix: Switch to pypa/gh-action-pypi-publish@release/v1 The older actions doesn't recognize the pyproject.toml metadata fields.
1 parent 67f40f2 commit 05faf5d

File tree

5 files changed

+173
-27
lines changed

5 files changed

+173
-27
lines changed

.github/workflows/enforce-linking-issues.yml

-10
This file was deleted.

.github/workflows/release.yml

+101-14
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,62 @@
11
name: Release
22

33
on:
4-
release:
5-
types: [published]
64
schedule:
75
- cron: "0 1 * * 1-5"
86
workflow_dispatch:
7+
inputs:
8+
live-run:
9+
type: boolean
10+
description: Live-run
11+
required: false
12+
version:
13+
type: string
14+
description: Release number
15+
required: false
16+
zenoh-version:
17+
type: string
18+
description: Release number of Zenoh
19+
required: false
920

1021
jobs:
11-
macos:
22+
tag:
23+
name: Branch, Bump & tag
24+
runs-on: ubuntu-latest
25+
outputs:
26+
version: ${{ steps.create-release-branch.outputs.version }}
27+
branch: ${{ steps.create-release-branch.outputs.branch }}
28+
steps:
29+
- id: create-release-branch
30+
uses: eclipse-zenoh/ci/create-release-branch@main
31+
with:
32+
repo: ${{ github.repository }}
33+
live-run: ${{ inputs.live-run || false }}
34+
version: ${{ inputs.version }}
35+
github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}
36+
37+
- name: Checkout this repository
38+
uses: actions/checkout@v4
39+
with:
40+
ref: ${{ steps.create-release-branch.outputs.branch }}
41+
42+
- name: Bump and tag project
43+
run: bash ci/scripts/bump-and-tag.bash
44+
env:
45+
VERSION: ${{ steps.create-release-branch.outputs.version }}
46+
BUMP_DEPS_VERSION: ${{ inputs.zenoh-version }}
47+
BUMP_DEPS_PATTERN: ${{ inputs.zenoh-version && 'zenoh.*' || '' }}
48+
BUMP_DEPS_BRANCH: ${{ inputs.zenoh-version && format('release/{0}', inputs.zenoh-version) || '' }}
49+
GIT_USER_NAME: eclipse-zenoh-bot
50+
GIT_USER_EMAIL: [email protected]
51+
52+
build-macos:
53+
needs: tag
1254
runs-on: macos-latest
1355
steps:
1456
- name: Checkout this repository
1557
uses: actions/checkout@v4
58+
with:
59+
ref: ${{ needs.tag.outputs.branch }}
1660

1761
- name: Install Rust toolchain
1862
run: |
@@ -36,7 +80,8 @@ jobs:
3680
name: wheels
3781
path: dist
3882

39-
windows:
83+
build-windows:
84+
needs: tag
4085
runs-on: windows-latest
4186
strategy:
4287
matrix:
@@ -45,6 +90,8 @@ jobs:
4590
steps:
4691
- name: Checkout this repository
4792
uses: actions/checkout@v4
93+
with:
94+
ref: ${{ needs.tag.outputs.branch }}
4895

4996
- name: Install Rust toolchain
5097
run: |
@@ -63,14 +110,17 @@ jobs:
63110
name: wheels
64111
path: dist
65112

66-
linux:
113+
build-linux:
114+
needs: tag
67115
runs-on: ubuntu-latest
68116
strategy:
69117
matrix:
70118
target: [x86_64, i686, armv7]
71119
steps:
72120
- name: Checkout this repository
73121
uses: actions/checkout@v4
122+
with:
123+
ref: ${{ needs.tag.outputs.branch }}
74124

75125
- name: Build wheels
76126
uses: messense/maturin-action@v1
@@ -85,11 +135,14 @@ jobs:
85135
name: wheels
86136
path: dist
87137

88-
linux-aarch64:
138+
build-linux-aarch64:
139+
needs: tag
89140
runs-on: ubuntu-latest
90141
steps:
91142
- name: Checkout this repository
92143
uses: actions/checkout@v4
144+
with:
145+
ref: ${{ needs.tag.outputs.branch }}
93146

94147
- name: Build wheels
95148
uses: messense/maturin-action@v1
@@ -110,18 +163,21 @@ jobs:
110163
name: wheels
111164
path: dist
112165

113-
linux-armv6:
166+
build-linux-armv6:
167+
needs: tag
114168
runs-on: macos-latest
115169
steps:
116170
- name: Checkout this repository
117171
uses: actions/checkout@v4
172+
with:
173+
ref: ${{ needs.tag.outputs.branch }}
118174

119175
- name: Install Rust toolchain
120176
run: |
121177
rustup set profile minimal
122178
rustup target add arm-unknown-linux-gnueabihf
123179
124-
- name: install cross toolchain
180+
- name: Install cross toolchain
125181
run: |
126182
brew tap messense/macos-cross-toolchains
127183
brew install arm-unknown-linux-gnueabihf
@@ -140,19 +196,50 @@ jobs:
140196
name: wheels
141197
path: dist
142198

143-
deploy-wheels:
144-
needs: [macos, windows, linux, linux-armv6]
145-
name: deploy wheels to pypi
199+
publish-pypi:
200+
needs:
201+
[
202+
tag,
203+
build-macos,
204+
build-windows,
205+
build-linux,
206+
build-linux-armv6,
207+
build-linux-aarch64,
208+
]
209+
name: Deploy wheels to pypi
146210
runs-on: ubuntu-latest
147211
steps:
148212
- uses: actions/download-artifact@v3
149213
with:
150214
name: wheels
151215
path: dist
216+
152217
- name: Check dist
153218
run: ls -al ./dist/*
154-
- name: publish
155-
if: github.event_name == 'release' && github.event.action == 'published'
156-
uses: pypa/[email protected]
219+
220+
- name: Publish
221+
if: ${{ inputs.live-run || false }}
222+
uses: pypa/gh-action-pypi-publish@release/v1
157223
with:
158224
password: ${{ secrets.PYPI_ORG_TOKEN }}
225+
226+
publish-github:
227+
needs:
228+
[
229+
tag,
230+
build-macos,
231+
build-windows,
232+
build-linux,
233+
build-linux-armv6,
234+
build-linux-aarch64,
235+
]
236+
runs-on: ubuntu-latest
237+
steps:
238+
- uses: eclipse-zenoh/ci/publish-crates-github@main
239+
with:
240+
repo: ${{ github.repository }}
241+
live-run: ${{ inputs.live-run || false }}
242+
version: ${{ needs.tag.outputs.version }}
243+
branch: ${{ needs.tag.outputs.branch }}
244+
github-token: ${{ secrets.BOT_TOKEN_WORKFLOW }}
245+
archive-patterns: "^$"

.readthedocs.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sphinx:
2626
build:
2727
os: ubuntu-22.04
2828
tools:
29-
python: "3.8"
29+
python: "3.11"
3030
rust: "latest"
3131
jobs:
3232
pre_build:

ci/scripts/bump-and-tag.bash

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/usr/bin/env bash
2+
3+
set -xeo pipefail
4+
5+
# Release number
6+
readonly version=${VERSION:?input VERSION is required}
7+
# Dependencies' pattern
8+
readonly bump_deps_pattern=${BUMP_DEPS_PATTERN:-''}
9+
# Dependencies' version
10+
readonly bump_deps_version=${BUMP_DEPS_VERSION:-''}
11+
# Dependencies' git branch
12+
readonly bump_deps_branch=${BUMP_DEPS_BRANCH:-''}
13+
# Git actor name
14+
readonly git_user_name=${GIT_USER_NAME:?input GIT_USER_NAME is required}
15+
# Git actor email
16+
readonly git_user_email=${GIT_USER_EMAIL:?input GIT_USER_EMAIL is required}
17+
18+
cargo +stable install toml-cli
19+
20+
# NOTE(fuzzypixelz): toml-cli doesn't yet support in-place modification
21+
# See: https://github.com/gnprice/toml-cli?tab=readme-ov-file#writing-ish-toml-set
22+
function toml_set_in_place() {
23+
local tmp=$(mktemp)
24+
toml set "$1" "$2" "$3" > "$tmp"
25+
mv "$tmp" "$1"
26+
}
27+
28+
export GIT_AUTHOR_NAME=$git_user_name
29+
export GIT_AUTHOR_EMAIL=$git_user_email
30+
export GIT_COMMITTER_NAME=$git_user_name
31+
export GIT_COMMITTER_EMAIL=$git_user_email
32+
33+
# Bump Cargo version
34+
toml_set_in_place Cargo.toml "package.version" "$version"
35+
# Propagate version change to pyproject.toml
36+
toml_set_in_place pyproject.toml "project.version" "$version"
37+
38+
git commit Cargo.toml pyproject.toml -m "chore: Bump version to $version"
39+
40+
# Select all package dependencies that match $bump_deps_pattern and bump them to $bump_deps_version
41+
if [[ "$bump_deps_pattern" != '' ]]; then
42+
deps=$(toml get Cargo.toml dependencies | jq -r "keys[] | select(test(\"$bump_deps_pattern\"))")
43+
for dep in $deps; do
44+
if [[ -n $bump_deps_version ]]; then
45+
toml_set_in_place Cargo.toml "dependencies.$dep.version" "$bump_deps_version"
46+
fi
47+
48+
if [[ -n $bump_deps_branch ]]; then
49+
toml_set_in_place Cargo.toml "dependencies.$dep.branch" "$bump_deps_branch"
50+
fi
51+
done
52+
# Update lockfile
53+
cargo check
54+
55+
if [[ -n $bump_deps_version || -n $bump_deps_branch ]]; then
56+
git commit Cargo.toml Cargo.lock -m "chore: Bump $bump_deps_pattern version to $bump_deps_version"
57+
else
58+
echo "warn: no changes have been made to any dependencies matching $bump_deps_pattern"
59+
fi
60+
fi
61+
62+
git tag --force "$version" -m "v$version"
63+
git log -10
64+
git show-ref --tags
65+
git push origin
66+
git push --force origin "$version"

docs/conf.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
# -- Project setup --------------------------------------------------------------
2525

26+
import tomllib
27+
2628
import zenoh
2729

2830
# -- Project information -----------------------------------------------------
@@ -31,8 +33,9 @@
3133
copyright = '2020, ZettaScale Zenoh team, <[email protected]>'
3234
author = 'ZettaScale Zenoh team, <[email protected]>'
3335

34-
# The full version, including alpha/beta/rc tags
35-
release = '0.11.0-dev'
36+
# Extract the release number from the Cargo manifest
37+
with open("../Cargo.toml", "rb") as f:
38+
release = tomllib.load(f)["package"]["version"]
3639

3740

3841
# -- General configuration ---------------------------------------------------

0 commit comments

Comments
 (0)