|
| 1 | +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json |
| 2 | + |
| 3 | +# Regenerate snapshot goldens stored at |
| 4 | +# ghcr.io/hyperlight-dev/hyperlight-snapshot-goldens. |
| 5 | +# |
| 6 | +# Run order: |
| 7 | +# |
| 8 | +# 1. Bump `GOLDENS_VERSION` in |
| 9 | +# `src/hyperlight_host/tests/snapshot_goldens/platform.rs` and any |
| 10 | +# matching constants in |
| 11 | +# `src/hyperlight_host/src/sandbox/snapshot/tripwires.rs`. |
| 12 | +# 2. Push the bump on a branch. |
| 13 | +# 3. Dispatch this workflow against the branch, passing the same |
| 14 | +# version string as the `version` input. |
| 15 | +# |
| 16 | +# The workflow walks every (hv, cpu, config) cell, dumps the |
| 17 | +# canonical init+call snapshots locally, then `oras copy`s each as |
| 18 | +# its own GHCR tag named |
| 19 | +# `{version}-{hv}-{cpu}-{profile}-{kind}`. |
| 20 | + |
| 21 | +name: Regenerate Snapshot Goldens |
| 22 | + |
| 23 | +on: |
| 24 | + workflow_dispatch: |
| 25 | + inputs: |
| 26 | + version: |
| 27 | + description: Goldens version string. Must match GOLDENS_VERSION in source (e.g. "v1.0"). |
| 28 | + required: true |
| 29 | + type: string |
| 30 | + |
| 31 | +env: |
| 32 | + CARGO_TERM_COLOR: always |
| 33 | + RUST_BACKTRACE: full |
| 34 | + GHCR_IMAGE: ghcr.io/hyperlight-dev/hyperlight-snapshot-goldens |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + packages: write |
| 39 | + |
| 40 | +defaults: |
| 41 | + run: |
| 42 | + shell: bash |
| 43 | + |
| 44 | +jobs: |
| 45 | + build-guests: |
| 46 | + strategy: |
| 47 | + matrix: |
| 48 | + config: [debug, release] |
| 49 | + uses: ./.github/workflows/dep_build_guests.yml |
| 50 | + with: |
| 51 | + config: ${{ matrix.config }} |
| 52 | + secrets: inherit |
| 53 | + |
| 54 | + dump-and-push: |
| 55 | + needs: build-guests |
| 56 | + strategy: |
| 57 | + fail-fast: false |
| 58 | + matrix: |
| 59 | + hypervisor: [kvm, mshv3, hyperv-ws2025] |
| 60 | + cpu: [amd, intel] |
| 61 | + config: [debug, release] |
| 62 | + runs-on: ${{ fromJson( |
| 63 | + format('["self-hosted", "{0}", "X64", "1ES.Pool=hld-{1}-{2}", "JobId=regen-goldens-{3}-{4}-{5}-{6}"]', |
| 64 | + matrix.hypervisor == 'hyperv-ws2025' && 'Windows' || 'Linux', |
| 65 | + matrix.hypervisor == 'hyperv-ws2025' && 'win2025' || matrix.hypervisor == 'mshv3' && 'azlinux3-mshv' || matrix.hypervisor, |
| 66 | + matrix.cpu, |
| 67 | + matrix.config, |
| 68 | + github.run_id, |
| 69 | + github.run_number, |
| 70 | + github.run_attempt)) }} |
| 71 | + steps: |
| 72 | + - uses: actions/checkout@v6 |
| 73 | + |
| 74 | + - uses: hyperlight-dev/ci-setup-workflow@v1.9.0 |
| 75 | + with: |
| 76 | + rust-toolchain: "1.89" |
| 77 | + env: |
| 78 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 79 | + |
| 80 | + - name: Fix cargo home permissions |
| 81 | + if: runner.os == 'Linux' |
| 82 | + run: sudo chown -R $(id -u):$(id -g) /opt/cargo || true |
| 83 | + |
| 84 | + - name: Download Rust guests |
| 85 | + uses: actions/download-artifact@v7 |
| 86 | + with: |
| 87 | + name: rust-guests-${{ matrix.config }} |
| 88 | + path: src/tests/rust_guests/bin/${{ matrix.config }}/ |
| 89 | + |
| 90 | + - name: Install oras |
| 91 | + run: | |
| 92 | + set -euo pipefail |
| 93 | + if command -v oras >/dev/null 2>&1; then |
| 94 | + echo "oras already installed: $(oras version)" |
| 95 | + exit 0 |
| 96 | + fi |
| 97 | + ORAS_VERSION=1.2.2 |
| 98 | + if [ "${{ runner.os }}" = "Windows" ]; then |
| 99 | + curl -sSLO "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_windows_amd64.zip" |
| 100 | + unzip -q "oras_${ORAS_VERSION}_windows_amd64.zip" -d oras_install |
| 101 | + mv oras_install/oras.exe /usr/bin/oras.exe |
| 102 | + else |
| 103 | + curl -sSLO "https://github.com/oras-project/oras/releases/download/v${ORAS_VERSION}/oras_${ORAS_VERSION}_linux_amd64.tar.gz" |
| 104 | + mkdir -p oras_install |
| 105 | + tar -xzf "oras_${ORAS_VERSION}_linux_amd64.tar.gz" -C oras_install |
| 106 | + sudo install -m 0755 oras_install/oras /usr/local/bin/oras |
| 107 | + fi |
| 108 | + oras version |
| 109 | +
|
| 110 | + - name: Verify GOLDENS_VERSION matches input |
| 111 | + run: | |
| 112 | + set -euo pipefail |
| 113 | + IN_SRC=$(grep -oE 'GOLDENS_VERSION: &str = "[^"]+"' src/hyperlight_host/tests/snapshot_goldens/platform.rs | head -n1 | sed -E 's/.*"([^"]+)".*/\1/') |
| 114 | + echo "GOLDENS_VERSION in source: ${IN_SRC}" |
| 115 | + echo "version input: ${{ inputs.version }}" |
| 116 | + if [ "${IN_SRC}" != "${{ inputs.version }}" ]; then |
| 117 | + echo "::error::version input does not match GOLDENS_VERSION in source" |
| 118 | + exit 1 |
| 119 | + fi |
| 120 | +
|
| 121 | + - name: Generate snapshots |
| 122 | + run: | |
| 123 | + set -euo pipefail |
| 124 | + OUT="${{ github.workspace }}/snapshot-goldens-out" |
| 125 | + mkdir -p "$OUT" |
| 126 | + PROFILE_FLAG=$([ "${{ matrix.config }}" = "release" ] && echo "--release" || echo "") |
| 127 | + FEATURES=$([ "${{ matrix.hypervisor }}" = "mshv3" ] && echo "mshv3" || echo "kvm") |
| 128 | + if [ "${{ runner.os }}" = "Windows" ]; then FEATURES=""; fi |
| 129 | + cargo test $PROFILE_FLAG -p hyperlight-host \ |
| 130 | + ${FEATURES:+--no-default-features --features "$FEATURES,build-metadata"} \ |
| 131 | + --test snapshot_goldens -- generate "$OUT" |
| 132 | + ls -la "$OUT" |
| 133 | +
|
| 134 | + - name: Log in to GHCR |
| 135 | + run: | |
| 136 | + echo "${{ secrets.GITHUB_TOKEN }}" | oras login ghcr.io -u "${{ github.actor }}" --password-stdin |
| 137 | +
|
| 138 | + - name: Push goldens to GHCR |
| 139 | + run: | |
| 140 | + set -euo pipefail |
| 141 | + OUT="${{ github.workspace }}/snapshot-goldens-out" |
| 142 | + for layout in "$OUT"/*/; do |
| 143 | + tag=$(basename "$layout") |
| 144 | + tag=${tag%/} |
| 145 | + echo "::group::push ${tag}" |
| 146 | + oras copy --from-oci-layout "${layout%/}:${tag}" "${GHCR_IMAGE}:${tag}" |
| 147 | + echo "::endgroup::" |
| 148 | + done |
0 commit comments