-
Notifications
You must be signed in to change notification settings - Fork 647
121 lines (108 loc) · 4.86 KB
/
generate-code.yml
File metadata and controls
121 lines (108 loc) · 4.86 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
111
112
113
114
115
116
117
118
119
120
121
name: Generate code and open pull request
on:
push:
branches:
- 'master'
pull_request:
merge_group:
workflow_dispatch:
jobs:
tests:
name: Generate OpenAPI based code
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
# Setup
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
submodules: recursive
- name: Update submodules
run: git submodule update --remote --recursive
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
id: setup_node_id
with:
node-version: 22
- uses: shivammathur/setup-php@ec406be512d7077f68eed36e63f4d91bc006edc4 # 2.35.4
with:
php-version: 8.2
# Install openapi-generator-cli
- run: echo "OPENAPI_GENERATOR_VERSION=7.11.0" >> $GITHUB_ENV
- uses: actions/cache@0400d5f644dc74513175e3cd8d07132dd4860809 # v4.2.4
id: openapi-generator-cache
env:
cache-name: openapi-generator-cache
with:
path: ~/bin/openapitools
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.OPENAPI_GENERATOR_VERSION }}
- if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
run: |
mkdir -p ~/bin/openapitools
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
chmod u+x ~/bin/openapitools/openapi-generator-cli
export PATH=$PATH:~/bin/openapitools/
OPENAPI_GENERATOR_VERSION=${{ env.OPENAPI_GENERATOR_VERSION }} openapi-generator-cli version
- name: Generate codes
run: |
export PATH=$PATH:~/bin/openapitools/
bash tools/gen-oas-client.sh
- name: Update document
run: |
wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.3.1/phpDocumentor.phar
php phpDocumentor.phar run -d src -t docs
- run: |
diff_files=$(git --no-pager diff --name-only)
diff_excluding_submodule=$(echo "$diff_files" | grep -v '^line-openapi$' || true)
echo "diff files: $diff_files"
echo "diff excluding submodule: $diff_excluding_submodule"
echo "DIFF_IS_EMPTY=$([[ -z "$diff_excluding_submodule" ]] && 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 or merge queue, and make CI status failure (but allow renovate bot)
- if: >-
${{
(github.event_name == 'pull_request' || github.event_name == 'merge_group')
&& 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 push or workflow_dispatch, make PR
- if: >-
${{
(github.event_name == 'push' || github.event_name == 'workflow_dispatch')
&& env.DIFF_IS_EMPTY != 'true'
}}
run: |
# Determine Change Type via Submodule Script. This scripts read current uncommited changes.
CHANGE_TYPE=$(npx zx ./line-openapi/tools/determine-change-type.mjs)
echo "Determined change type: $CHANGE_TYPE"
# 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
# Create PR
BRANCH_NAME="update-diff-${{ env.CURRENT_DATETIME }}"
git config user.name github-actions
git config user.email github-actions@github.com
git checkout -b $BRANCH_NAME
git add line-openapi
git add src/**
git commit --allow-empty -m "Codes are generated by openapi generator"
git add docs/**
git commit --allow-empty -m "Update document"
git push origin $BRANCH_NAME
gh pr create -B ${{ github.ref_name }} -H $BRANCH_NAME -t "$TITLE" -b "$BODY" --label "line-openapi-update"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}