Skip to content

Commit

Permalink
Open pull request automatically when code are generated by openapi ge…
Browse files Browse the repository at this point in the history
…nerator (#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.
  • Loading branch information
Yang-33 authored Oct 13, 2023
1 parent e9e1ce1 commit ecc57a8
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Commit generated code to master branch
name: Generate code and open pull request

on:
workflow_dispatch:
Expand All @@ -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 }}

0 comments on commit ecc57a8

Please sign in to comment.