-
Notifications
You must be signed in to change notification settings - Fork 950
71 lines (62 loc) · 2.61 KB
/
generate-code.yml
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
name: Generate code and open pull request
on:
workflow_dispatch:
pull_request:
push:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Setup
uses: actions/checkout@v4
with:
submodules: recursive
- name: Update submodules
run: git submodule update --remote --recursive
- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 17
architecture: x64
- uses: actions/setup-node@v4
- name: Generate code
run: |
python generate-code.py
diff=$(git --no-pager diff --name-only HEAD)
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
## Run if diff exists and pull request, and make CI status failure (but allow renovate bot)
- if: ${{ github.event_name == 'pull_request' && env.DIFF_IS_EMPTY != 'true' && github.actor != 'renovate[bot]' }}
run: |
echo "There are changes in the generated codes. Please run 'generate-code.py' and commit the changes." >&2
echo "The files with differences are as follows." >&2
echo "$(git --no-pager diff --name-only HEAD)" >&2
exit 1
## Run if diff exists and event is not pull request, and make PR
- if: ${{ github.event_name != 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
run: |
BRANCH_NAME="update-diff-${{ env.CURRENT_DATETIME }}"
git config user.name github-actions
git config user.email [email protected]
git checkout -b $BRANCH_NAME
git add .
git commit -m "Code are generated by openapi generator"
git push origin $BRANCH_NAME
# Determine PR title and body
if [ "$CHANGE_TYPE" == "submodule-update" ]; then
# Fetch PR info from submodule
npx zx ./line-openapi/tools/get-pr-info.mjs
PR_INFO=$(cat pr_info.json)
TITLE=$(echo "$PR_INFO" | jq -r '.title')
BODY=$(echo "$PR_INFO" | jq -r '.url')$'\n\n'$(echo "$PR_INFO" | jq -r '.body')
else
# Default PR title and body
TITLE="Codes are generated by openapi generator"
BODY="⚠Reviewer: Please edit this description to include relevant information about the changes.⚠"
fi
gh pr create -B ${{ github.ref_name }} -H $BRANCH_NAME -t "$TITLE" -b "$BODY" --label "line-openapi-update"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}