Skip to content

Commit 8718536

Browse files
committed
Refactor
1 parent a45d039 commit 8718536

File tree

6 files changed

+126
-173
lines changed

6 files changed

+126
-173
lines changed

.github/workflows/build.yml

Lines changed: 14 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,49 +2,27 @@ name: Build Firecracker Versions
22

33
on:
44
workflow_call:
5-
outputs:
6-
versions:
7-
description: "JSON array of versions that were built"
8-
value: ${{ jobs.prepare.outputs.versions }}
5+
inputs:
6+
version:
7+
required: true
8+
type: string
9+
hash:
10+
required: true
11+
type: string
12+
version_name:
13+
required: true
14+
type: string
915
workflow_dispatch:
1016

1117
jobs:
12-
prepare:
13-
runs-on: ubuntu-latest
14-
outputs:
15-
versions: ${{ steps.set-versions.outputs.versions }}
16-
steps:
17-
- uses: actions/checkout@v4
18-
19-
- name: Parse versions from file
20-
id: set-versions
21-
run: |
22-
versions=$(./scripts/parse-versions.sh firecracker_versions.txt)
23-
echo "versions=$versions" >> $GITHUB_OUTPUT
24-
echo "Building versions: $versions"
25-
2618
build:
27-
needs: prepare
2819
runs-on: ubuntu-latest
29-
strategy:
30-
fail-fast: true
31-
matrix:
32-
version: ${{ fromJson(needs.prepare.outputs.versions) }}
3320
steps:
3421
- uses: actions/checkout@v4
35-
36-
- name: Build Firecracker ${{ matrix.version }}
37-
id: build
38-
run: |
39-
./build.sh "${{ matrix.version }}"
40-
# Read the computed version name (with hash) - format is "version_name:commit_hash"
41-
version_info=$(cat built_versions.txt | tail -1)
42-
version_name=$(echo "$version_info" | cut -d: -f1)
43-
echo "version_name=$version_name" >> $GITHUB_OUTPUT
44-
45-
- name: Upload build artifact
46-
uses: actions/upload-artifact@v4
22+
- name: Build Firecracker ${{ inputs.version_name }}
23+
run: ./build.sh "${{ inputs.version }}" "${{ inputs.hash }}" "${{ inputs.version_name }}"
24+
- uses: actions/upload-artifact@v4
4725
with:
48-
name: firecracker-${{ steps.build.outputs.version_name }}
26+
name: firecracker-${{ inputs.version_name }}
4927
path: builds/
5028
retention-days: 7

.github/workflows/fc-versions.yml

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -13,55 +13,61 @@ permissions:
1313
contents: write
1414

1515
jobs:
16-
# Run parallel builds via reusable workflow
16+
prepare:
17+
runs-on: ubuntu-latest
18+
outputs:
19+
matrix: ${{ steps.set-matrix.outputs.matrix }}
20+
steps:
21+
- uses: actions/checkout@v4
22+
- name: Parse versions and resolve hashes
23+
id: set-matrix
24+
run: |
25+
versions_json=$(./scripts/parse-versions-with-hash.sh firecracker_versions.txt)
26+
echo "matrix=$versions_json" >> $GITHUB_OUTPUT
27+
1728
build:
29+
needs: prepare
1830
uses: ./.github/workflows/build.yml
31+
strategy:
32+
fail-fast: true
33+
matrix:
34+
include: ${{ fromJson(needs.prepare.outputs.matrix) }}
35+
with:
36+
version: ${{ matrix.version }}
37+
hash: ${{ matrix.hash }}
38+
version_name: ${{ matrix.version_name }}
1939

20-
# Check CI status in parallel with builds (for faster feedback)
2140
check-ci:
22-
name: Check FC repo CI status
2341
runs-on: ubuntu-latest
2442
outputs:
2543
ci_passed: ${{ steps.ci-check.outputs.ci_passed }}
2644
steps:
2745
- uses: actions/checkout@v4
28-
29-
- name: Check CI status for all versions
46+
- name: Check CI status
3047
id: ci-check
3148
env:
3249
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3350
run: |
3451
output=$(./scripts/check-fc-ci.sh firecracker_versions.txt)
3552
echo "$output"
36-
# Extract ci_passed from last line
3753
ci_passed=$(echo "$output" | grep "^ci_passed=" | cut -d= -f2)
3854
echo "ci_passed=$ci_passed" >> $GITHUB_OUTPUT
3955
40-
# Collect artifacts and publish (waits for both build and CI check)
4156
publish:
4257
name: Collect and upload builds
4358
needs: [build, check-ci]
4459
runs-on: ubuntu-22.04
4560
steps:
46-
- name: Checkout repository
47-
uses: actions/checkout@v4
61+
- uses: actions/checkout@v4
4862
with:
4963
fetch-depth: 0
50-
51-
# Download all build artifacts
52-
- name: Download all build artifacts
53-
uses: actions/download-artifact@v4
64+
- uses: actions/download-artifact@v4
5465
with:
5566
path: builds
5667
pattern: firecracker-*
5768
merge-multiple: true
58-
59-
- name: List downloaded builds
60-
run: find builds -type f | head -20
61-
6269
- name: CI check result
6370
run: |
64-
echo "CI check passed: ${{ needs.check-ci.outputs.ci_passed }}"
6571
if [[ "${{ needs.check-ci.outputs.ci_passed }}" != "true" ]]; then
6672
echo "⚠️ CI checks did not pass - skipping GCS upload and release"
6773
fi
@@ -82,41 +88,22 @@ jobs:
8288
gzip: false
8389
parent: false
8490

85-
- name: Create releases for each Firecracker version
91+
- name: Create releases
8692
if: github.ref_name == 'main' && needs.check-ci.outputs.ci_passed == 'true'
8793
env:
8894
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8995
run: |
9096
git config user.name "github-actions"
9197
git config user.email "[email protected]"
92-
9398
for dir in ./builds/*/; do
9499
version_name=$(basename "$dir")
95-
binary_path="$dir/firecracker"
96-
97-
echo "Processing $version_name..."
98-
99-
# Check if tag already exists
100-
if git rev-parse "refs/tags/$version_name" >/dev/null 2>&1; then
101-
echo "Tag $version_name already exists, skipping..."
102-
continue
103-
fi
104-
105-
# Check if release already exists
106-
if gh release view "$version_name" >/dev/null 2>&1; then
107-
echo "Release $version_name already exists, skipping..."
100+
if git rev-parse "refs/tags/$version_name" >/dev/null 2>&1 || gh release view "$version_name" >/dev/null 2>&1; then
108101
continue
109102
fi
110-
111-
echo "Creating tag and release for $version_name..."
112-
113-
# Create and push tag
114103
git tag "$version_name"
115104
git push origin "$version_name"
116-
117-
# Create release with the binary
118105
gh release create "$version_name" \
119106
--title "Firecracker $version_name" \
120107
--notes "Firecracker build: $version_name" \
121-
"$binary_path#${version_name}"
108+
"$dir/firecracker#${version_name}"
122109
done

build.sh

Lines changed: 20 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -4,73 +4,34 @@ set -euo pipefail
44

55
FIRECRACKER_REPO_URL="https://github.com/e2b-dev/firecracker.git"
66

7-
function build_version {
8-
local version=$1
9-
10-
# Detect if the version is of the form tag_shorthash (e.g., v1.12.1_abcdef12)
11-
if [[ "$version" =~ ^([^_]+)_([0-9a-fA-F]+)$ ]]; then
12-
local tag="${BASH_REMATCH[1]}"
13-
local shorthash="${BASH_REMATCH[2]}"
14-
echo "Starting build for Firecracker tag: $tag and shorthash: $shorthash"
7+
if [[ $# -lt 3 ]]; then
8+
echo "Usage: $0 <version> <hash> <version_name>" >&2
9+
exit 1
10+
fi
1511

16-
echo "Checking out repo at tag: $tag"
17-
git checkout "$tag"
12+
version="$1"
13+
fullhash="$2"
14+
version_name="$3"
1815

19-
# Find full hash from shorthash
20-
fullhash=$(git rev-parse --verify "$shorthash^{commit}" 2>/dev/null || true)
21-
if [[ -z "$fullhash" ]]; then
22-
echo "Error: Could not resolve hash $shorthash"
23-
exit 1
24-
fi
16+
git clone $FIRECRACKER_REPO_URL firecracker
17+
cd firecracker
2518

26-
# Ensure that $fullhash is a descendant of $tag
27-
if git merge-base --is-ancestor "$tag" "$fullhash"; then
28-
echo "Shorthash $shorthash is AFTER tag $tag -- proceeding"
29-
git checkout "$fullhash"
30-
else
31-
echo "Error: shorthash $shorthash is not a descendant of tag $tag"
32-
exit 1
33-
fi
34-
version_name="${tag}_$shorthash"
35-
else
36-
echo "Starting build for Firecracker at commit: $version"
37-
echo "Checking out repo for Firecracker at commit: $version"
38-
git checkout "${version}"
39-
40-
fullhash=$(git rev-parse HEAD)
41-
# The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
42-
version_name=$(git describe --tags --abbrev=0 "$fullhash")_$(git rev-parse --short HEAD)
19+
if [[ "$version" =~ ^([^_]+)_([0-9a-fA-F]+)$ ]]; then
20+
tag="${BASH_REMATCH[1]}"
21+
git checkout "$tag"
22+
if ! git merge-base --is-ancestor "$tag" "$fullhash"; then
23+
echo "Error: shorthash is not a descendant of tag $tag" >&2
24+
exit 1
4325
fi
44-
45-
echo "Version name: $version_name"
46-
47-
echo "Building Firecracker version: $version_name"
48-
# Build only the firecracker binary, skip jailer and snapshot-editor for faster builds
49-
tools/devtool -y build --release -- --bin firecracker
50-
51-
echo "Copying finished build to builds directory"
52-
mkdir -p "../builds/${version_name}"
53-
cp build/cargo_target/x86_64-unknown-linux-musl/release/firecracker "../builds/${version_name}/firecracker"
54-
55-
# Write version name and commit hash to file for CI to use
56-
echo "${version_name}:${fullhash}" >> ../built_versions.txt
57-
}
58-
59-
# If a version is passed as argument, build only that version
60-
# Otherwise, build all versions from firecracker_versions.txt
61-
if [[ $# -ge 1 ]]; then
62-
versions=("$@")
26+
git checkout "$fullhash"
6327
else
64-
mapfile -t versions < <(grep -v '^ *#' firecracker_versions.txt | grep -v '^$')
28+
git checkout "$fullhash"
6529
fi
6630

67-
echo "Cloning the Firecracker repository"
68-
git clone $FIRECRACKER_REPO_URL firecracker
69-
cd firecracker
31+
tools/devtool -y build --release -- --bin firecracker
7032

71-
for version in "${versions[@]}"; do
72-
build_version "$version"
73-
done
33+
mkdir -p "../builds/${version_name}"
34+
cp build/cargo_target/x86_64-unknown-linux-musl/release/firecracker "../builds/${version_name}/firecracker"
7435

7536
cd ..
7637
rm -rf firecracker

scripts/check-fc-ci.sh

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
#!/bin/bash
2-
# Check CI status for all Firecracker versions
3-
# Outputs: ci_passed=true|false to stdout (for GitHub Actions)
42

53
set -euo pipefail
64

@@ -13,34 +11,25 @@ if [[ ! -f "$VERSIONS_FILE" ]]; then
1311
exit 1
1412
fi
1513

16-
# Clone FC repo to resolve commit hashes
1714
TEMP_DIR=$(mktemp -d)
1815
trap "rm -rf $TEMP_DIR" EXIT
1916

20-
echo "Cloning FC repo to resolve commit hashes..."
2117
git clone --bare "$FIRECRACKER_REPO_URL" "$TEMP_DIR/fc-repo" 2>/dev/null
2218
cd "$TEMP_DIR/fc-repo"
2319

2420
all_passed=true
2521
failed_versions=""
2622

27-
# Read versions from file
2823
while IFS= read -r version || [[ -n "$version" ]]; do
29-
# Skip comments and empty lines
3024
[[ "$version" =~ ^[[:space:]]*# ]] && continue
3125
[[ -z "$version" ]] && continue
3226

33-
echo "Processing version: $version"
34-
35-
# Resolve commit hash
3627
if [[ "$version" =~ ^([^_]+)_([0-9a-fA-F]+)$ ]]; then
37-
# Format: tag_shorthash
3828
tag="${BASH_REMATCH[1]}"
3929
shorthash="${BASH_REMATCH[2]}"
4030
commit_hash=$(git rev-parse --verify "$shorthash^{commit}" 2>/dev/null || echo "")
4131
version_name="${tag}_${shorthash}"
4232
else
43-
# Plain tag
4433
commit_hash=$(git rev-parse --verify "${version}^{commit}" 2>/dev/null || echo "")
4534
if [[ -n "$commit_hash" ]]; then
4635
short_hash=$(git rev-parse --short "$commit_hash")
@@ -57,15 +46,10 @@ while IFS= read -r version || [[ -n "$version" ]]; do
5746
continue
5847
fi
5948

60-
echo " Checking CI for $version_name (commit: $commit_hash)..."
61-
62-
# Check combined commit status (returns total_count of statuses)
6349
status_response=$(gh api "/repos/${FIRECRACKER_REPO_API}/commits/${commit_hash}/status" 2>/dev/null || echo '{"state":"unknown","total_count":0}')
6450
status=$(echo "$status_response" | jq -r '.state')
6551
status_count=$(echo "$status_response" | jq -r '.total_count')
6652

67-
# Check check-runs (GitHub Actions)
68-
# Order matters: check pending BEFORE success (null conclusion means in-progress)
6953
check_response=$(gh api "/repos/${FIRECRACKER_REPO_API}/commits/${commit_hash}/check-runs" 2>/dev/null || echo '{"total_count":0}')
7054
check_count=$(echo "$check_response" | jq -r '.total_count')
7155
check_conclusion=$(echo "$check_response" | jq -r '
@@ -77,20 +61,11 @@ while IFS= read -r version || [[ -n "$version" ]]; do
7761
end
7862
')
7963

80-
echo " Status: $status (count: $status_count), Check runs: $check_conclusion (count: $check_count)"
81-
82-
# Handle the different cases
8364
if [[ "$status" == "failure" ]] || [[ "$check_conclusion" == "failure" ]]; then
8465
echo " ❌ CI failed for $version_name"
8566
all_passed=false
8667
failed_versions="${failed_versions}${version_name} "
87-
elif [[ "$check_conclusion" == "pending" ]]; then
88-
# Only pending if there are actual check-runs in progress
89-
echo " ⏳ CI still running for $version_name"
90-
all_passed=false
91-
failed_versions="${failed_versions}${version_name}(pending) "
92-
elif [[ "$status" == "pending" ]] && [[ "$status_count" -gt 0 ]]; then
93-
# Only pending if there are actual statuses pending
68+
elif [[ "$check_conclusion" == "pending" ]] || ([[ "$status" == "pending" ]] && [[ "$status_count" -gt 0 ]]); then
9469
echo " ⏳ CI still running for $version_name"
9570
all_passed=false
9671
failed_versions="${failed_versions}${version_name}(pending) "
@@ -101,24 +76,15 @@ while IFS= read -r version || [[ -n "$version" ]]; do
10176
elif [[ "$status" == "success" ]] || [[ "$check_conclusion" == "success" ]]; then
10277
echo " ✅ CI passed for $version_name"
10378
elif [[ "$status_count" -eq 0 ]] && [[ "$check_count" -eq 0 ]]; then
104-
# No CI configured for this commit - treat as acceptable
10579
echo " ℹ️ No CI checks found for $version_name (assuming OK)"
10680
elif [[ "$status" == "pending" ]] && [[ "$status_count" -eq 0 ]] && [[ "$check_conclusion" == "no_checks" ]]; then
107-
# GitHub returns "pending" when there are no statuses - this is OK
10881
echo " ℹ️ No CI checks found for $version_name (assuming OK)"
10982
else
110-
# Catch-all for unexpected states
11183
echo " ⚠️ Unexpected CI state for $version_name: status=$status, check_conclusion=$check_conclusion"
11284
all_passed=false
11385
failed_versions="${failed_versions}${version_name}(unexpected) "
11486
fi
11587
done < "$OLDPWD/$VERSIONS_FILE"
11688

11789
echo ""
118-
if [[ "$all_passed" == "true" ]]; then
119-
echo "All CI checks passed!"
120-
echo "ci_passed=true"
121-
else
122-
echo "CI checks failed or pending for: $failed_versions"
123-
echo "ci_passed=false"
124-
fi
90+
[[ "$all_passed" == "true" ]] && echo "ci_passed=true" || echo "ci_passed=false"

0 commit comments

Comments
 (0)