From 5a2bea57b7c051d368f5e7240e83860103407785 Mon Sep 17 00:00:00 2001 From: eucyt Date: Wed, 25 Dec 2024 10:43:33 +0900 Subject: [PATCH] Refactor duplicated CI code --- .github/workflows/diff-check.yml | 14 +++++++-- .github/workflows/php-checks.yml | 52 -------------------------------- 2 files changed, 12 insertions(+), 54 deletions(-) diff --git a/.github/workflows/diff-check.yml b/.github/workflows/diff-check.yml index ae88a1eb..a3eb460c 100644 --- a/.github/workflows/diff-check.yml +++ b/.github/workflows/diff-check.yml @@ -5,10 +5,12 @@ on: push: branches: - master + pull_request: + merge_group: jobs: tests: - name: Diff check and push + name: Generate OpenAPI based code runs-on: ubuntu-latest steps: @@ -55,7 +57,15 @@ jobs: 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 - - if: ${{ env.DIFF_IS_EMPTY != 'true' }} + ## 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: | git config user.name github-actions git config user.email github-actions@github.com diff --git a/.github/workflows/php-checks.yml b/.github/workflows/php-checks.yml index b74a7223..1407007f 100644 --- a/.github/workflows/php-checks.yml +++ b/.github/workflows/php-checks.yml @@ -6,58 +6,6 @@ on: merge_group: jobs: - diff-check: - name: Diff check - runs-on: ubuntu-latest - - steps: - # Setup - - uses: actions/checkout@v4 - with: - submodules: recursive - - name: Update submodules - run: git submodule update --remote --recursive - - uses: actions/setup-node@v4 - id: setup_node_id - with: - node-version: 18 - - uses: shivammathur/setup-php@v2 - with: - php-version: 8.2 - - # Install openapi-generator-cli - - run: echo "OPENAPI_GENERATOR_VERSION=6.6.0" >> $GITHUB_ENV - - uses: actions/cache@v4 - 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=$(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 - - if: ${{ env.DIFF_IS_EMPTY != 'true' }} - run: | - echo "There are changes from the auto-generated files by OAS. Please run diff-check.yml and merge the PR generated by it first." - exit 1 tests: name: Run checks on PHP ${{ matrix.php }} runs-on: ubuntu-latest