-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (89 loc) · 3.45 KB
/
regenerate-openapi-pr.yml
File metadata and controls
110 lines (89 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
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
pull-requests: write
jobs:
regenerate-and-pr:
runs-on: ubuntu-latest
steps:
# Avoid infinite loop triggered by GitHub Actions
- name: Exit if triggered by GitHub Actions bot
if: github.actor == 'github-actions[bot]'
run: |
echo "Triggered by GitHub Actions bot; exiting to avoid loop."
exit 0
# Checkout repo
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true
# Setup JDK
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 21
# Grant execute permission for Gradle
- name: Grant execute permission for gradlew
run: chmod +x ./gradlew
# Run Generator (regenerates client + models)
- name: Run Generator
run: ./gradlew :generator:run --args="--openapi-url https://raw.githubusercontent.com/near/nearcore/master/chain/jsonrpc/openapi/openapi.json" --no-daemon
# Build and run tests
- name: Build project (and run tests)
run: ./gradlew build --stacktrace --no-daemon
# Prepare branch, commit changes, push
- name: Prepare branch, commit regenerated sources
id: commit
env:
PAT_TOKEN: ${{ secrets.PAT_TOKEN }}
run: |
set -euo pipefail
git config --local user.email "automation@github.com"
git config --local user.name "GitHub Actions Bot"
# create unique branch
SHORT_SHA=${GITHUB_SHA:0:8}
BRANCH="regenerate-openapi-${GITHUB_RUN_NUMBER}-${SHORT_SHA}"
git checkout -b "$BRANCH"
git add .
# check if any changes
if git diff --staged --quiet; then
echo "No changes to commit"
echo "pr_required=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "fix: regenerate client from OpenAPI"
git push https://x-access-token:${PAT_TOKEN}@github.com/${GITHUB_REPOSITORY}.git "$BRANCH"
echo "pr_required=true" >> "$GITHUB_OUTPUT"
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
# Create Pull Request if changes exist
- name: Create Pull Request for regenerated sources
if: steps.commit.outputs.pr_required == 'true'
uses: actions/github-script@v6
with:
github-token: ${{ secrets.PAT_TOKEN }}
script: |
const 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.`;
const pr = await github.rest.pulls.create({
owner: context.repo.owner,
repo: context.repo.repo,
title,
head: branch,
base: "main",
body
});
return { pr_number: pr.data.number, pr_url: pr.data.html_url };
# Output when no changes
- name: Output when no changes
if: steps.commit.outputs.pr_required != 'true'
run: echo "No regenerated changes — nothing to create a PR for."