From 3aba3c60c479444c5b68d2fafb34eddc5f77e15d Mon Sep 17 00:00:00 2001 From: Motoi Okuzono Date: Tue, 21 Jan 2025 11:20:14 +0900 Subject: [PATCH 1/2] Add generate-code workflow #304 #346 #347 --- .github/workflows/generate-code.yml | 87 +++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 .github/workflows/generate-code.yml diff --git a/.github/workflows/generate-code.yml b/.github/workflows/generate-code.yml new file mode 100644 index 00000000..7699773a --- /dev/null +++ b/.github/workflows/generate-code.yml @@ -0,0 +1,87 @@ +name: Generate OpenAPI based code + +on: + workflow_dispatch: + pull_request: + push: + branches: + - master + +jobs: + tests: + name: Generate OpenAPI based code + runs-on: ubuntu-latest + + steps: + # Setup + - uses: actions/checkout@v4 + with: + submodules: recursive + - name: Update submodules + run: git submodule update --remote --recursive + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.x' + - name: Set up Java + uses: actions/setup-java@v4 + with: + distribution: 'temurin' + java-version: 17 + architecture: x64 + - name: Set up Node + - uses: actions/setup-node@v4 + id: setup_node_id + with: + node-version: 18 + + # Generate codes + - name: Generate code + run: python3 generate-code.py + - run: | + diff=$(git --no-pager diff --name-only) + 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: | + # 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 lib/** + git commit -m "Codes are generated by openapi" + + 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 }} From 10e1520ba5c0aaf9a37f7d516dae23e431cd1667 Mon Sep 17 00:00:00 2001 From: Motoi Okuzono Date: Tue, 21 Jan 2025 11:34:09 +0900 Subject: [PATCH 2/2] Fix renovate config for git submodule #361 --- renovate.json | 18 ------------------ renovate.json5 | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 18 deletions(-) delete mode 100644 renovate.json create mode 100644 renovate.json5 diff --git a/renovate.json b/renovate.json deleted file mode 100644 index 7dac1bf1..00000000 --- a/renovate.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "$schema": "https://docs.renovatebot.com/renovate-schema.json", - "extends": [ - "config:base" - ], - "automerge": true, - "platformAutomerge": true, - "git-submodules": { - "enabled": true - }, - "labels": [ "dependency upgrade" ], - "packageRules": [ - { - "matchPackagePatterns": ["^line-openapi$"], - "labels": ["dependency upgrade", "line-openapi-update"] - } - ] -} diff --git a/renovate.json5 b/renovate.json5 new file mode 100644 index 00000000..24f76eeb --- /dev/null +++ b/renovate.json5 @@ -0,0 +1,34 @@ + { + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:recommended" + ], + "timezone": "Asia/Tokyo", + "automerge": true, + "platformAutomerge": true, + "git-submodules": { + "enabled": true + }, + "labels": [ + "dependency upgrade" + ], + "packageRules": [ + { + "matchPackagePatterns": [ + "line-openapi" + ], + "labels": [ + "dependency upgrade", + "line-openapi-update" + ], + // In many cases, we would like to update line-openapi by dispatching the GitHub workflow during working + // hours, as there are code changes. + // If that is forgotten, there's a possibility that line-openapi updates or code changes won't happen at + // all, so we allow it to run at night just in case. + "schedule": [ + "after 11pm", + "before 4am" + ] + }, + ] + }