Skip to content

Commit 80bdf3d

Browse files
committed
Open pull request automatically when line-openapi is updated
1 parent bc25f75 commit 80bdf3d

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

.github/workflows/diff-check.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Diff check and open pull request
2+
3+
on: [push, pull_request] # For test
4+
#on:
5+
# push:
6+
# branches:
7+
# - 'master'
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Setup
15+
uses: actions/checkout@v3
16+
with:
17+
submodules: recursive
18+
- name: Set up Python
19+
uses: actions/setup-python@v4
20+
with:
21+
python-version: '3.x'
22+
- name: Generate codes
23+
run: python generate-code.py
24+
- name: Mark if diff exists
25+
run: |
26+
diff=$(git --no-pager diff --name-only)
27+
echo "DIFF_IS_EMPTY=$([[ -z "$diff" ]] && echo 'true' || echo 'false')" >> $GITHUB_ENV
28+
echo "CURRENT_DATETIME=$(date +'%Y%m%d%H%M%S')" >> $GITHUB_ENV
29+
- name: Open pull request if generated code is not same as current one
30+
if: ${{ env.DIFF_IS_EMPTY != 'true' }}
31+
run: |
32+
git config user.name github-actions
33+
git config user.email github-actions@github.com
34+
git checkout -b update-diff-${{ env.CURRENT_DATETIME }}
35+
git add .
36+
git commit -m "Codes are generated by openapi"
37+
git push origin update-diff-${{ env.CURRENT_DATETIME }}
38+
gh pr create -B ${{ github.ref_name }} -t "Codes are generated by openapi" -b ""
39+
env:
40+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)