Skip to content

Commit 3fc5017

Browse files
authored
Setup workflows for OpenAPI code generation (#366)
resolve #304 #346 #346 and #361 The following code has been added and updated based on code in other languages. - Workflow for OpenAPI code generation - Renovate configuration file
1 parent c2731f5 commit 3fc5017

4 files changed

Lines changed: 128 additions & 19 deletions

File tree

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
name: Generate OpenAPI based code
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
push:
7+
branches:
8+
- master
9+
10+
jobs:
11+
tests:
12+
name: Generate OpenAPI based code
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
pull-requests: write
17+
18+
steps:
19+
# Setup
20+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
with:
22+
submodules: recursive
23+
- name: Update submodules
24+
run: git submodule update --remote --recursive
25+
- uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
26+
id: setup_node_id
27+
with:
28+
node-version: 18
29+
- name: Set up Java
30+
uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
31+
with:
32+
distribution: 'temurin'
33+
java-version: 17
34+
architecture: x64
35+
36+
# Generate codes
37+
- name: Generate code
38+
run: python3 generate-code.py
39+
- run: |
40+
diff=$(git --no-pager diff --name-only)
41+
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
42+
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
43+
## Run if diff exists and pull request, and make CI status failure (but allow renovate bot)
44+
- if: ${{ github.event_name == 'pull_request' && env.DIFF_IS_EMPTY != 'true' && github.actor != 'renovate[bot]' }}
45+
run: |
46+
echo "There are changes in the generated codes. Please run 'generate-code.py' and commit the changes." >&2
47+
echo "The files with differences are as follows." >&2
48+
echo "$(git --no-pager diff --name-only HEAD)" >&2
49+
exit 1
50+
## Run if diff exists and event is not pull request, and make PR
51+
- if: ${{ github.event_name != 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
52+
run: |
53+
# Determine Change Type via Submodule Script. This scripts read current uncommited changes.
54+
CHANGE_TYPE=$(npx zx ./line-openapi/tools/determine-change-type.mjs)
55+
echo "Determined change type: $CHANGE_TYPE"
56+
57+
# Determine PR title and body
58+
if [ "$CHANGE_TYPE" == "submodule-update" ]; then
59+
# Fetch PR info from submodule
60+
npx zx ./line-openapi/tools/get-pr-info.mjs
61+
PR_INFO=$(cat pr_info.json)
62+
TITLE=$(echo "$PR_INFO" | jq -r '.title')
63+
BODY=$(echo "$PR_INFO" | jq -r '.url')$'\n\n'$(echo "$PR_INFO" | jq -r '.body')
64+
else
65+
# Default PR title and body
66+
TITLE="Codes are generated by openapi generator"
67+
BODY="⚠Reviewer: Please edit this description to include relevant information about the changes.⚠"
68+
fi
69+
70+
# Create PR
71+
BRANCH_NAME="update-diff-${{ env.CURRENT_DATETIME }}"
72+
73+
git config user.name github-actions
74+
git config user.email github-actions@github.com
75+
git checkout -b $BRANCH_NAME
76+
77+
git add line-openapi
78+
git add lib/**
79+
git commit -m "Codes are generated by openapi"
80+
81+
git push origin $BRANCH_NAME
82+
83+
gh pr create -B ${{ github.ref_name }} -H $BRANCH_NAME -t "$TITLE" -b "$BODY" --label "line-openapi-update"
84+
env:
85+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pull_request.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,17 @@ jobs:
1919
name: Ruby v${{ matrix.ruby }}
2020
steps:
2121
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
22+
with:
23+
submodules: true
2224
- uses: ruby/setup-ruby@354a1ad156761f5ee2b7b13fa8e09943a5e8d252 # v1.229.0
2325
with:
2426
ruby-version: ${{ matrix.ruby }}
27+
- uses: actions/setup-java@3a4f6e1af504cf6a31855fa899c6aa5355ba6c12 # v4.7.0
28+
with:
29+
distribution: 'temurin'
30+
java-version: 17
31+
architecture: x64
32+
- run: python3 generate-code.py
2533
- run: gem install bundler
2634
- run: bundle install
2735
- run: bundle exec rubocop

renovate.json

Lines changed: 0 additions & 19 deletions
This file was deleted.

renovate.json5

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"extends": [
4+
"config:recommended",
5+
"helpers:pinGitHubActionDigestsToSemver"
6+
],
7+
"timezone": "Asia/Tokyo",
8+
"automerge": true,
9+
"platformAutomerge": true,
10+
"git-submodules": {
11+
"enabled": true
12+
},
13+
"labels": [
14+
"dependency upgrade"
15+
],
16+
"packageRules": [
17+
{
18+
"matchPackagePatterns": [
19+
"line-openapi"
20+
],
21+
"labels": [
22+
"dependency upgrade",
23+
"line-openapi-update"
24+
],
25+
// In many cases, we would like to update line-openapi by dispatching the GitHub workflow during working
26+
// hours, as there are code changes.
27+
// If that is forgotten, there's a possibility that line-openapi updates or code changes won't happen at
28+
// all, so we allow it to run at night just in case.
29+
"schedule": [
30+
"after 11pm",
31+
"before 4am"
32+
]
33+
},
34+
]
35+
}

0 commit comments

Comments
 (0)