-
Notifications
You must be signed in to change notification settings - Fork 48
191 lines (171 loc) · 6.63 KB
/
Copy pathrelease.yml
File metadata and controls
191 lines (171 loc) · 6.63 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Build and Release Rust Router
# Builds prebuilt grid_router binaries for Linux x86_64, macOS arm64+x86_64,
# and Windows x86_64 whenever a version tag (vX.Y.Z) is pushed, packages
# them into KiCad PCM (Plugin and Content Manager) zips, and attaches
# everything to a GitHub Release.
#
# The Rust crate uses pyo3 abi3-py39, so one binary per platform works for
# every Python 3.9+ interpreter.
on:
push:
tags:
- 'v*'
workflow_dispatch: # allow manual runs from the Actions tab
permissions:
contents: write # needed to create/update the GitHub Release
jobs:
validate:
name: Validate version consistency
runs-on: ubuntu-latest
# Fail in seconds — before the ~10-min build matrix — if VERSION,
# metadata.json, and the pushed tag disagree (the half-bumped state that
# broke v0.17.0). Otherwise the mismatch only surfaces in the package job
# after every binary is built.
steps:
- uses: actions/checkout@v6
- name: VERSION <-> metadata.json (and tag) agree
shell: bash
run: |
if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then
python3 check_release_version.py --tag "${GITHUB_REF#refs/tags/}"
else
python3 check_release_version.py
fi
build:
name: Build ${{ matrix.target_name }}
needs: validate
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
target_name: linux-x86_64
artifact_src: rust_router/target/release/libgrid_router.so
artifact_dst: grid_router-linux-x86_64.so
cargo_target: ''
extra_rustflags: ''
- os: macos-14
target_name: macos-arm64
artifact_src: rust_router/target/release/libgrid_router.dylib
artifact_dst: grid_router-macos-arm64.so
cargo_target: ''
# pyo3's extension-module needs these on macOS so Python symbols
# resolve at load time inside the interpreter instead of at link
# time. Locally pyo3-build-config sets this for you; in CI it
# doesn't always, so set it explicitly.
extra_rustflags: '-C link-arg=-undefined -C link-arg=dynamic_lookup'
# Cross-compile x86_64 macOS from the arm64 runner — macos-13
# runners are scarce and queue for 30+ min in the free tier.
- os: macos-14
target_name: macos-x86_64
artifact_src: rust_router/target/x86_64-apple-darwin/release/libgrid_router.dylib
artifact_dst: grid_router-macos-x86_64.so
cargo_target: 'x86_64-apple-darwin'
extra_rustflags: '-C link-arg=-undefined -C link-arg=dynamic_lookup'
- os: windows-latest
target_name: windows-x86_64
artifact_src: rust_router/target/release/grid_router.dll
artifact_dst: grid_router-windows-x86_64.pyd
cargo_target: ''
extra_rustflags: ''
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v6
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.cargo_target }}
- name: Cache cargo registry and target
uses: actions/cache@v5
with:
path: |
~/.cargo/registry
~/.cargo/git
rust_router/target
key: ${{ runner.os }}-${{ matrix.target_name }}-cargo-${{ hashFiles('rust_router/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-${{ matrix.target_name }}-cargo-
- name: Build release binary
shell: bash
env:
RUSTFLAGS: ${{ matrix.extra_rustflags }}
CARGO_TARGET: ${{ matrix.cargo_target }}
run: |
if [ -n "$CARGO_TARGET" ]; then
cargo build --release --target "$CARGO_TARGET" --manifest-path rust_router/Cargo.toml
else
cargo build --release --manifest-path rust_router/Cargo.toml
fi
- name: Stage artifact
shell: bash
run: cp "${{ matrix.artifact_src }}" "${{ matrix.artifact_dst }}"
- name: Upload artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_dst }}
path: ${{ matrix.artifact_dst }}
if-no-files-found: error
package:
name: Build PCM zips
needs: build
runs-on: ubuntu-latest
# We always package (even on manual workflow_dispatch) so PRs/branches
# can produce a downloadable zip for inspection. metadata.json is only
# committed/PR'd on tag pushes (see the release job below).
steps:
- uses: actions/checkout@v6
- name: Download all built binaries
uses: actions/download-artifact@v8
with:
path: artifacts
merge-multiple: true
- name: List downloaded binaries
run: ls -la artifacts
- name: Build PCM zip
run: python3 package_pcm.py --binary-dir artifacts
- name: Patch metadata.json with sha256 / sizes
run: |
python3 update_metadata.py \
--sidecar dist/KiCadRoutingTools-*.zip.meta.json \
--repo '${{ github.repository }}'
- name: List PCM artifacts
run: ls -la dist
- name: Upload PCM zips + metadata
uses: actions/upload-artifact@v7
with:
name: pcm-package
path: |
dist/*.zip
dist/*.meta.json
metadata.json
if-no-files-found: error
release:
name: Publish GitHub Release
needs: [build, package]
runs-on: ubuntu-latest
# Only publish a Release when a tag was pushed; manual runs just produce
# downloadable workflow artifacts.
if: startsWith(github.ref, 'refs/tags/v')
steps:
- name: Download all built binaries
uses: actions/download-artifact@v8
with:
path: artifacts
merge-multiple: true
- name: List downloaded files
run: ls -la artifacts
- name: Create or update GitHub Release
uses: softprops/action-gh-release@v3
with:
# Attach: raw binaries, PCM zips, and the patched metadata.json
# (so a maintainer can grab the exact metadata.json that matches
# the published zips for submission to gitlab.com/kicad/addons).
# The package job uploaded the zips under dist/, and merge-multiple
# strips the artifact name but preserves the in-artifact path, so
# they land at artifacts/dist/.
files: |
artifacts/grid_router-*
artifacts/dist/KiCadRoutingTools-*.zip
artifacts/metadata.json
generate_release_notes: true
fail_on_unmatched_files: true