Skip to content

Commit 94b51ac

Browse files
committed
Fix parsing; parallelize
1 parent 5ab5207 commit 94b51ac

File tree

2 files changed

+85
-6
lines changed

2 files changed

+85
-6
lines changed

.github/workflows/build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Build Firecracker Versions
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
prepare:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
versions: ${{ steps.set-versions.outputs.versions }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Parse versions from file
19+
id: set-versions
20+
run: |
21+
# Read versions, skip comments and empty lines, output as JSON array
22+
versions=$(grep -v '^ *#' firecracker_versions.txt | grep -v '^$' | jq -R -s -c 'split("\n") | map(select(length > 0))')
23+
echo "versions=$versions" >> $GITHUB_OUTPUT
24+
echo "Building versions: $versions"
25+
26+
build:
27+
needs: prepare
28+
runs-on: ubuntu-latest
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
version: ${{ fromJson(needs.prepare.outputs.versions) }}
33+
steps:
34+
- uses: actions/checkout@v4
35+
36+
- name: Build Firecracker ${{ matrix.version }}
37+
run: ./build.sh "${{ matrix.version }}"
38+
39+
- name: Upload build artifact
40+
uses: actions/upload-artifact@v4
41+
with:
42+
name: firecracker-${{ matrix.version }}
43+
path: builds/
44+
retention-days: 30

build.sh

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,40 @@ FIRECRACKER_REPO_URL="https://github.com/e2b-dev/firecracker.git"
66

77
function build_version {
88
local version=$1
9-
echo "Starting build for Firecracker commit: $version"
109

11-
echo "Checking out repo for Firecracker at commit: $version"
12-
git checkout "${version}"
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"
15+
16+
echo "Checking out repo at tag: $tag"
17+
git checkout "$tag"
18+
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
25+
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+
# The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
40+
version_name=$(git describe --tags --abbrev=0 "$(git rev-parse HEAD)")_$(git rev-parse --short HEAD)
41+
fi
1342

14-
# The format will be: latest_tag_latest_commit_hash — v1.7.0-dev_g8bb88311
15-
version_name=$(git describe --tags --abbrev=0 $(git rev-parse HEAD))_$(git rev-parse --short HEAD)
1643
echo "Version name: $version_name"
1744

1845
echo "Building Firecracker version: $version_name"
@@ -23,11 +50,19 @@ function build_version {
2350
cp build/cargo_target/x86_64-unknown-linux-musl/release/firecracker "../builds/${version_name}/firecracker"
2451
}
2552

53+
# If a version is passed as argument, build only that version
54+
# Otherwise, build all versions from firecracker_versions.txt
55+
if [[ $# -ge 1 ]]; then
56+
versions=("$@")
57+
else
58+
mapfile -t versions < <(grep -v '^ *#' firecracker_versions.txt | grep -v '^$')
59+
fi
60+
2661
echo "Cloning the Firecracker repository"
2762
git clone $FIRECRACKER_REPO_URL firecracker
2863
cd firecracker
2964

30-
grep -v '^ *#' <../firecracker_versions.txt | while IFS= read -r version; do
65+
for version in "${versions[@]}"; do
3166
build_version "$version"
3267
done
3368

0 commit comments

Comments
 (0)