Skip to content

Commit 80a74ef

Browse files
committed
ci: resolve the capy checkout across forks
The capy branch resolution only consulted cppalliance/capy, so a branch pushed to a fork of corosio could never find its matching capy branch on the same owner's capy fork and silently fell back to capy's default branch, building against the wrong API. Try the repository owner's capy fork first for each branch candidate, then cppalliance/capy, and carry the resolved repository into the checkout step. Runs in cppalliance/corosio behave exactly as before.
1 parent afd7b2d commit 80a74ef

4 files changed

Lines changed: 73 additions & 90 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#
2+
# Copyright (c) 2026 Steve Gerbino
3+
#
4+
# Distributed under the Boost Software License, Version 1.0. (See accompanying
5+
# file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
#
7+
# Official repository: https://github.com/cppalliance/corosio/
8+
#
9+
10+
name: Resolve Capy branch
11+
description: >-
12+
Resolve the capy repository and branch matching this build. Use the
13+
capy branch with the same name as this build's branch (for pull
14+
requests: the source branch, then the target branch). Inside a fork
15+
the owner's capy fork is preferred, so fork branches build against
16+
their matching capy fork branch. Cross-repo PRs into cppalliance
17+
resolve against cppalliance/capy as before. Fall back to capy's
18+
default branch.
19+
20+
outputs:
21+
repo:
22+
description: The resolved capy repository (owner/capy).
23+
value: ${{ steps.resolve.outputs.repo }}
24+
ref:
25+
description: The resolved capy branch.
26+
value: ${{ steps.resolve.outputs.ref }}
27+
28+
runs:
29+
using: composite
30+
steps:
31+
- id: resolve
32+
shell: bash
33+
# Bind untrusted context values into env: head_ref is
34+
# attacker-controlled on fork PRs, so never interpolate it into
35+
# the script body.
36+
env:
37+
HEAD_REF: ${{ github.head_ref }}
38+
BASE_REF: ${{ github.base_ref }}
39+
REF_NAME: ${{ github.ref_name }}
40+
OWNER: ${{ github.repository_owner }}
41+
run: |
42+
repo=cppalliance/capy
43+
ref=
44+
for candidate in "$HEAD_REF" "$BASE_REF" "$REF_NAME"; do
45+
[ -n "$candidate" ] || continue
46+
probed=
47+
for fork in "$OWNER/capy" cppalliance/capy; do
48+
# Skip a fork already probed for this candidate (the owner
49+
# fork equals cppalliance/capy when running in cppalliance).
50+
[ "$fork" = "$probed" ] && continue
51+
probed="$fork"
52+
if GIT_TERMINAL_PROMPT=0 git ls-remote --exit-code --heads "https://github.com/$fork.git" "$candidate" > /dev/null; then
53+
repo="$fork"
54+
ref="$candidate"
55+
break 2
56+
fi
57+
done
58+
done
59+
if [ -z "$ref" ]; then
60+
ref=$(GIT_TERMINAL_PROMPT=0 git ls-remote --symref "https://github.com/$repo.git" HEAD | awk '/^ref:/ { sub("refs/heads/", "", $2); print $2 }')
61+
fi
62+
echo "repo=$repo" >> "$GITHUB_OUTPUT"
63+
echo "ref=$ref" >> "$GITHUB_OUTPUT"

‎.github/workflows/ci.yml‎

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,14 @@ jobs:
9595
liburing-dev
9696
curl zip unzip tar pkg-config
9797
98-
# Use the capy branch with the same name as this build's branch
99-
# (for pull requests: the source branch, then the target branch);
100-
# fall back to capy's default branch.
10198
- name: Resolve Capy branch
10299
id: capy-ref
103-
shell: bash
104-
run: |
105-
url=https://github.com/cppalliance/capy.git
106-
ref=
107-
for candidate in "${{ github.head_ref }}" "${{ github.base_ref }}" "${{ github.ref_name }}"; do
108-
if [ -n "$candidate" ] && git ls-remote --exit-code --heads "$url" "$candidate" > /dev/null; then
109-
ref="$candidate"
110-
break
111-
fi
112-
done
113-
if [ -z "$ref" ]; then
114-
ref=$(git ls-remote --symref "$url" HEAD | awk '/^ref:/ { sub("refs/heads/", "", $2); print $2 }')
115-
fi
116-
echo "ref=$ref" >> "$GITHUB_OUTPUT"
100+
uses: ./corosio-root/.github/actions/resolve-capy
117101

118102
- name: Clone Capy
119103
uses: actions/checkout@v4
120104
with:
121-
repository: cppalliance/capy
105+
repository: ${{ steps.capy-ref.outputs.repo }}
122106
ref: ${{ steps.capy-ref.outputs.ref }}
123107
path: capy-root
124108

@@ -799,30 +783,14 @@ jobs:
799783
with:
800784
path: corosio-root
801785

802-
# Use the capy branch with the same name as this build's branch
803-
# (for pull requests: the source branch, then the target branch);
804-
# fall back to capy's default branch.
805786
- name: Resolve Capy branch
806787
id: capy-ref
807-
shell: bash
808-
run: |
809-
url=https://github.com/cppalliance/capy.git
810-
ref=
811-
for candidate in "${{ github.head_ref }}" "${{ github.base_ref }}" "${{ github.ref_name }}"; do
812-
if [ -n "$candidate" ] && git ls-remote --exit-code --heads "$url" "$candidate" > /dev/null; then
813-
ref="$candidate"
814-
break
815-
fi
816-
done
817-
if [ -z "$ref" ]; then
818-
ref=$(git ls-remote --symref "$url" HEAD | awk '/^ref:/ { sub("refs/heads/", "", $2); print $2 }')
819-
fi
820-
echo "ref=$ref" >> "$GITHUB_OUTPUT"
788+
uses: ./corosio-root/.github/actions/resolve-capy
821789

822790
- name: Clone Capy
823791
uses: actions/checkout@v4
824792
with:
825-
repository: cppalliance/capy
793+
repository: ${{ steps.capy-ref.outputs.repo }}
826794
ref: ${{ steps.capy-ref.outputs.ref }}
827795
path: capy-root
828796

‎.github/workflows/code-coverage.yml‎

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -150,30 +150,14 @@ jobs:
150150
echo "CMAKE_WOLFSSL_INCLUDE=${vcpkg_installed}/include" >> $GITHUB_ENV
151151
echo "CMAKE_WOLFSSL_LIBRARY=${vcpkg_installed}/lib/libwolfssl.a" >> $GITHUB_ENV
152152
153-
# Use the capy branch with the same name as this build's branch
154-
# (for pull requests: the source branch, then the target branch);
155-
# fall back to capy's default branch.
156153
- name: Resolve Capy branch
157154
id: capy-ref
158-
shell: bash
159-
run: |
160-
url=https://github.com/cppalliance/capy.git
161-
ref=
162-
for candidate in "${{ github.head_ref }}" "${{ github.base_ref }}" "${{ github.ref_name }}"; do
163-
if [ -n "$candidate" ] && git ls-remote --exit-code --heads "$url" "$candidate" > /dev/null; then
164-
ref="$candidate"
165-
break
166-
fi
167-
done
168-
if [ -z "$ref" ]; then
169-
ref=$(git ls-remote --symref "$url" HEAD | awk '/^ref:/ { sub("refs/heads/", "", $2); print $2 }')
170-
fi
171-
echo "ref=$ref" >> "$GITHUB_OUTPUT"
155+
uses: ./corosio-root/.github/actions/resolve-capy
172156

173157
- name: Clone Capy
174158
uses: actions/checkout@v6
175159
with:
176-
repository: cppalliance/capy
160+
repository: ${{ steps.capy-ref.outputs.repo }}
177161
ref: ${{ steps.capy-ref.outputs.ref }}
178162
path: capy-root
179163

@@ -391,30 +375,14 @@ jobs:
391375
echo "CMAKE_WOLFSSL_LIBRARY=${vcpkg_installed}/lib/libwolfssl.a" >> $GITHUB_ENV
392376
echo "CMAKE_OPENSSL_ROOT=C:/msys64/mingw64" >> $GITHUB_ENV
393377
394-
# Use the capy branch with the same name as this build's branch
395-
# (for pull requests: the source branch, then the target branch);
396-
# fall back to capy's default branch.
397378
- name: Resolve Capy branch
398379
id: capy-ref
399-
shell: bash
400-
run: |
401-
url=https://github.com/cppalliance/capy.git
402-
ref=
403-
for candidate in "${{ github.head_ref }}" "${{ github.base_ref }}" "${{ github.ref_name }}"; do
404-
if [ -n "$candidate" ] && git ls-remote --exit-code --heads "$url" "$candidate" > /dev/null; then
405-
ref="$candidate"
406-
break
407-
fi
408-
done
409-
if [ -z "$ref" ]; then
410-
ref=$(git ls-remote --symref "$url" HEAD | awk '/^ref:/ { sub("refs/heads/", "", $2); print $2 }')
411-
fi
412-
echo "ref=$ref" >> "$GITHUB_OUTPUT"
380+
uses: ./corosio-root/.github/actions/resolve-capy
413381

414382
- name: Clone Capy
415383
uses: actions/checkout@v6
416384
with:
417-
repository: cppalliance/capy
385+
repository: ${{ steps.capy-ref.outputs.repo }}
418386
ref: ${{ steps.capy-ref.outputs.ref }}
419387
path: capy-root
420388

‎.github/workflows/docs.yml‎

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,14 @@ jobs:
4242
with:
4343
path: corosio-root
4444

45-
# Use the capy branch with the same name as this build's branch
46-
# (for pull requests: the source branch, then the target branch);
47-
# fall back to capy's default branch.
4845
- name: Resolve Capy branch
4946
id: capy-ref
50-
shell: bash
51-
run: |
52-
url=https://github.com/cppalliance/capy.git
53-
ref=
54-
for candidate in "${{ github.head_ref }}" "${{ github.base_ref }}" "${{ github.ref_name }}"; do
55-
if [ -n "$candidate" ] && git ls-remote --exit-code --heads "$url" "$candidate" > /dev/null; then
56-
ref="$candidate"
57-
break
58-
fi
59-
done
60-
if [ -z "$ref" ]; then
61-
ref=$(git ls-remote --symref "$url" HEAD | awk '/^ref:/ { sub("refs/heads/", "", $2); print $2 }')
62-
fi
63-
echo "ref=$ref" >> "$GITHUB_OUTPUT"
47+
uses: ./corosio-root/.github/actions/resolve-capy
6448

6549
- name: Clone Capy
6650
uses: actions/checkout@v4
6751
with:
68-
repository: cppalliance/capy
52+
repository: ${{ steps.capy-ref.outputs.repo }}
6953
ref: ${{ steps.capy-ref.outputs.ref }}
7054
path: capy-root
7155

0 commit comments

Comments
 (0)