Skip to content

Commit df1b407

Browse files
committed
Build a revision once, not once per repository
A push to master here fires the announcement, and autobuilds describes that revision, builds the lock through this repository's own reusable workflow, and publishes what comes out. Since the hand-written matrix went, the build this workflow runs on such a push is the same lock, the same ten legs and the same code -- done twice, at the same time, in two repositories. It was worth having when the two were different paths, because two paths give two signals. They are one path now, so the second run is only cost: four full builds were in flight at once this afternoon, half of them copies. The build stays on every pull request, which is where it is the signal that decides whether something merges. On master the signal is the autobuilds run, and that one also says whether the revision is releasable, which this one never could.
1 parent 93a4d9a commit df1b407

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ jobs:
7676
# because its macOS leg had never run the code that publishes one.
7777
build:
7878
needs: describe
79+
# Not on a push to master: that push is announced to autobuilds, which
80+
# describes the same revision, builds the same lock through the same
81+
# reusable workflow, and publishes what comes out. Building it here as
82+
# well is the same ten legs twice, and the copy that says whether the
83+
# revision is releasable is the one over there.
84+
if: github.event_name != 'push' || github.ref != 'refs/heads/master'
7985
uses: ./.github/workflows/build-sdk.yml
8086
with:
8187
lock: ${{ needs.describe.outputs.lock }}

tests/ci/test-single-matrix.sh

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,63 @@ for runner in sorted({host["runner"] for host in hosts} - {"ubuntu-24.04"}):
6767
print(f"build.yml names the runner {runner!r}; cmake/hosts.json is where runners are declared")
6868
if "cmake/toolchains/" in text:
6969
print("build.yml names a cross toolchain file; build-host.sh is where a host is built")
70+
71+
# And it must not run that one path twice. A push to master is announced to
72+
# autobuilds, which describes the same revision and builds the same lock, so
73+
# building it here too is the same legs over again.
74+
def evaluate(expression, context):
75+
tokens = re.findall(r"'[^']*'|\|\||&&|==|!=|[A-Za-z0-9_.-]+", expression)
76+
position = 0
77+
78+
def take():
79+
nonlocal position
80+
position += 1
81+
return tokens[position - 1]
82+
83+
def primary():
84+
token = take()
85+
if token.startswith("'"):
86+
return token[1:-1]
87+
value = context
88+
for part in token.split("."):
89+
value = value.get(part, "") if isinstance(value, dict) else ""
90+
return value
91+
92+
def comparison():
93+
left = primary()
94+
if position < len(tokens) and tokens[position] in ("==", "!="):
95+
operator = take()
96+
right = primary()
97+
return left == right if operator == "==" else left != right
98+
return left
99+
100+
def conjunction():
101+
value = comparison()
102+
while position < len(tokens) and tokens[position] == "&&":
103+
take()
104+
right = comparison()
105+
value = right if value else value
106+
return value
107+
108+
value = conjunction()
109+
while position < len(tokens) and tokens[position] == "||":
110+
take()
111+
right = conjunction()
112+
value = value if value else right
113+
return value
114+
115+
116+
def runs_on(event_name, ref):
117+
condition = str(jobs[caller].get("if", "")).strip()
118+
if not condition:
119+
return True
120+
return bool(evaluate(condition, {"github": {"event_name": event_name, "ref": ref}}))
121+
122+
123+
if runs_on("push", "refs/heads/master"):
124+
print("a push to master builds here as well as in autobuilds; that is the same lock twice")
125+
if not runs_on("pull_request", "refs/pull/1/merge"):
126+
print("a pull request no longer builds, which is the only place this build is the signal")
70127
PYEOF
71128
)
72129

0 commit comments

Comments
 (0)