|
1 | | -name: Overwrite Proto Directory |
| 1 | +name: Update Permify Proto Definitions |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | 5 | branches: [ "main" ] |
6 | | - workflow_dispatch: # Allows manual trigger from GitHub UI |
| 6 | + workflow_dispatch: |
7 | 7 |
|
8 | 8 | permissions: |
9 | | - contents: read |
| 9 | + contents: write |
| 10 | + pull-requests: write |
10 | 11 |
|
11 | 12 | jobs: |
12 | | - copy-proto: |
13 | | - permissions: |
14 | | - contents: write # Required for pushing changes back to the repository |
| 13 | + update-protos: |
| 14 | + name: Update Proto Definitions |
| 15 | + timeout-minutes: 10 |
15 | 16 | runs-on: ubuntu-latest |
16 | 17 |
|
17 | 18 | steps: |
18 | | - # Security hardening for GitHub Actions runner |
19 | | - - name: Harden Runner |
20 | | - uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 |
21 | | - with: |
22 | | - egress-policy: audit |
| 19 | + # Security hardening for GitHub Actions runner |
| 20 | + - name: Harden Runner |
| 21 | + uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2 |
| 22 | + with: |
| 23 | + egress-policy: audit |
23 | 24 |
|
24 | | - # Checkout the current repository |
25 | | - - name: Checkout Repository |
26 | | - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
| 25 | + # Checkout the current repository |
| 26 | + - name: Checkout Repository |
| 27 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0 |
27 | 28 |
|
28 | | - # Clone Permify repo and copy proto files to our repo |
29 | | - - name: Copy Proto Files from Permify |
30 | | - run: | |
31 | | - git clone --depth=1 https://github.com/Permify/permify.git temp_dir |
32 | | - rm -rf proto |
33 | | - mkdir -p proto |
34 | | - cp -r temp_dir/proto/* proto |
35 | | - rm -rf temp_dir |
| 29 | + # Setup Buf CLI - will pull proto from buf.build/permifyco/permify |
| 30 | + - name: Setup Buf |
| 31 | + uses: bufbuild/buf-action@v1 |
| 32 | + with: |
| 33 | + setup_only: true |
| 34 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
36 | 35 |
|
37 | | - # Setup Node.js and install dependencies (including ts-proto) |
38 | | - - name: Setup Node.js |
39 | | - uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0 |
40 | | - with: |
41 | | - node-version: '18' |
42 | | - cache: 'npm' |
| 36 | + # Generate TypeScript code from Buf Schema Registry |
| 37 | + - name: Generate Code with Buf |
| 38 | + run: buf generate |
43 | 39 |
|
44 | | - - name: Install Dependencies |
45 | | - run: npm ci |
| 40 | + # Check if there are any changes |
| 41 | + - name: Check for changes |
| 42 | + id: verify-changes |
| 43 | + run: | |
| 44 | + if git diff --quiet; then |
| 45 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 46 | + echo "No changes detected" |
| 47 | + else |
| 48 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 49 | + echo "Changes detected, will create PR" |
| 50 | + fi |
46 | 51 |
|
47 | | - # Install Buf CLI using official action |
48 | | - - name: Setup Buf |
49 | | - uses: bufbuild/buf-action@v1 |
50 | | - with: |
51 | | - setup_only: true |
52 | | - |
53 | | - # Generate TypeScript code from proto files |
54 | | - - name: Generate Code with Buf |
55 | | - run: buf generate |
56 | | - |
57 | | - # Commit generated files if there are any changes |
58 | | - - name: Add and Commit Changes |
59 | | - run: | |
60 | | - git config --global user.name 'GitHub Actions Bot' |
61 | | - git config --global user.email '<>' |
62 | | - git add src/grpc/generated proto/ package-lock.json |
63 | | - if git diff-index --quiet HEAD; then |
64 | | - echo "No changes to commit" |
65 | | - else |
66 | | - git commit -m "Update generated sdk directory with latest changes" |
67 | | - fi |
68 | | -
|
69 | | - # Push changes back to main branch |
70 | | - - name: Push Changes |
71 | | - env: |
72 | | - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
73 | | - run: | |
74 | | - git push origin main |
| 52 | + # Create Pull Request only if there are changes |
| 53 | + - name: Create Pull Request |
| 54 | + if: steps.verify-changes.outputs.has_changes == 'true' |
| 55 | + uses: peter-evans/create-pull-request@v7.0.8 |
| 56 | + with: |
| 57 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 58 | + commit-message: "chore(proto): update generated SDK with latest Permify definitions" |
| 59 | + title: "chore(proto): update generated SDK with latest Permify definitions" |
| 60 | + branch: proto-update/permify-latest |
| 61 | + delete-branch: true |
| 62 | + base: main |
| 63 | + labels: | |
| 64 | + dependencies |
| 65 | + automated |
0 commit comments