From dc82525624db612a24998f53a3737275c109e680 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Sun, 2 Nov 2025 09:51:13 -0800 Subject: [PATCH] chore: add sample update workflow --- .github/workflows/update-samples.yml | 115 +++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 .github/workflows/update-samples.yml diff --git a/.github/workflows/update-samples.yml b/.github/workflows/update-samples.yml new file mode 100644 index 00000000..97b216ab --- /dev/null +++ b/.github/workflows/update-samples.yml @@ -0,0 +1,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: 20.x + cache: 'npm' + + - name: Update @zenstackhq packages to next + 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 next tag + for pkg in $PACKAGES; do + echo "Updating $pkg to next" + npm install "$pkg@next" + done + + # Finally run zenstack generate + npx zen 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 next release" + git push