Skip to content

chore(deps): update actions/cache action to v5 (#768) #389

chore(deps): update actions/cache action to v5 (#768)

chore(deps): update actions/cache action to v5 (#768) #389

Workflow file for this run

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@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
submodules: recursive
- name: Update submodules
run: git submodule update --remote --recursive
- uses: actions/setup-node@395ad3262231945c25e8478fd5baf05154b1d79f # v6.1.0
id: setup_node_id
with:
node-version: 24
- uses: shivammathur/setup-php@44454db4f0199b8b9685a5d763dc37cbf79108e1 # 2.36.0
with:
php-version: 8.2
# Install openapi-generator-cli
- run: echo "OPENAPI_GENERATOR_VERSION=7.11.0" >> $GITHUB_ENV
- uses: actions/cache@a7833574556fa59680c1b7cb190c1735db73ebf0 # v5.0.0
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.8.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
# Save full diff to file and upload artifact
- name: Save full diff to file
if: env.DIFF_IS_EMPTY != 'true'
run: |
git --no-pager diff HEAD > diff.patch
echo "Full diff saved to diff.patch"
- name: Upload diff artifact
if: env.DIFF_IS_EMPTY != 'true'
uses: actions/upload-artifact@330a01c490aca151604b8cf639adc76d48f6c5d4 # v5.0.0
with:
name: codegen-diff
path: diff.patch
## Run if diff exists and pull request or merge queue, and make CI status failure (but allow renovate bot)
## 29139614 is renovate bot's actor id
- if: >-
${{
(github.event_name == 'pull_request' || github.event_name == 'merge_group')
&& env.DIFF_IS_EMPTY != 'true'
&& github.actor_id != '29139614'
}}
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 }}