Skip to content

Commit 33e4eff

Browse files
fixed some bugs
1 parent e66dafe commit 33e4eff

File tree

3 files changed

+108
-55
lines changed

3 files changed

+108
-55
lines changed

.github/workflows/generate-and-release.yml

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
name: Regenerate NEAR RPC Client (create PR)
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
schedule:
9+
- cron: "0 0 * * *" # daily run (every day at midnight)
10+
11+
permissions:
12+
contents: write
13+
14+
jobs:
15+
regenerate-and-pr:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Exit if triggered by GitHub Actions bot (avoid loops)
19+
if: github.actor == 'github-actions[bot]'
20+
run: |
21+
echo "Triggered by GitHub Actions bot; exiting to avoid loop."
22+
exit 0
23+
24+
- name: Checkout repository
25+
uses: actions/checkout@v3
26+
with:
27+
fetch-depth: 0
28+
persist-credentials: true
29+
30+
- name: Set up JDK 21
31+
uses: actions/setup-java@v3
32+
with:
33+
distribution: temurin
34+
java-version: 21
35+
36+
- name: Grant execute permission for gradlew
37+
run: chmod +x ./gradlew
38+
39+
- name: Run Generator
40+
run: ./gradlew :generator:run --args="--openapi-url https://raw.githubusercontent.com/near/nearcore/master/chain/jsonrpc/openapi/openapi.json" --no-daemon
41+
42+
- name: Build project (and run tests)
43+
run: ./gradlew build --stacktrace --no-daemon
44+
45+
- name: Prepare branch, commit regenerated sources (if any) and push
46+
id: commit
47+
env:
48+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49+
run: |
50+
set -euo pipefail
51+
52+
# configure git author (actions token is present via checkout persist-credentials)
53+
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
54+
git config --local user.name "github-actions[bot]"
55+
56+
# create a unique branch name
57+
SHORT_SHA=${GITHUB_SHA:0:8}
58+
BRANCH="regenerate-openapi-${GITHUB_RUN_NUMBER}-${SHORT_SHA}"
59+
60+
git checkout -b "$BRANCH"
61+
62+
# stage all changes produced by generator
63+
git add .
64+
65+
# if there are no staged changes, set output and exit gracefully
66+
if git diff --staged --quiet; then
67+
echo "No changes to commit"
68+
echo "pr_required=false" >> "$GITHUB_OUTPUT"
69+
exit 0
70+
fi
71+
72+
# commit and push branch
73+
git commit -m "chore: regenerate client from OpenAPI"
74+
git push --set-upstream origin "$BRANCH"
75+
76+
# export outputs for next steps
77+
echo "pr_required=true" >> "$GITHUB_OUTPUT"
78+
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
79+
80+
- name: Create Pull Request for regenerated sources
81+
if: steps.commit.outputs.pr_required == 'true'
82+
uses: actions/github-script@v6
83+
with:
84+
github-token: ${{ secrets.GITHUB_TOKEN }}
85+
script: |
86+
const branch = context.payload.inputs?.branch || '${{ steps.commit.outputs.branch }}';
87+
const title = `chore: regenerate client from OpenAPI (${branch})`;
88+
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.`;
89+
90+
// create PR targeting main
91+
const pr = await github.rest.pulls.create({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
title,
95+
head: branch,
96+
base: "main",
97+
body
98+
});
99+
100+
// optionally add a label to PR (uncomment if you have label created)
101+
// await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.data.number, labels: ["autogen"] });
102+
103+
return { pr_number: pr.data.number, pr_url: pr.data.html_url };
104+
105+
- name: Output when no changes
106+
if: steps.commit.outputs.pr_required != 'true'
107+
run: echo "No regenerated changes — nothing to create a PR for."

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ The `generator` module is a CLI that parses NEAR's OpenAPI spec and writes gener
183183

184184
Run the generator against NEAR's OpenAPI:
185185
```bash
186-
./gradlew :generator:run --args="--openapi-url https://raw.githubusercontent.com/near/nearcore/master/chain/jsonrpc/openapi/openapi.json --models-out build/generated --client-out build/generated
186+
./gradlew :generator:run --args="--openapi-url https://raw.githubusercontent.com/near/nearcore/master/chain/jsonrpc/openapi/openapi.json --models-out build/generated --client-out build/generated"
187187
```
188188

189189
---

0 commit comments

Comments
 (0)