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