fixed some bugs #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Regenerate NEAR RPC Client (create PR) | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| - cron: "0 0 * * *" # daily run (every day at midnight) | |
| permissions: | |
| contents: write | |
| jobs: | |
| regenerate-and-pr: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Exit if triggered by GitHub Actions bot (avoid loops) | |
| if: github.actor == 'github-actions[bot]' | |
| run: | | |
| echo "Triggered by GitHub Actions bot; exiting to avoid loop." | |
| exit 0 | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: true | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./gradlew | |
| - name: Run Generator | |
| run: ./gradlew :generator:run --args="--openapi-url https://raw.githubusercontent.com/near/nearcore/master/chain/jsonrpc/openapi/openapi.json" --no-daemon | |
| - name: Build project (and run tests) | |
| run: ./gradlew build --stacktrace --no-daemon | |
| - name: Prepare branch, commit regenerated sources (if any) and push | |
| id: commit | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -euo pipefail | |
| # configure git author (actions token is present via checkout persist-credentials) | |
| git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| # create a unique branch name | |
| SHORT_SHA=${GITHUB_SHA:0:8} | |
| BRANCH="regenerate-openapi-${GITHUB_RUN_NUMBER}-${SHORT_SHA}" | |
| git checkout -b "$BRANCH" | |
| # stage all changes produced by generator | |
| git add . | |
| # if there are no staged changes, set output and exit gracefully | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| echo "pr_required=false" >> "$GITHUB_OUTPUT" | |
| exit 0 | |
| fi | |
| # commit and push branch | |
| git commit -m "chore: regenerate client from OpenAPI" | |
| git push --set-upstream origin "$BRANCH" | |
| # export outputs for next steps | |
| echo "pr_required=true" >> "$GITHUB_OUTPUT" | |
| echo "branch=$BRANCH" >> "$GITHUB_OUTPUT" | |
| - name: Create Pull Request for regenerated sources | |
| if: steps.commit.outputs.pr_required == 'true' | |
| uses: actions/github-script@v6 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const branch = context.payload.inputs?.branch || '${{ steps.commit.outputs.branch }}'; | |
| const title = `chore: regenerate client from OpenAPI (${branch})`; | |
| 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.`; | |
| // create PR targeting main | |
| const pr = await github.rest.pulls.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title, | |
| head: branch, | |
| base: "main", | |
| body | |
| }); | |
| // optionally add a label to PR (uncomment if you have label created) | |
| // await github.rest.issues.addLabels({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.data.number, labels: ["autogen"] }); | |
| return { pr_number: pr.data.number, pr_url: pr.data.html_url }; | |
| - name: Output when no changes | |
| if: steps.commit.outputs.pr_required != 'true' | |
| run: echo "No regenerated changes — nothing to create a PR for." |