Skip to content

Commit bfbc024

Browse files
committed
Test bblocks-repository-mappings
1 parent 8f4fc4b commit bfbc024

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/workflows/validate-and-process.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ on:
8585
sparql_password:
8686
description: SPARQL Graph Store Protocol password for push authentication
8787
required: false
88+
gh_pat:
89+
description: GitHub Personal Access Token to use when cloning repositories
90+
required: false
8891

8992

9093
permissions:
@@ -144,6 +147,49 @@ jobs:
144147
core.exportVariable('PAGES_BASE_URL', base_url);
145148
core.exportVariable('PAGES_PATH', parsed.pathname);
146149
return base_url;
150+
- name: Process GitHub repository mappings
151+
run: |
152+
export RANDOM_DIR="_repos_$(openssl rand -hex 8)"
153+
mkdir "$RANDOM_DIR"
154+
echo '*' > "${RANDOM_DIR}/.gitignore"
155+
156+
if [ -f "bblocks-github.yaml" ]; then
157+
INPUT_YML="bblocks-github.yaml"
158+
elif [ -f "bblocks-github.yml" ]; then
159+
INPUT_YML="bblocks-github.yml"
160+
fi
161+
162+
if [ -z "$INPUT_YML" ]; then
163+
echo "No GitHub repository mappings found"
164+
exit 0
165+
fi
166+
167+
MAPPINGS_YML="bblocks-config-local.yml"
168+
echo 'url-mappings:' > $MAPPINGS_YML
169+
170+
if [ -z "${{ secrets.GH_PAT }}" ]; then
171+
GH_AUTH=
172+
echo "*WARNING* Cloning repository without a PAT"
173+
else
174+
GH_AUTH="x-access-token:${{ secrets.GH_PAT }}@"
175+
echo "Using a GitHub PAT"
176+
fi
177+
export GH_AUTH
178+
yq -r '."repository-mappings" | to_entries[] |
179+
"\(strenv(RANDOM_DIR))/\(.value | sub(\"[^A-Za-z0-9]\", \"_\"))" as $SUBDIR |
180+
"
181+
if [ ! -d \"\($SUBDIR)\" ]; then
182+
git clone \"https://\(strenv(GH_AUTH))github.com/\(.value).git\" \"\($SUBDIR)\"
183+
fi
184+
echo \" \\\"\(.key)\\\": \\\"\($SUBDIR)\\\"\" >> bblocks-config-local.yml
185+
"
186+
' < $INPUT_YML > _script.sh
187+
cat _script.sh
188+
bash _script.sh
189+
190+
191+
echo "Repositories cloned and mapped in $RANDOM_DIR — output saved to $MAPPINGS_YML"
192+
147193
- name: Before postprocess
148194
if: ${{inputs.before_postprocess}}
149195
run: ${{inputs.before_postprocess}}

0 commit comments

Comments
 (0)