v2 / .github / workflows / bootstrapping_ci.yml
133 lines · 130 sloc · 5.07 KB · a217565d716afb3d7ca895c7af99a17b0005a1a9
Raw
1name: Bootstrapping CI
2
3on:
4 workflow_dispatch:
5 push:
6 paths-ignore:
7 - '**.yml'
8 - '**.md'
9 - '**.vv'
10 - '**.out'
11 - 'cmd/tools/**'
12 - '!cmd/tools/builders/**.v'
13 - '!cmd/tools/vup.v'
14 - '!**/bootstrapping_ci.yml'
15 pull_request:
16 paths-ignore:
17 - '**.yml'
18 - '**.md'
19 - '**.vv'
20 - '**.out'
21 - 'cmd/tools/**'
22 - '!cmd/tools/builders/**.v'
23 - '!cmd/tools/vup.v'
24 - '!**/bootstrapping_ci.yml'
25
26concurrency:
27 group: bootstrapping-${{ github.workflow }}-${{ github.ref == 'refs/heads/master' && github.sha || github.ref }}
28 cancel-in-progress: true
29
30jobs:
31 bootstrap-v:
32 strategy:
33 matrix:
34 os: [ubuntu-latest, macos-14]
35 fail-fast: false
36 runs-on: ${{ matrix.os }}
37 timeout-minutes: 20
38 env:
39 VFLAGS: -no-parallel
40 B_LFLAGS: -lm -lpthread
41 steps:
42 - uses: actions/checkout@v6
43 with:
44 fetch-depth: 0
45 - name: Build V
46 run: make -j4
47 - name: Test bootstrapping (v.c can be compiled and run with -os cross)
48 run: |
49 ls -la v vc/v.c
50 ./v -os cross -o vc/v.c cmd/v
51 # shellcheck disable=SC2086
52 cc -o v_from_vc vc/v.c $B_LFLAGS
53 ls -lart v_from_vc
54 ./v_from_vc version
55 ./v_from_vc run examples/hello_world.v
56 ./v_from_vc -o v_from_vc_produced_native_v cmd/v
57 ./v_from_vc_produced_native_v run examples/hello_world.v
58 ### the next make invocation will simulate building V from scratch
59 make local=1
60 ls -la v vc/v.c v_from_vc v_from_vc_produced_native_v
61 ./v_from_vc_produced_native_v -os cross -o vc/v.c cmd/v
62 ### do it a second time, just in case:
63 # shellcheck disable=SC2086
64 clang -o v_from_vc2 vc/v.c $B_LFLAGS
65 ls -lart v_from_vc2
66 ./v_from_vc2 version
67 ./v_from_vc2 run examples/hello_world.v
68 ./v_from_vc2 -o v_from_vc_produced_native_v2 cmd/v
69 ./v_from_vc_produced_native_v2 run examples/hello_world.v
70 make local=1
71 ls -la v vc/v.c
72 ls -la v_from_vc v_from_vc_produced_native_v
73 ls -la v_from_vc2 v_from_vc_produced_native_v2
74 - name: Ensure V master is available
75 if: github.ref_name != 'master'
76 run: git branch master remotes/origin/master
77 - name: Test `v up`
78 run: |
79 # Derive a commit sha from an older successful fast workflow on master that was able to build V.
80 # The workflow used below is `Path Testing CI` (18477644).
81 # Fetch several successful runs and pick the first commit that is actually reachable on master.
82 # Some runs may reference commits from force-pushed branches that are no longer on master.
83 fetch_page() {
84 local page="$1"
85 local body=""
86 for attempt in 1 2 3; do
87 body=$(curl -sL --max-time 30 \
88 -H "Accept: application/vnd.github+json" \
89 -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
90 -H "X-GitHub-Api-Version: 2022-11-28" \
91 "https://api.github.com/repos/vlang/v/actions/workflows/18477644/runs?branch=master&status=success&event=push&per_page=10&page=$page")
92 if [ -n "$body" ] && echo "$body" | jq -e '.workflow_runs' >/dev/null 2>&1; then
93 echo "$body" | jq -r '.workflow_runs[].head_sha'
94 return 0
95 fi
96 echo "::warning::page $page attempt $attempt failed, retrying..." >&2
97 sleep 5
98 done
99 return 1
100 }
101 recent_good_commit=""
102 valid_count=0
103 for page in 1 2 3; do
104 commits=$(fetch_page "$page" || true)
105 commit_count=$(printf '%s\n' "$commits" | grep -c . || true)
106 echo "page $page: fetched $commit_count commits"
107 for sha in $commits; do
108 if git merge-base --is-ancestor "$sha" master 2>/dev/null; then
109 valid_count=$((valid_count + 1))
110 echo " valid #$valid_count: $sha"
111 # Skip the first few valid commits to get an older one for testing upgrades.
112 if [ "$valid_count" -ge 5 ]; then
113 recent_good_commit="$sha"
114 break 2
115 fi
116 fi
117 done
118 done
119 if [ -z "$recent_good_commit" ]; then
120 echo "Path Testing CI lookup yielded only $valid_count valid commits; falling back to git log."
121 recent_good_commit=$(git log master --first-parent --format=%H --before='14 days ago' -n 1)
122 fi
123 if [ -z "$recent_good_commit" ]; then
124 echo "Could not find a valid recent good commit on master"
125 exit 1
126 fi
127 echo "recent_good_commit=$recent_good_commit"
128 # Build oldv at recent_good_commit.
129 ./v run cmd/tools/oldv.v -v "$recent_good_commit"
130 cd "$HOME/.cache/oldv/v_at_$recent_good_commit"
131 # Test updating
132 ./v version && ./v -v up && ./v version
133 ./v -o v2 cmd/v && ./v2 -o v3 cmd/v
134