-
Notifications
You must be signed in to change notification settings - Fork 784
68 lines (60 loc) · 2.08 KB
/
update-generated-files.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
name: Update generated files
on:
push:
branches:
- develop
env:
BRANCH_NAME: sync-generated-files
jobs:
update_genereated_files:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Build
run: |
npm ci
npm run build
- name: Check for changes
id: changes
run: |
changes=$(git status --porcelain)
# see https://unix.stackexchange.com/a/509498
echo $changes | grep . && echo "Changes detected" || echo "No changes"
echo ::set-output name=changes::"$changes"
- name: Check branch exists
id: branchExists
if: steps.changes.outputs.changes
run: |
exists=$(git ls-remote --heads origin $BRANCH_NAME)
echo $exists | grep . && echo "Branch '$BRANCH_NAME' already exists on remote" || echo "Branch does not exists in remote"
echo ::set-output name=exists::"$exists"
- name: Create pull request
if: ${{ steps.changes.outputs.changes && !steps.branchExists.outputs.exists }}
run: |
git status
git config user.name github-actions
git config user.email [email protected]
git add .
git checkout -b $BRANCH_NAME
git commit -m "chore: sync generated files"
git push origin $BRANCH_NAME
gh pr create --base develop --head $BRANCH_NAME --title "chore: sync generated files" --body ""
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Update pull request
if: ${{ steps.changes.outputs.changes && steps.branchExists.outputs.exists }}
run: |
git reset HEAD --hard
git checkout $BRANCH_NAME
npm run build
git status
git config user.name github-actions
git config user.email [email protected]
git add .
git commit -m "chore: sync generated files"
git push origin $BRANCH_NAME
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}