Skip to content

Commit b3a0c0e

Browse files
fixed some bugs
1 parent a679e81 commit b3a0c0e

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

.github/workflows/regenerate-openapi-pr.yml

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,80 +15,84 @@ permissions:
1515
jobs:
1616
regenerate-and-pr:
1717
runs-on: ubuntu-latest
18+
1819
steps:
19-
- name: Exit if triggered by GitHub Actions bot (avoid loops)
20+
# Avoid infinite loop triggered by GitHub Actions
21+
- name: Exit if triggered by GitHub Actions bot
2022
if: github.actor == 'github-actions[bot]'
2123
run: |
2224
echo "Triggered by GitHub Actions bot; exiting to avoid loop."
2325
exit 0
2426
27+
# Checkout repo
2528
- name: Checkout repository
2629
uses: actions/checkout@v3
2730
with:
2831
fetch-depth: 0
2932
persist-credentials: true
3033

34+
# Setup JDK
3135
- name: Set up JDK 21
3236
uses: actions/setup-java@v3
3337
with:
3438
distribution: temurin
3539
java-version: 21
3640

41+
# Grant execute permission for Gradle
3742
- name: Grant execute permission for gradlew
3843
run: chmod +x ./gradlew
3944

45+
# Run Generator (regenerates client + models)
4046
- name: Run Generator
4147
run: ./gradlew :generator:run --args="--openapi-url https://raw.githubusercontent.com/near/nearcore/master/chain/jsonrpc/openapi/openapi.json" --no-daemon
4248

49+
# Build and run tests
4350
- name: Build project (and run tests)
4451
run: ./gradlew build --stacktrace --no-daemon
4552

46-
- name: Prepare branch, commit regenerated sources (if any) and push
53+
# Prepare branch, commit changes, push
54+
- name: Prepare branch, commit regenerated sources
4755
id: commit
4856
env:
49-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
57+
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
5058
run: |
5159
set -euo pipefail
5260
53-
# configure git author (actions token is present via checkout persist-credentials)
54-
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
55-
git config --local user.name "github-actions[bot]"
61+
git config --local user.email "automation@github.com"
62+
git config --local user.name "GitHub Actions Bot"
5663
57-
# create a unique branch name
64+
# create unique branch
5865
SHORT_SHA=${GITHUB_SHA:0:8}
5966
BRANCH="regenerate-openapi-${GITHUB_RUN_NUMBER}-${SHORT_SHA}"
6067
6168
git checkout -b "$BRANCH"
6269
63-
# stage all changes produced by generator
6470
git add .
6571
66-
# if there are no staged changes, set output and exit gracefully
72+
# check if any changes
6773
if git diff --staged --quiet; then
6874
echo "No changes to commit"
6975
echo "pr_required=false" >> "$GITHUB_OUTPUT"
7076
exit 0
7177
fi
7278
73-
# commit and push branch
7479
git commit -m "chore: regenerate client from OpenAPI"
75-
git push --set-upstream origin "$BRANCH"
80+
git push https://x-access-token:${PAT_TOKEN}@github.com/${GITHUB_REPOSITORY}.git "$BRANCH"
7681
77-
# export outputs for next steps
7882
echo "pr_required=true" >> "$GITHUB_OUTPUT"
7983
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
8084
85+
# Create Pull Request if changes exist
8186
- name: Create Pull Request for regenerated sources
8287
if: steps.commit.outputs.pr_required == 'true'
8388
uses: actions/github-script@v6
8489
with:
85-
github-token: ${{ secrets.GITHUB_TOKEN }}
90+
github-token: ${{ secrets.PAT_TOKEN }}
8691
script: |
87-
const branch = context.payload.inputs?.branch || '${{ steps.commit.outputs.branch }}';
92+
const branch = '${{ steps.commit.outputs.branch }}';
8893
const title = `chore: regenerate client from OpenAPI (${branch})`;
8994
const body = `This PR regenerates the NEAR RPC client and models from the latest OpenAPI spec.\n\nPlease review the generated code and run CI checks.`;
9095
91-
// create PR targeting main
9296
const pr = await github.rest.pulls.create({
9397
owner: context.repo.owner,
9498
repo: context.repo.repo,
@@ -98,11 +102,9 @@ jobs:
98102
body
99103
});
100104
101-
// optionally add a label to PR (uncomment if you have label created)
102-
// await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.data.number, labels: ["autogen"] });
103-
104105
return { pr_number: pr.data.number, pr_url: pr.data.html_url };
105106
107+
# Output when no changes
106108
- name: Output when no changes
107109
if: steps.commit.outputs.pr_required != 'true'
108110
run: echo "No regenerated changes — nothing to create a PR for."

0 commit comments

Comments
 (0)