Skip to content

Commit 43e6af3

Browse files
committed
Add generate-code workflow line#304 line#346 line#347
1 parent 46e2059 commit 43e6af3

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

Diff for: .github/workflows/generate-code.yml

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

0 commit comments

Comments
 (0)