-
Notifications
You must be signed in to change notification settings - Fork 1
147 lines (125 loc) · 4.32 KB
/
pull-request.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: pr
on:
pull_request:
branches:
- main
env:
GIT_AUTHOR_NAME: github-actions[bot]
GIT_AUTHOR_EMAIL: 41898282+github-actions[bot]@users.noreply.github.com
GIT_COMMITTER_NAME: GitHub
GIT_COMMITTER_EMAIL: [email protected]
CDK_DEFAULT_ACCOUNT: 111111111111
CDK_DEFAULT_REGION: us-east-1
CDK_DEPLOY_STAGES: dev int tp prod
CDK_DEPLOY_dev_ACCOUNTS: 111111111111
CDK_DEPLOY_int_ACCOUNTS: 111111111111
CDK_DEPLOY_tp_ACCOUNTS: 333333333333
CDK_DEPLOY_prod_ACCOUNTS: 333333333333
CDK_DEPLOY_dev_111111111111_REGIONS: us-east-1
CDK_DEPLOY_int_111111111111_REGIONS: us-east-1
CDK_DEPLOY_tp_333333333333_REGIONS: us-east-1
CDK_DEPLOY_prod_333333333333_REGIONS: us-east-1
jobs:
cdk-diff:
runs-on: ubuntu-latest
steps:
- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: "16"
- name: Setup Python
uses: actions/setup-python@v3
with:
python-version: "3.9"
- name: Install CDK
run: npm install -g aws-cdk@1
- name: Checkout main
uses: actions/checkout@v3
with:
ref: main
fetch-depth: 0
- name: Install main dependencies
run: pip install pip-tools && pip-sync
- name: CDK synth main
run: cdk synth -o base.cdk.out
- name: Checkout PR branch
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
clean: false
- name: Merge main to PR branch
run: git merge origin/main
- name: Install PR branch dependencies
run: pip-sync
- name: CDK synth PR branch
run: cdk synth -o head.cdk.out
- name: Comment on Pull Request
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var fs = require('fs');
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: fs.readFileSync('${{ steps.diff.outputs.comment_file }}', 'utf8')
})
# Always run this last as it can push new changes and actions will not rerun.
pre-commit:
needs: [cdk-diff]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
- name: Setup Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install PreCommit
run: pip install pre-commit
- name: Cache
uses: actions/cache@v2
with:
path: ~/.cache/pre-/Users/ejimenez/work/BBDN-Base-Python-Flask/.github
key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }}
- name: PreCommit
id: pre-commit
run: |
if SKIP=flake8 pre-commit run --show-diff-on-failure --color=always --all-files; then
echo "::set-output name=failed::0"
else
echo "::set-output name=failed::1"
fi
if [ -n "$(git status -s)" ]; then
echo "::set-output name=dirty::1"
else
echo "::set-output name=dirty::0"
fi
# Run a second time to verify that everything has indeed been fixed.
- name: PreCommit verify
if: steps.pre-commit.outputs.failed == 1
run: |
SKIP=flake8 pre-commit run --show-diff-on-failure --color=always --all-files
- name: Commit and Push to Pull Request
if: steps.pre-commit.outputs.failed == 1 && steps.pre-commit.outputs.dirty == 1
run: |
git add .
git status
git commit -m "Automated formatting changes"
git push origin ${{ github.head_ref }}
- name: Comment on Pull Request
if: steps.pre-commit.outputs.failed == 1 && steps.pre-commit.outputs.dirty == 1
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ':sparkles: :star: A new commit has been added to your pull request to fix formatting! :star: :sparkles:'
})