Skip to content

Commit 2114ccc

Browse files
authored
Refactor duplicated CI code (#639)
Close #637
1 parent b61ddc8 commit 2114ccc

File tree

2 files changed

+12
-56
lines changed

2 files changed

+12
-56
lines changed

.github/workflows/diff-check.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ on:
55
push:
66
branches:
77
- master
8+
pull_request:
9+
merge_group:
810

911
jobs:
1012
tests:
11-
name: Diff check and push
13+
name: Generate OpenAPI based code
1214
runs-on: ubuntu-latest
1315

1416
steps:
@@ -55,7 +57,15 @@ jobs:
5557
diff=$(git --no-pager diff --name-only HEAD)
5658
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
5759
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
58-
- if: ${{ env.DIFF_IS_EMPTY != 'true' }}
60+
## Run if diff exists and pull request, and make CI status failure (but allow renovate bot)
61+
- if: ${{ github.event_name == 'pull_request' && env.DIFF_IS_EMPTY != 'true' && github.actor != 'renovate[bot]' }}
62+
run: |
63+
echo "There are changes in the generated codes. Please run 'generate-code.py' and commit the changes." >&2
64+
echo "The files with differences are as follows." >&2
65+
echo "$(git --no-pager diff --name-only HEAD)" >&2
66+
exit 1
67+
## Run if diff exists and event is not pull request, and make PR
68+
- if: ${{ github.event_name != 'pull_request' && env.DIFF_IS_EMPTY != 'true' }}
5969
run: |
6070
BRANCH_NAME="update-diff-${{ env.CURRENT_DATETIME }}"
6171

.github/workflows/php-checks.yml

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,60 +6,6 @@ on:
66
merge_group:
77

88
jobs:
9-
diff-check:
10-
name: Diff check
11-
runs-on: ubuntu-latest
12-
13-
steps:
14-
# Setup
15-
- uses: actions/checkout@v4
16-
with:
17-
submodules: recursive
18-
- name: Update submodules
19-
run: git submodule update --remote --recursive
20-
- uses: actions/setup-node@v4
21-
id: setup_node_id
22-
with:
23-
node-version: 18
24-
- uses: shivammathur/setup-php@v2
25-
with:
26-
php-version: 8.2
27-
28-
# Install openapi-generator-cli
29-
- run: echo "OPENAPI_GENERATOR_VERSION=6.6.0" >> $GITHUB_ENV
30-
- uses: actions/cache@v4
31-
id: openapi-generator-cache
32-
env:
33-
cache-name: openapi-generator-cache
34-
with:
35-
path: ~/bin/openapitools
36-
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ env.OPENAPI_GENERATOR_VERSION }}
37-
- if: steps.openapi-generator-cache.outputs.cache-hit != 'true'
38-
run: |
39-
mkdir -p ~/bin/openapitools
40-
curl https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/bin/utils/openapi-generator-cli.sh > ~/bin/openapitools/openapi-generator-cli
41-
chmod u+x ~/bin/openapitools/openapi-generator-cli
42-
export PATH=$PATH:~/bin/openapitools/
43-
OPENAPI_GENERATOR_VERSION=${{ env.OPENAPI_GENERATOR_VERSION }} openapi-generator-cli version
44-
45-
- name: Generate codes
46-
run: |
47-
export PATH=$PATH:~/bin/openapitools/
48-
bash tools/gen-oas-client.sh
49-
- name: Update document
50-
run: |
51-
wget https://github.com/phpDocumentor/phpDocumentor/releases/download/v3.3.1/phpDocumentor.phar
52-
php phpDocumentor.phar run -d src -t docs
53-
- run: |
54-
diff=$(git --no-pager diff --name-only HEAD)
55-
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
56-
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
57-
- if: ${{ env.DIFF_IS_EMPTY != 'true' && github.actor != 'renovate[bot]' }}
58-
run: |
59-
echo "There are changes from the auto-generated files by OAS. Please run diff-check.yml and merge the PR generated by it first."
60-
echo "The files with differences are as follows."
61-
echo "$(git --no-pager diff --name-only HEAD)"
62-
exit 1
639
tests:
6410
name: Run checks on PHP ${{ matrix.php }}
6511
runs-on: ubuntu-latest

0 commit comments

Comments
 (0)