From ecc57a89e8fefeadb0572e9479809a01d168f523 Mon Sep 17 00:00:00 2001 From: Yuta Kasai Date: Fri, 13 Oct 2023 11:57:47 +0900 Subject: [PATCH] Open pull request automatically when code are generated by openapi generator (#532) github acitons doesn't support `push to change to protected branch`... - https://github.com/orgs/community/discussions/25305 - https://github.com/orgs/community/discussions/13836 - https://stackoverflow.com/questions/74128344/github-protected-branch-hook-declined-even-with-allow-force-pushes Thus we need to approve pull request created by github actions. --- .../{commit-generated-code.yml => generated-code.yml} | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) rename .github/workflows/{commit-generated-code.yml => generated-code.yml} (69%) diff --git a/.github/workflows/commit-generated-code.yml b/.github/workflows/generated-code.yml similarity index 69% rename from .github/workflows/commit-generated-code.yml rename to .github/workflows/generated-code.yml index 9dde44c4b..49a218eff 100644 --- a/.github/workflows/commit-generated-code.yml +++ b/.github/workflows/generated-code.yml @@ -1,4 +1,4 @@ -name: Commit generated code to master branch +name: Generate code and open pull request on: workflow_dispatch: @@ -24,12 +24,15 @@ jobs: python generate-code.py 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: | git config user.name github-actions git config user.email github-actions@github.com + git checkout -b update-diff-${{ env.CURRENT_DATETIME }} git add . git commit -m "Code are generated by openapi generator" - git push origin master + git push origin update-diff-${{ env.CURRENT_DATETIME }} + gh pr create -B ${{ github.ref_name }} -t "Codes are generated by openapi generator" -b "" --label "line-openapi-update" env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}