|
| 1 | +name: Manual Build & Release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + kernel_versions: |
| 7 | + description: 'Comma-separated kernel versions to build (default: kernel_versions.txt)' |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: '' |
| 11 | + build_amd64: |
| 12 | + description: 'Build for amd64 architecture' |
| 13 | + required: false |
| 14 | + type: boolean |
| 15 | + default: true |
| 16 | + build_arm64: |
| 17 | + description: 'Build for arm64 architecture' |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + default: true |
| 21 | + |
| 22 | +permissions: |
| 23 | + contents: write |
| 24 | + id-token: write |
| 25 | + |
| 26 | +jobs: |
| 27 | + validate: |
| 28 | + runs-on: ubuntu-24.04 |
| 29 | + outputs: |
| 30 | + build_matrix: ${{ steps.validate.outputs.build_matrix }} |
| 31 | + versions: ${{ steps.validate.outputs.versions }} |
| 32 | + has_new_artifacts: ${{ steps.validate.outputs.has_new_artifacts }} |
| 33 | + steps: |
| 34 | + - uses: actions/checkout@v4 |
| 35 | + |
| 36 | + - uses: actions/setup-python@v5 |
| 37 | + with: |
| 38 | + python-version: '3.11' |
| 39 | + |
| 40 | + - id: validate |
| 41 | + env: |
| 42 | + GH_TOKEN: ${{ github.token }} |
| 43 | + run: | |
| 44 | + python3 scripts/validate.py \ |
| 45 | + --kernel-versions "${{ inputs.kernel_versions }}" \ |
| 46 | + --build-amd64 "${{ inputs.build_amd64 }}" \ |
| 47 | + --build-arm64 "${{ inputs.build_arm64 }}" |
| 48 | +
|
| 49 | + build: |
| 50 | + needs: validate |
| 51 | + if: needs.validate.outputs.has_new_artifacts == 'true' |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: ${{ fromJson(needs.validate.outputs.build_matrix) }} |
| 55 | + runs-on: ${{ matrix.runner }} |
| 56 | + steps: |
| 57 | + - uses: actions/checkout@v4 |
| 58 | + |
| 59 | + - name: Build kernel ${{ matrix.version_name }} (${{ matrix.arch }}) |
| 60 | + env: |
| 61 | + VERSION_NAME: ${{ matrix.version_name }} |
| 62 | + run: | |
| 63 | + target_arch="${{ matrix.arch }}" |
| 64 | + [ "$target_arch" = "amd64" ] && target_arch="x86_64" |
| 65 | + sudo VERSION_NAME="$VERSION_NAME" ./build.sh "${{ matrix.kernel_version }}" "$target_arch" |
| 66 | +
|
| 67 | + - uses: actions/upload-artifact@v4 |
| 68 | + with: |
| 69 | + name: ${{ matrix.version_name }}-${{ matrix.arch }} |
| 70 | + path: ./builds/${{ matrix.version_name }} |
| 71 | + retention-days: 7 |
| 72 | + |
| 73 | + publish: |
| 74 | + needs: [validate, build] |
| 75 | + if: needs.validate.outputs.has_new_artifacts == 'true' |
| 76 | + runs-on: ubuntu-24.04 |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v4 |
| 79 | + with: |
| 80 | + fetch-depth: 0 |
| 81 | + |
| 82 | + - uses: actions/download-artifact@v4 |
| 83 | + with: |
| 84 | + path: ./builds |
| 85 | + merge-multiple: true |
| 86 | + |
| 87 | + - name: Show build artifacts |
| 88 | + run: find ./builds -type f | head -50 |
| 89 | + |
| 90 | + - name: Create or update releases |
| 91 | + env: |
| 92 | + GH_TOKEN: ${{ github.token }} |
| 93 | + VERSIONS: ${{ needs.validate.outputs.versions }} |
| 94 | + run: | |
| 95 | + set -euo pipefail |
| 96 | + git config user.name "github-actions[bot]" |
| 97 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 98 | +
|
| 99 | + echo "$VERSIONS" | jq -c '.[]' | while read -r entry; do |
| 100 | + version_name=$(echo "$entry" | jq -r '.version_name') |
| 101 | + kernel_version=$(echo "$entry" | jq -r '.kernel_version') |
| 102 | +
|
| 103 | + if ! gh release view "$version_name" >/dev/null 2>&1; then |
| 104 | + if ! git rev-parse "refs/tags/$version_name" >/dev/null 2>&1; then |
| 105 | + git tag "$version_name" |
| 106 | + git push origin "$version_name" |
| 107 | + fi |
| 108 | + gh release create "$version_name" \ |
| 109 | + --title "Kernel $version_name" \ |
| 110 | + --notes "Linux kernel $kernel_version built from configs at ${{ github.sha }}" |
| 111 | + fi |
| 112 | +
|
| 113 | + existing=$(gh release view "$version_name" --json assets -q '.assets[].name' || true) |
| 114 | +
|
| 115 | + for arch in amd64 arm64; do |
| 116 | + local_path="./builds/$version_name/$arch/vmlinux.bin" |
| 117 | + [ -f "$local_path" ] || continue |
| 118 | +
|
| 119 | + asset="vmlinux-${arch}.bin" |
| 120 | + if echo "$existing" | grep -qx "$asset"; then |
| 121 | + echo "Release $version_name: $asset exists, skipping" |
| 122 | + else |
| 123 | + tmp=$(mktemp -d)/$asset |
| 124 | + cp "$local_path" "$tmp" |
| 125 | + gh release upload "$version_name" "$tmp" |
| 126 | + rm -f "$tmp" |
| 127 | + fi |
| 128 | +
|
| 129 | + # Legacy non-arch-suffixed asset (amd64 only) for backwards compat. |
| 130 | + if [ "$arch" = "amd64" ] && ! echo "$existing" | grep -qx "vmlinux.bin"; then |
| 131 | + tmp=$(mktemp -d)/vmlinux.bin |
| 132 | + cp "$local_path" "$tmp" |
| 133 | + gh release upload "$version_name" "$tmp" |
| 134 | + rm -f "$tmp" |
| 135 | + fi |
| 136 | + done |
| 137 | + done |
| 138 | +
|
| 139 | + deploy: |
| 140 | + needs: [validate, publish] |
| 141 | + if: needs.validate.outputs.has_new_artifacts == 'true' |
| 142 | + runs-on: ubuntu-24.04 |
| 143 | + steps: |
| 144 | + - uses: actions/checkout@v4 |
| 145 | + |
| 146 | + - uses: google-github-actions/auth@v2 |
| 147 | + with: |
| 148 | + workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }} |
| 149 | + service_account: ${{ secrets.GCP_SERVICE_ACCOUNT_EMAIL }} |
| 150 | + |
| 151 | + - uses: google-github-actions/setup-gcloud@v2 |
| 152 | + |
| 153 | + - name: Download release assets and upload to GCS |
| 154 | + env: |
| 155 | + GH_TOKEN: ${{ github.token }} |
| 156 | + GCP_BUCKET_NAME: ${{ vars.GCP_BUCKET_NAME }} |
| 157 | + VERSIONS: ${{ needs.validate.outputs.versions }} |
| 158 | + run: | |
| 159 | + set -euo pipefail |
| 160 | + echo "$VERSIONS" | jq -c '.[]' | while read -r entry; do |
| 161 | + version_name=$(echo "$entry" | jq -r '.version_name') |
| 162 | +
|
| 163 | + for arch in amd64 arm64; do |
| 164 | + asset="vmlinux-${arch}.bin" |
| 165 | + dl_dir="./dl/$version_name/$arch" |
| 166 | + mkdir -p "$dl_dir" |
| 167 | + if ! gh release download "$version_name" \ |
| 168 | + --repo "${{ github.repository }}" \ |
| 169 | + --pattern "$asset" \ |
| 170 | + --output "$dl_dir/vmlinux.bin" 2>/dev/null; then |
| 171 | + continue |
| 172 | + fi |
| 173 | +
|
| 174 | + gcs_path="gs://${GCP_BUCKET_NAME}/kernels/${version_name}/${arch}/vmlinux.bin" |
| 175 | + if gcloud storage ls "$gcs_path" >/dev/null 2>&1; then |
| 176 | + echo "GCS: $gcs_path exists, skipping" |
| 177 | + else |
| 178 | + gcloud storage cp "$dl_dir/vmlinux.bin" "$gcs_path" |
| 179 | + fi |
| 180 | +
|
| 181 | + # Legacy non-arch path (amd64 only) for backwards compat. |
| 182 | + if [ "$arch" = "amd64" ]; then |
| 183 | + legacy_path="gs://${GCP_BUCKET_NAME}/kernels/${version_name}/vmlinux.bin" |
| 184 | + if gcloud storage ls "$legacy_path" >/dev/null 2>&1; then |
| 185 | + echo "GCS: $legacy_path exists, skipping" |
| 186 | + else |
| 187 | + gcloud storage cp "$dl_dir/vmlinux.bin" "$legacy_path" |
| 188 | + fi |
| 189 | + fi |
| 190 | + done |
| 191 | + done |
0 commit comments