|
| 1 | +name: Blacksmith Build Artifacts Testbox |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + testbox_id: |
| 7 | + type: string |
| 8 | + description: "Testbox session ID" |
| 9 | + required: true |
| 10 | + pull_request: |
| 11 | + paths: |
| 12 | + - ".github/workflows/**" |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +env: |
| 18 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" |
| 19 | + |
| 20 | +jobs: |
| 21 | + build-artifacts: |
| 22 | + permissions: |
| 23 | + contents: read |
| 24 | + name: "build-artifacts" |
| 25 | + runs-on: blacksmith-8vcpu-ubuntu-2404 |
| 26 | + timeout-minutes: 35 |
| 27 | + steps: |
| 28 | + - name: Begin Testbox |
| 29 | + uses: useblacksmith/begin-testbox@v2 |
| 30 | + with: |
| 31 | + testbox_id: ${{ inputs.testbox_id }} |
| 32 | + |
| 33 | + - name: Checkout |
| 34 | + shell: bash |
| 35 | + env: |
| 36 | + CHECKOUT_REPO: ${{ github.repository }} |
| 37 | + CHECKOUT_SHA: ${{ github.sha }} |
| 38 | + CHECKOUT_TOKEN: ${{ github.token }} |
| 39 | + run: | |
| 40 | + set -euo pipefail |
| 41 | +
|
| 42 | + workdir="$GITHUB_WORKSPACE" |
| 43 | + auth_header="$(printf 'x-access-token:%s' "$CHECKOUT_TOKEN" | base64 | tr -d '\n')" |
| 44 | +
|
| 45 | + reset_checkout_dir() { |
| 46 | + mkdir -p "$workdir" |
| 47 | + find "$workdir" -mindepth 1 -maxdepth 1 -exec rm -rf {} + |
| 48 | + } |
| 49 | +
|
| 50 | + checkout_attempt() { |
| 51 | + local attempt="$1" |
| 52 | +
|
| 53 | + reset_checkout_dir |
| 54 | + git init "$workdir" >/dev/null |
| 55 | + git config --global --add safe.directory "$workdir" |
| 56 | + git -C "$workdir" remote add origin "https://github.com/${CHECKOUT_REPO}" |
| 57 | + git -C "$workdir" config gc.auto 0 |
| 58 | +
|
| 59 | + timeout --signal=TERM 30s git -C "$workdir" \ |
| 60 | + -c protocol.version=2 \ |
| 61 | + -c "http.https://github.com/.extraheader=AUTHORIZATION: basic ${auth_header}" \ |
| 62 | + fetch --no-tags --prune --no-recurse-submodules --depth=1 origin \ |
| 63 | + "+${CHECKOUT_SHA}:refs/remotes/origin/ci-target" || return 1 |
| 64 | +
|
| 65 | + git -C "$workdir" checkout --force --detach "$CHECKOUT_SHA" || return 1 |
| 66 | + test -f "$workdir/.github/actions/setup-node-env/action.yml" || return 1 |
| 67 | + echo "checkout attempt ${attempt}/5 succeeded" |
| 68 | + } |
| 69 | +
|
| 70 | + for attempt in 1 2 3 4 5; do |
| 71 | + if checkout_attempt "$attempt"; then |
| 72 | + exit 0 |
| 73 | + fi |
| 74 | + echo "checkout attempt ${attempt}/5 failed" |
| 75 | + sleep $((attempt * 5)) |
| 76 | + done |
| 77 | +
|
| 78 | + echo "checkout failed after 5 attempts" >&2 |
| 79 | + exit 1 |
| 80 | +
|
| 81 | + - name: Setup Node environment |
| 82 | + uses: ./.github/actions/setup-node-env |
| 83 | + with: |
| 84 | + install-bun: "false" |
| 85 | + |
| 86 | + - name: Resolve release dist cache seeds |
| 87 | + id: dist-cache-seeds |
| 88 | + shell: bash |
| 89 | + run: | |
| 90 | + set -euo pipefail |
| 91 | +
|
| 92 | + cache_prefix="${RUNNER_OS}-dist-build-" |
| 93 | + declare -A seen=() |
| 94 | +
|
| 95 | + resolve_tag_sha() { |
| 96 | + local tag="$1" |
| 97 | + local direct="" |
| 98 | + local peeled="" |
| 99 | +
|
| 100 | + while read -r sha ref; do |
| 101 | + if [[ "$ref" == "refs/tags/${tag}^{}" ]]; then |
| 102 | + peeled="$sha" |
| 103 | + elif [[ "$ref" == "refs/tags/${tag}" ]]; then |
| 104 | + direct="$sha" |
| 105 | + fi |
| 106 | + done < <(git ls-remote --tags origin "refs/tags/${tag}" "refs/tags/${tag}^{}") |
| 107 | +
|
| 108 | + printf '%s\n' "${peeled:-$direct}" |
| 109 | + } |
| 110 | +
|
| 111 | + { |
| 112 | + echo "restore-keys<<EOF" |
| 113 | + for dist_tag in beta latest; do |
| 114 | + version="$(npm view "openclaw@${dist_tag}" version 2>/dev/null || true)" |
| 115 | + if [[ -z "$version" ]]; then |
| 116 | + echo "Could not resolve npm dist-tag ${dist_tag}; skipping cache seed." >&2 |
| 117 | + continue |
| 118 | + fi |
| 119 | +
|
| 120 | + sha="$(resolve_tag_sha "v${version}")" |
| 121 | + if [[ -z "$sha" ]]; then |
| 122 | + echo "Could not resolve git tag v${version}; skipping cache seed." >&2 |
| 123 | + continue |
| 124 | + fi |
| 125 | +
|
| 126 | + key="${cache_prefix}${sha}" |
| 127 | + if [[ -z "${seen[$key]+x}" ]]; then |
| 128 | + echo "$key" |
| 129 | + seen[$key]=1 |
| 130 | + fi |
| 131 | + done |
| 132 | + echo "${cache_prefix}" |
| 133 | + echo "EOF" |
| 134 | + } >> "$GITHUB_OUTPUT" |
| 135 | +
|
| 136 | + - name: Restore dist build cache |
| 137 | + id: dist-cache |
| 138 | + uses: actions/cache@v5 |
| 139 | + with: |
| 140 | + path: | |
| 141 | + .artifacts/build-all-cache/ |
| 142 | + dist/ |
| 143 | + dist-runtime/ |
| 144 | + key: ${{ runner.os }}-dist-build-${{ github.sha }} |
| 145 | + restore-keys: ${{ steps.dist-cache-seeds.outputs.restore-keys }} |
| 146 | + |
| 147 | + - name: Build dist on cache miss |
| 148 | + if: steps.dist-cache.outputs.cache-hit != 'true' |
| 149 | + run: pnpm build:ci-artifacts |
| 150 | + |
| 151 | + - name: Build Control UI on cache miss |
| 152 | + if: steps.dist-cache.outputs.cache-hit != 'true' |
| 153 | + run: pnpm ui:build |
| 154 | + |
| 155 | + - name: Verify build artifacts |
| 156 | + shell: bash |
| 157 | + run: | |
| 158 | + set -euo pipefail |
| 159 | +
|
| 160 | + test -d dist |
| 161 | + test -d dist-runtime |
| 162 | + if [[ ! -f dist/index.js && ! -f dist/index.mjs ]]; then |
| 163 | + echo "Missing dist/index.js or dist/index.mjs" >&2 |
| 164 | + exit 1 |
| 165 | + fi |
| 166 | + test -f dist/build-info.json |
| 167 | + test -f dist/control-ui/index.html |
| 168 | +
|
| 169 | + - name: Prepare Testbox shell |
| 170 | + shell: bash |
| 171 | + run: | |
| 172 | + set -euo pipefail |
| 173 | +
|
| 174 | + git fetch --no-tags --depth=50 origin "+refs/heads/main:refs/remotes/origin/main" |
| 175 | +
|
| 176 | + node_bin="$(dirname "$(node -p 'process.execPath')")" |
| 177 | + pnpm_bin="$(command -v pnpm)" |
| 178 | + sudo ln -sf "$node_bin/node" /usr/local/bin/node |
| 179 | + sudo ln -sf "$node_bin/npm" /usr/local/bin/npm |
| 180 | + sudo ln -sf "$node_bin/npx" /usr/local/bin/npx |
| 181 | + sudo ln -sf "$node_bin/corepack" /usr/local/bin/corepack |
| 182 | + sudo ln -sf "$pnpm_bin" /usr/local/bin/pnpm |
| 183 | +
|
| 184 | + - name: Run Testbox |
| 185 | + uses: useblacksmith/run-testbox@v2 |
| 186 | + if: always() |
| 187 | + env: |
| 188 | + FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: "true" |
0 commit comments