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