-
Notifications
You must be signed in to change notification settings - Fork 1
103 lines (85 loc) · 3.05 KB
/
generate-and-release.yml
File metadata and controls
103 lines (85 loc) · 3.05 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
name: Generate and Release NEAR RPC Client
on:
workflow_dispatch:
push:
schedule:
- cron: "0 0 * * *" # daily run (every day at midnight)
permissions:
contents: write
jobs:
build-and-release:
runs-on: ubuntu-latest
steps:
- 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 --no-daemon
- name: Build project
run: ./gradlew build --stacktrace --no-daemon
- name: Commit regenerated sources (if any) and push
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# always push to main branch
git checkout main
git add .
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore: regenerate client from OpenAPI"
git push origin main
fi
- name: Get or create Release
id: get_release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
let release = releases.data.find(r => r.tag_name === "v0.1.0");
if (!release) {
release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: "v0.1.0",
name: "NEAR RPC Client v0.1.0",
body: "Auto-generated client from the latest OpenAPI spec."
});
}
const assets = await github.rest.repos.listReleaseAssets({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: release.data.id
});
for (const asset of assets.data) {
if (asset.name === "near-rpc-client.zip") {
await github.rest.repos.deleteReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
asset_id: asset.id
});
}
}
return release.data.upload_url;
- name: Upload new ZIP
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.get_release.outputs.result }}
asset_path: release/near-rpc-client.zip
asset_name: near-rpc-client.zip
asset_content_type: application/zip