Repository navigation
115 lines (96 loc) · 4.01 KB
/
Copy pathupdate-samples.yml
File metadata and controls
115 lines (96 loc) · 4.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
name: Update Sample Repos
on:
release:
types: [published]
workflow_dispatch:
permissions:
contents: read
jobs:
update-samples:
runs-on: ubuntu-latest
outputs:
repos: ${{ steps.get-repos.outputs.repos }}
steps:
- name: Get all public repos with v3-sample topic in @zenstackhq org
id: get-repos
env:
GH_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
# Get all public repos from the zenstackhq org with v3-sample topic
REPOS=$(gh repo list zenstackhq --json name,isPrivate,nameWithOwner,repositoryTopics --limit 100 | \
jq -r '.[] | select(.isPrivate == false) | select((.repositoryTopics // []) | map(.name) | contains(["v3-sample"])) | .nameWithOwner')
echo "Found repos with v3-sample topic:"
echo "$REPOS"
# Convert to JSON array for matrix
REPOS_JSON=$(echo "$REPOS" | jq -R -s -c 'split("\n") | map(select(length > 0))')
echo "repos=$REPOS_JSON" >> $GITHUB_OUTPUT
- name: Display repos to update
run: |
echo "Will update the following repos:"
echo '${{ steps.get-repos.outputs.repos }}' | jq -r '.[]'
update-repo:
needs: update-samples
runs-on: ubuntu-latest
if: ${{ needs.update-samples.outputs.repos != '[]' }}
strategy:
matrix:
repo: ${{ fromJson(needs.update-samples.outputs.repos) }}
fail-fast: false
steps:
- name: Checkout target repo
uses: actions/checkout@v4
with:
repository: ${{ matrix.repo }}
token: ${{ secrets.PAT_TOKEN }}
- name: Check if package.json exists
id: check-package
run: |
if [ -f "package.json" ]; then
echo "exists=true" >> $GITHUB_OUTPUT
else
echo "exists=false" >> $GITHUB_OUTPUT
fi
- name: Use Node.js
if: steps.check-package.outputs.exists == 'true'
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'
- name: Update @zenstackhq packages to latest
if: steps.check-package.outputs.exists == 'true'
run: |
# Get all @zenstackhq packages in the repo
PACKAGES=$(cat package.json | jq -r '
[.dependencies, .devDependencies] |
add |
to_entries |
map(select(.key | startswith("@zenstackhq/"))) |
map(.key) |
.[]
')
if [ -z "$PACKAGES" ]; then
echo "No @zenstackhq packages found in ${{ matrix.repo }}"
exit 0
fi
echo "Updating packages in ${{ matrix.repo }}:"
echo "$PACKAGES"
# Update each package to latest tag
for pkg in $PACKAGES; do
echo "Updating $pkg to latest"
npm install "$pkg@latest"
done
# Finally run generate
npm run generate
- name: Commit and push changes
if: steps.check-package.outputs.exists == 'true'
run: |
git config --global user.name "GitHub Actions Bot"
git config --global user.email "actions@github.com"
# Check if there are changes to commit
if git diff --quiet && git diff --staged --quiet; then
echo "No changes to commit"
exit 0
fi
git add .
git commit -m "chore: update @zenstackhq packages to latest release"
git push