Skip to content

Commit f2c18ad

Browse files
authored
Merge pull request #324 from Permify/update-permify-proto-definitions
ci(workflows): update GitHub Actions for proto definitions management
2 parents 2417d5a + fcd5da0 commit f2c18ad

3 files changed

Lines changed: 62 additions & 64 deletions

File tree

.github/workflows/protos.yml

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,65 @@
1-
name: Overwrite Proto Directory
1+
name: Update Permify Proto Definitions
22

33
on:
44
push:
55
branches: [ "main" ]
6-
workflow_dispatch: # Allows manual trigger from GitHub UI
6+
workflow_dispatch:
77

88
permissions:
9-
contents: read
9+
contents: write
10+
pull-requests: write
1011

1112
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
1516
runs-on: ubuntu-latest
1617

1718
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
2324

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
2728

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 }}
3635

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
4339

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
4651
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

buf.gen.yaml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1-
version: "v1"
1+
version: v2
2+
managed:
3+
enabled: true
4+
inputs:
5+
- module: buf.build/permifyco/permify
26
plugins:
3-
- name: ts-proto
4-
out: "src/grpc/generated"
5-
opt: oneof=unions,forceLong=long,esModuleInterop=true,env=node,outputServices=nice-grpc,outputServices=generic-definitions,useExactTypes=false
6-
path: node_modules/.bin/protoc-gen-ts_proto
7+
- remote: buf.build/community/timostamm-protobuf-ts:v2.9.1
8+
out: src/grpc/generated
9+
opt:
10+
- long_type_string
11+
- client_grpc1
12+
- generate_dependencies

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"run-instance": "scripts/run-instance.sh",
1111
"run-test": "ts-node node_modules/jasmine/bin/jasmine --config=jasmine.json",
1212
"lint": "eslint \"src/**/*.ts\"",
13-
"build": "rm -rf ./dist && npx tsc"
13+
"build": "rm -rf ./dist && npx tsc",
14+
"buf:generate": "buf generate"
1415
},
1516
"keywords": [
1617
"permissions",

0 commit comments

Comments
 (0)