|
| 1 | +name: vendor-libs |
| 2 | + |
| 3 | +# The development branches deliberately do not carry the prebuilt libkcl |
| 4 | +# binaries or kcl.wasm — they are ~370MB of compiled artifacts reproducible |
| 5 | +# from the kcl-lang/kcl release of the same version. This workflow vendors them |
| 6 | +# onto a release branch, and release tags are cut from that branch so consumers |
| 7 | +# pinning a tag get a self-contained tree. |
| 8 | +# |
| 9 | +# Why a branch and not a force-moved tag: wasm-test.yaml publishes |
| 10 | +# @kcl-lib/wasm to npm on a tag push, and kcl.wasm is in that package's `files` |
| 11 | +# array. Vendoring by force-updating the tag after the fact would let npm |
| 12 | +# publish run against the pre-vendoring commit and silently ship a package with |
| 13 | +# no runtime in it. See docs/lib-vendoring.md for the full procedure. |
| 14 | +on: |
| 15 | + push: |
| 16 | + branches: |
| 17 | + - 'release/v*' |
| 18 | + workflow_dispatch: |
| 19 | + inputs: |
| 20 | + branch: |
| 21 | + description: Release branch to vendor onto, e.g. release/v0.13.2 |
| 22 | + required: true |
| 23 | + type: string |
| 24 | + kcl_version: |
| 25 | + description: >- |
| 26 | + kcl-lang/kcl release to fetch from. Defaults to the version in the |
| 27 | + branch name. Override only when the lib and kcl versions diverge. |
| 28 | + required: false |
| 29 | + type: string |
| 30 | + |
| 31 | +concurrency: |
| 32 | + group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} |
| 33 | + cancel-in-progress: false |
| 34 | + |
| 35 | +# contents: write so the vendoring commit can be pushed back to the branch. |
| 36 | +permissions: |
| 37 | + contents: write |
| 38 | + |
| 39 | +jobs: |
| 40 | + # The kcl-lang/kcl release has to be published before this branch is pushed; |
| 41 | + # see docs/lib-vendoring.md. |
| 42 | + prebuilt: |
| 43 | + name: Fetch prebuilt runtimes |
| 44 | + runs-on: ubuntu-latest |
| 45 | + outputs: |
| 46 | + branch: ${{ steps.vars.outputs.branch }} |
| 47 | + lib_version: ${{ steps.vars.outputs.lib_version }} |
| 48 | + kcl_version: ${{ steps.vars.outputs.kcl_version }} |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v7 |
| 51 | + |
| 52 | + - name: Resolve versions |
| 53 | + id: vars |
| 54 | + env: |
| 55 | + DISPATCH_BRANCH: ${{ inputs.branch }} |
| 56 | + DISPATCH_KCL_VERSION: ${{ inputs.kcl_version }} |
| 57 | + PUSH_REF: ${{ github.ref }} |
| 58 | + run: | |
| 59 | + set -euo pipefail |
| 60 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 61 | + branch="$DISPATCH_BRANCH" |
| 62 | + else |
| 63 | + branch="${PUSH_REF#refs/heads/}" |
| 64 | + fi |
| 65 | + if [[ ! "$branch" =~ ^release/v[0-9] ]]; then |
| 66 | + echo "::error::expected a release/v<version> branch, got '$branch'" |
| 67 | + exit 1 |
| 68 | + fi |
| 69 | +
|
| 70 | + # The lib version is the branch name; the SDK advertises it on first |
| 71 | + # run and InstallKcl keys its cache directory off it, so vendoring a |
| 72 | + # libkcl from a different version than the SDK claims would be a |
| 73 | + # silent ABI mismatch. Same guard as publish-kcltool.yaml. |
| 74 | + lib_version="v${branch#release/}" |
| 75 | + sdk_version="$(sed -nE 's/^const KCL_VERSION[[:space:]]*=[[:space:]]*"([^"]+)".*/\1/p' go/install/install.go)" |
| 76 | + echo "branch: $branch" |
| 77 | + echo "lib version: $lib_version" |
| 78 | + echo "SDK KCL_VERSION: $sdk_version" |
| 79 | + if [ "$sdk_version" != "$lib_version" ]; then |
| 80 | + echo "::error::go/install/install.go KCL_VERSION ($sdk_version) does not match the branch version ($lib_version). Bump one of them before vendoring." |
| 81 | + exit 1 |
| 82 | + fi |
| 83 | +
|
| 84 | + kcl_version="$DISPATCH_KCL_VERSION" |
| 85 | + if [ -z "$kcl_version" ]; then |
| 86 | + kcl_version="$lib_version" |
| 87 | + fi |
| 88 | + echo "kcl release: $kcl_version" |
| 89 | + { |
| 90 | + echo "branch=$branch" |
| 91 | + echo "lib_version=$lib_version" |
| 92 | + echo "kcl_version=$kcl_version" |
| 93 | + } >> "$GITHUB_OUTPUT" |
| 94 | +
|
| 95 | + - name: Download and stage |
| 96 | + run: | |
| 97 | + ./hack/download-libs.sh --version "${{ steps.vars.outputs.kcl_version }}" \ |
| 98 | + linux-amd64 linux-arm64 linux-musl-amd64 linux-musl-arm64 \ |
| 99 | + darwin-amd64 darwin-arm64 windows-amd64 windows-arm64 \ |
| 100 | + wasm32-wasip1 |
| 101 | +
|
| 102 | + - name: Inventory |
| 103 | + run: | |
| 104 | + set -euo pipefail |
| 105 | + find go/lib wasm -type f \ |
| 106 | + \( -name 'libkcl.*' -o -name 'kcl.dll' -o -name 'kcl.wasm' \) \ |
| 107 | + -exec ls -la {} + |
| 108 | +
|
| 109 | + - uses: actions/upload-artifact@v7 |
| 110 | + with: |
| 111 | + name: prebuilt-libs |
| 112 | + path: | |
| 113 | + go/lib/*/libkcl.so |
| 114 | + go/lib/*/libkcl.dylib |
| 115 | + go/lib/*/libkcl.a |
| 116 | + go/lib/*/kcl.dll |
| 117 | + wasm/kcl.wasm |
| 118 | + if-no-files-found: error |
| 119 | + |
| 120 | + # iOS has no prebuilt source: go/lib/ios-*/libkcl.a is the kcl-lib-c static |
| 121 | + # archive built from this repository's c/ crate, so it is cross-compiled |
| 122 | + # here rather than downloaded. Same recipe as build-libkcl-mobile.yaml. |
| 123 | + ios: |
| 124 | + name: Cross-compile iOS static archives |
| 125 | + runs-on: macos-latest |
| 126 | + needs: [prebuilt] |
| 127 | + steps: |
| 128 | + - uses: actions/checkout@v7 |
| 129 | + |
| 130 | + - name: Build |
| 131 | + run: | |
| 132 | + set -euo pipefail |
| 133 | + ./hack/download-libs.sh \ |
| 134 | + --version "${{ needs.prebuilt.outputs.kcl_version }}" \ |
| 135 | + ios-arm64 ios-arm64-sim |
| 136 | +
|
| 137 | + - name: Verify architectures |
| 138 | + run: | |
| 139 | + set -euo pipefail |
| 140 | + lipo -info go/lib/ios-arm64/libkcl.a |
| 141 | + lipo -info go/lib/ios-arm64-sim/libkcl.a |
| 142 | +
|
| 143 | + - uses: actions/upload-artifact@v7 |
| 144 | + with: |
| 145 | + name: ios-libs |
| 146 | + path: | |
| 147 | + go/lib/ios-arm64/libkcl.a |
| 148 | + go/lib/ios-arm64-sim/libkcl.a |
| 149 | + if-no-files-found: error |
| 150 | + |
| 151 | + vendor: |
| 152 | + name: Commit the binaries onto the release branch |
| 153 | + runs-on: ubuntu-latest |
| 154 | + needs: [prebuilt, ios] |
| 155 | + steps: |
| 156 | + - uses: actions/checkout@v7 |
| 157 | + with: |
| 158 | + # Full history so the commit lands on the branch tip. |
| 159 | + fetch-depth: 0 |
| 160 | + ref: ${{ needs.prebuilt.outputs.branch }} |
| 161 | + |
| 162 | + - uses: actions/download-artifact@v8 |
| 163 | + with: |
| 164 | + path: staged |
| 165 | + |
| 166 | + # Both artifacts are rooted at the repository, so they merge into one |
| 167 | + # staged/ tree without colliding on a path. |
| 168 | + - name: Merge into the working tree |
| 169 | + run: | |
| 170 | + set -euo pipefail |
| 171 | + test -d staged/go/lib || { echo "::error::no artifacts downloaded"; exit 1; } |
| 172 | + mkdir -p go/lib wasm |
| 173 | + cp -Rv staged/go/lib/. go/lib/ |
| 174 | + test -f staged/wasm/kcl.wasm |
| 175 | + install -m 0755 staged/wasm/kcl.wasm wasm/kcl.wasm |
| 176 | +
|
| 177 | + - name: Sanity-check the staged tree |
| 178 | + run: | |
| 179 | + set -euo pipefail |
| 180 | + missing=0 |
| 181 | + for f in \ |
| 182 | + go/lib/darwin-amd64/libkcl.dylib go/lib/darwin-arm64/libkcl.dylib \ |
| 183 | + go/lib/linux-amd64/libkcl.so go/lib/linux-arm64/libkcl.so \ |
| 184 | + go/lib/linux-musl-amd64/libkcl.a go/lib/linux-musl-arm64/libkcl.a \ |
| 185 | + go/lib/windows-amd64/kcl.dll go/lib/windows-arm64/kcl.dll \ |
| 186 | + go/lib/ios-arm64/libkcl.a go/lib/ios-arm64-sim/libkcl.a \ |
| 187 | + wasm/kcl.wasm ; do |
| 188 | + if [ ! -s "$f" ]; then |
| 189 | + echo "::error::missing or empty $f" |
| 190 | + missing=1 |
| 191 | + fi |
| 192 | + done |
| 193 | + [ "$missing" -eq 0 ] || exit 1 |
| 194 | + du -sh go/lib wasm/kcl.wasm |
| 195 | +
|
| 196 | + - name: Commit the binaries onto the branch |
| 197 | + env: |
| 198 | + BRANCH: ${{ needs.prebuilt.outputs.branch }} |
| 199 | + TAG: ${{ needs.prebuilt.outputs.lib_version }} |
| 200 | + run: | |
| 201 | + set -euo pipefail |
| 202 | + git config user.name "github-actions[bot]" |
| 203 | + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" |
| 204 | +
|
| 205 | + # go/.gitignore and wasm/.gitignore exclude these on purpose so the |
| 206 | + # development branches stay small. Force-add: this is the one place |
| 207 | + # the artifacts are meant to be tracked. |
| 208 | + git add -f \ |
| 209 | + go/lib/darwin-amd64/libkcl.dylib go/lib/darwin-arm64/libkcl.dylib \ |
| 210 | + go/lib/linux-amd64/libkcl.so go/lib/linux-arm64/libkcl.so \ |
| 211 | + go/lib/linux-musl-amd64/libkcl.a go/lib/linux-musl-arm64/libkcl.a \ |
| 212 | + go/lib/windows-amd64/kcl.dll go/lib/windows-arm64/kcl.dll \ |
| 213 | + go/lib/ios-arm64/libkcl.a go/lib/ios-arm64-sim/libkcl.a \ |
| 214 | + wasm/kcl.wasm |
| 215 | +
|
| 216 | + if git diff --cached --quiet; then |
| 217 | + echo "Already vendored; nothing to commit." |
| 218 | + exit 0 |
| 219 | + fi |
| 220 | + git commit -m "chore(release): vendor prebuilt runtimes for ${TAG}" |
| 221 | + git push origin "HEAD:${BRANCH}" |
| 222 | +
|
| 223 | + - name: Summary |
| 224 | + if: always() |
| 225 | + env: |
| 226 | + BRANCH: ${{ needs.prebuilt.outputs.branch }} |
| 227 | + TAG: ${{ needs.prebuilt.outputs.lib_version }} |
| 228 | + run: | |
| 229 | + echo "::notice title=Release branch ready::\`${BRANCH}\` now carries the prebuilt runtimes." |
| 230 | + echo "Cut the release tag from this branch, not from main:" |
| 231 | + echo '```' |
| 232 | + echo "git tag ${TAG} ${BRANCH}" |
| 233 | + echo "git push origin ${TAG}" |
| 234 | + echo '```' |
0 commit comments