Skip to content

Commit b950036

Browse files
committed
Add workflow template to collect PURLs for an ecosystem
Signed-off-by: Keshav Priyadarshi <[email protected]>
1 parent 5062d9f commit b950036

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Collect base PURLs for an ecosystem from AboutCode federated package metadata
2+
on:
3+
workflow_call:
4+
inputs:
5+
ecosystem:
6+
description: "Ecosystem for which to collect base PackageURLs (eg. npm)"
7+
required: true
8+
type: string
9+
path:
10+
description: "Path to store collected PURLs (eg. 'data/npm.txt')"
11+
required: true
12+
type: string
13+
14+
permissions:
15+
contents: write
16+
17+
jobs:
18+
clone-repos:
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Install GitHub CLI
23+
run: |
24+
sudo apt update && sudo apt install -y gh
25+
26+
- name: Fetch repo list
27+
env:
28+
GH_TOKEN: ${{ github.token }}
29+
run: |
30+
mkdir ../repos && cd ../repos
31+
gh repo list aboutcode-data --limit 20000 --json name \
32+
--jq '.[] | select(.name | startswith("purls-${{ inputs.ecosystem }}")) | .name' \
33+
> repos.txt
34+
35+
- name: Shallow clone repos
36+
run: |
37+
cd ../repos
38+
cat repos.txt | xargs -n 1 -P 8 -I {} bash -c '
39+
echo "Cloning {}"
40+
git clone --depth 1 "https://github.com/aboutcode-data/{}.git"
41+
'
42+
- name: Extract base purl from purls.yml
43+
run: |
44+
cd ../repos
45+
find . -type f -name "purls.yml" -exec sed -n '1{ s/^- *//; s/@.*//; p }' {} \; \
46+
> "${{ inputs.ecosystem }}.txt"
47+
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
- name: Commit and push if it changed
52+
run: |-
53+
dest="${{ inputs.path }}"
54+
git config user.name "AboutCode Automation"
55+
git config user.email "[email protected]"
56+
mkdir -p "$(dirname "$dest")" && mv ../repos/${{ inputs.ecosystem }}.txt "$dest"
57+
git add -A
58+
git commit -m "$(echo -e "Sync latest ${{ inputs.ecosystem }} PURLs from FederatedCode\n\nSigned-off-by: AboutCode Automation <[email protected]>")" || exit 0
59+
git push

0 commit comments

Comments
 (0)