Skip to content

Commit a912f75

Browse files
authored
ci: Improve release management (#868)
1 parent 400028d commit a912f75

3 files changed

Lines changed: 148 additions & 79 deletions

File tree

.github/workflows/build-binary.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Build binary matrix
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
version:
7+
description: "Version string for archive naming (e.g. 1.2.3 or dev)"
8+
required: true
9+
type: string
10+
upload-to-release:
11+
description: "Upload built artifacts to a GitHub release"
12+
required: false
13+
type: boolean
14+
default: false
15+
release-tag:
16+
description: "The full release tag to upload to (e.g. fontspector-v1.2.3)"
17+
required: false
18+
type: string
19+
checkout-ref:
20+
description: "Git ref to checkout (defaults to the event's ref)"
21+
required: false
22+
type: string
23+
24+
jobs:
25+
build:
26+
name: ${{ matrix.os.build }}
27+
permissions:
28+
contents: write
29+
id-token: write
30+
runs-on: ${{ matrix.os.os }}
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
os:
35+
- build: linux
36+
os: ubuntu-22.04
37+
target: x86_64-unknown-linux-gnu
38+
39+
- build: macos
40+
os: macos-latest
41+
target: x86_64-apple-darwin
42+
43+
- build: macos-m1
44+
os: macos-latest
45+
target: aarch64-apple-darwin
46+
47+
- build: windows-gnu
48+
os: windows-latest
49+
target: x86_64-pc-windows-gnu
50+
51+
steps:
52+
- name: Checkout
53+
uses: actions/checkout@v7
54+
with:
55+
submodules: recursive
56+
fetch-depth: 0
57+
ref: ${{ inputs.checkout-ref }}
58+
59+
- run: rustup toolchain install stable --profile minimal
60+
61+
- if: matrix.os.target == 'x86_64-apple-darwin'
62+
run: rustup target add x86_64-apple-darwin
63+
64+
- uses: Swatinem/rust-cache@v2
65+
with:
66+
cache-workspace-crates: true
67+
add-job-id-key: false
68+
69+
- name: Build
70+
run: cargo build --verbose --release --target ${{ matrix.os.target }}
71+
72+
- name: Build archive
73+
shell: bash
74+
run: |
75+
dirname="fontspector-${{ inputs.version }}-${{ matrix.os.target }}"
76+
mkdir "$dirname"
77+
if [ "${{ matrix.os.os }}" = "windows-latest" ]; then
78+
mv "target/${{ matrix.os.target }}/release/"*.exe "$dirname"
79+
7z a "$dirname.zip" "$dirname"
80+
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
81+
else
82+
mv "target/${{ matrix.os.target }}/release/fontspector" "$dirname"
83+
tar -czf "$dirname.tar.gz" "$dirname"
84+
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
85+
fi
86+
87+
- uses: actions/upload-artifact@v7
88+
with:
89+
name: ${{ env.ASSET }}
90+
path: ${{ env.ASSET }}
91+
92+
- if: inputs.upload-to-release
93+
name: Add artefact to release
94+
env:
95+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
96+
run: gh release upload "${{ inputs.release-tag }}" "${{ env.ASSET }}"

.github/workflows/release.yml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ env:
88
GH_TOKEN: ${{ github.token }}
99

1010
jobs:
11-
build:
11+
make-release:
1212
runs-on: ubuntu-latest
13+
outputs:
14+
version: ${{ steps.find_version.outputs.VERSION }}
1315

1416
steps:
1517
- uses: actions/checkout@v7
@@ -28,4 +30,32 @@ jobs:
2830
- name: Install smart release
2931
run: cargo install cargo-smart-release
3032
- name: Run smart release
31-
run: cargo smart-release `python3 scripts/publishable.py` --no-changelog-preview --allow-fully-generated-changelogs --update-crates-index --execute
33+
run: |-
34+
PUBLISHABLE_CRATES=$(python3 scripts/publishable.py)
35+
for crate in $PUBLISHABLE_CRATES; do
36+
echo "Publishing $crate"
37+
cargo smart-release $crate --no-changelog-preview --allow-fully-generated-changelogs --update-crates-index --execute || exit 1
38+
done
39+
- name: Find Cargo version of fontspector crate
40+
id: find_version
41+
run: |-
42+
VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "fontspector") | .version')
43+
echo "VERSION=$VERSION" >> $GITHUB_ENV
44+
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT
45+
- name: Create GitHub release
46+
run: |-
47+
git tag -l --format='%(contents)' "fontspector-v${{ env.VERSION }}" > /tmp/release_body.md
48+
gh release create "fontspector-v${{ env.VERSION }}" \
49+
--title "Release v${{ env.VERSION }}" \
50+
--notes-file /tmp/release_body.md
51+
build-artefacts:
52+
needs: make-release
53+
permissions:
54+
contents: write
55+
id-token: write
56+
uses: ./.github/workflows/build-binary.yml
57+
with:
58+
version: ${{ needs.make-release.outputs.version }}
59+
upload-to-release: true
60+
release-tag: fontspector-v${{ needs.make-release.outputs.version }}
61+
checkout-ref: fontspector-v${{ needs.make-release.outputs.version }}

.github/workflows/rust.yml

Lines changed: 20 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -83,88 +83,31 @@ jobs:
8383
npm install
8484
npm run build
8585
86-
deploy-binaries:
87-
name: Build and upload binaries
88-
permissions:
89-
contents: write
90-
id-token: write
91-
runs-on: ${{ matrix.os.os }}
92-
# Only build on main or tag
86+
compute-version:
87+
runs-on: ubuntu-latest
9388
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
94-
strategy:
95-
fail-fast: false
96-
matrix:
97-
os:
98-
- build: linux
99-
os: ubuntu-22.04
100-
target: x86_64-unknown-linux-gnu
101-
102-
- build: macos
103-
os: macos-latest
104-
target: x86_64-apple-darwin
105-
106-
- build: macos-m1
107-
os: macos-latest
108-
target: aarch64-apple-darwin
109-
110-
- build: windows-gnu
111-
os: windows-latest
112-
target: x86_64-pc-windows-gnu
113-
# python: ["3.9", "3.10", "3.11", "3.12", "3.13"]
114-
89+
outputs:
90+
version: ${{ steps.version.outputs.VERSION }}
11591
steps:
116-
- name: Checkout
117-
uses: actions/checkout@v7
118-
with:
119-
submodules: recursive
120-
- run: rustup toolchain install stable --profile minimal
121-
- if: matrix.os.target == 'x86_64-apple-darwin'
122-
run: rustup target add x86_64-apple-darwin
123-
- uses: Swatinem/rust-cache@v2
124-
with:
125-
cache-workspace-crates: true
126-
add-job-id-key: false
127-
128-
# - name: Set up python
129-
# uses: actions/setup-python@v5
130-
# with:
131-
# python-version: ${{ matrix.python }}
132-
- name: Build
133-
run: cargo build --verbose --release --target ${{ matrix.os.target }}
92+
- uses: actions/checkout@v7
13493
- name: Decide on our version name (tag or "dev")
13594
id: version
13695
shell: bash
13796
run: |
138-
if [ -n "$GITHUB_REF" ]; then
139-
if [[ "$GITHUB_REF" == refs/tags/fontspector-v* ]]; then
140-
echo "VERSION=${GITHUB_REF/refs\/tags\/fontspector-/}" >> $GITHUB_ENV
141-
else
142-
echo "VERSION=dev" >> $GITHUB_ENV
143-
fi
144-
else
145-
echo "VERSION=dev" >> $GITHUB_ENV
146-
fi
147-
- name: Build archive
148-
shell: bash
149-
run: |
150-
# dirname="fontspector-${{ env.VERSION }}-${{ matrix.os.target }}-py${{ matrix.python }}"
151-
dirname="fontspector-${{ env.VERSION }}-${{ matrix.os.target }}"
152-
mkdir "$dirname"
153-
if [ "${{ matrix.os.os }}" = "windows-latest" ]; then
154-
mv "target/${{ matrix.os.target }}/release/"*.exe "$dirname"
155-
7z a "$dirname.zip" "$dirname"
156-
echo "ASSET=$dirname.zip" >> $GITHUB_ENV
97+
if [[ "$GITHUB_REF" == refs/tags/fontspector-v* ]]; then
98+
VERSION="${GITHUB_REF#refs/tags/fontspector-v}"
15799
else
158-
mv "target/${{ matrix.os.target }}/release/fontspector" "$dirname"
159-
tar -czf "$dirname.tar.gz" "$dirname"
160-
echo "ASSET=$dirname.tar.gz" >> $GITHUB_ENV
100+
VERSION="dev"
161101
fi
162-
- uses: actions/upload-artifact@v7
163-
with:
164-
name: ${{ env.ASSET }}
165-
path: ${{ env.ASSET }}
166-
- if: contains(github.ref, 'refs/tags/fontspector-v')
167-
name: Add artefact to release
168-
env:
169-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
170-
run: gh release upload fontspector-${{ env.VERSION }} ${{ env.ASSET }}
102+
echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
103+
104+
deploy-binaries:
105+
name: Build and upload binaries
106+
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/')
107+
needs: compute-version
108+
permissions:
109+
contents: write
110+
id-token: write
111+
uses: ./.github/workflows/build-binary.yml
112+
with:
113+
version: ${{ needs.compute-version.outputs.version }}

0 commit comments

Comments
 (0)