Skip to content

Commit adad736

Browse files
authored
Merge pull request #401 from Permify/fix/protos-workflow-actions
fix: replace blocked actions in proto update
2 parents 9358b8a + f2d129d commit adad736

File tree

2 files changed

+54
-31
lines changed

2 files changed

+54
-31
lines changed

.github/workflows/protos.yml

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
steps:
1919
# Security hardening for GitHub Actions runner
2020
- name: Harden Runner
21-
uses: step-security/harden-runner@95d9a5deda9de15063e7595e9719c11c38c90ae2 # v2.13.2
21+
uses: step-security/harden-runner@df199fb7be9f65074067a9eb93f12bb4c5547cf2 # v2.13.3
2222
with:
2323
egress-policy: audit
2424

@@ -36,44 +36,45 @@ jobs:
3636

3737
# Install dependencies (needed for ts-proto plugin)
3838
- name: Install Dependencies
39-
uses: bahmutov/npm-install@3e063b974f0d209807684aa23e534b3dde517fd9 # v1.11.2
40-
with:
41-
useLockFile: false
39+
run: yarn install --frozen-lockfile --non-interactive
4240

4341
# Setup Buf CLI - will pull proto from buf.build/permifyco/permify
4442
- name: Setup Buf
45-
uses: bufbuild/buf-action@8f4a1456a0ab6a1eb80ba68e53832e6fcfacc16c # v1.3.0
46-
with:
47-
setup_only: true
48-
github_token: ${{ secrets.GITHUB_TOKEN }}
43+
run: |
44+
BUF_VERSION="1.57.0"
45+
curl -sSL "https://github.com/bufbuild/buf/releases/download/v${BUF_VERSION}/buf-Linux-x86_64" -o "${RUNNER_TEMP}/buf"
46+
chmod +x "${RUNNER_TEMP}/buf"
47+
echo "${RUNNER_TEMP}" >> "${GITHUB_PATH}"
4948
5049
# Generate TypeScript code from Buf Schema Registry
5150
- name: Generate Code with Buf
5251
run: yarn buf:generate
5352

54-
# Check if there are any changes
55-
- name: Check for changes
56-
id: verify-changes
53+
- name: Commit changes
54+
id: commitchanges
55+
run: |
56+
echo "commit changes"
57+
scripts/commit-changes.sh "proto-update/permify-latest"
58+
shell: bash
59+
60+
# Push branch and open or update the PR only if there are changes
61+
- name: Push changes and open PR
62+
if: steps.commitchanges.outputs.changes_made == '1'
63+
env:
64+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
5765
run: |
58-
if git diff --quiet; then
59-
echo "has_changes=false" >> $GITHUB_OUTPUT
60-
echo "No changes detected"
66+
BRANCH_NAME="${{ steps.commitchanges.outputs.branch_name }}"
67+
PR_TITLE="chore(proto): update generated SDK with latest Permify definitions"
68+
PR_BODY="Automatically created PR with the latest generated SDK from Permify proto definitions."
69+
70+
echo "${BRANCH_NAME}"
71+
git push "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}" "${BRANCH_NAME}"
72+
73+
PR_NUMBER="$(gh pr list --head "${BRANCH_NAME}" --base main --state open --json number --jq '.[0].number')"
74+
75+
if [ -n "${PR_NUMBER}" ]; then
76+
gh pr edit "${PR_NUMBER}" --title "${PR_TITLE}" --body "${PR_BODY}"
6177
else
62-
echo "has_changes=true" >> $GITHUB_OUTPUT
63-
echo "Changes detected, will create PR"
78+
gh pr create --base main --head "${BRANCH_NAME}" --title "${PR_TITLE}" --body "${PR_BODY}" --label dependencies --label automated
6479
fi
65-
66-
# Create Pull Request only if there are changes
67-
- name: Create Pull Request
68-
if: steps.verify-changes.outputs.has_changes == 'true'
69-
uses: peter-evans/create-pull-request@84ae59a2cdc2258d6fa0732dd66352dddae2a412 # v7.0.9
70-
with:
71-
token: ${{ secrets.GITHUB_TOKEN }}
72-
commit-message: "chore(proto): update generated SDK with latest Permify definitions"
73-
title: "chore(proto): update generated SDK with latest Permify definitions"
74-
branch: proto-update/permify-latest
75-
delete-branch: true
76-
base: main
77-
labels: |
78-
dependencies
79-
automated
80+
shell: bash

scripts/commit-changes.sh

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
branch_name="${1:?branch name is required}"
6+
7+
if git diff --quiet; then
8+
echo "changes_made=0" >> "${GITHUB_OUTPUT}"
9+
echo "No changes detected"
10+
exit 0
11+
fi
12+
13+
git config user.email "github-actions[bot]@users.noreply.github.com"
14+
git config user.name "github-actions[bot]"
15+
git checkout -B "${branch_name}"
16+
git add -A
17+
git commit -m "chore(proto): update generated SDK with latest Permify definitions"
18+
19+
{
20+
echo "changes_made=1"
21+
echo "branch_name=${branch_name}"
22+
} >> "${GITHUB_OUTPUT}"

0 commit comments

Comments
 (0)