105 lines (86 loc) · 2.93 KB
/
pr.yml
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
name: PR
on:
pull_request:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Mount bazelisk cache
id: bazelisk-cache
uses: actions/cache@v2
with:
path: |
- /home/runner/.cache/bazelisk
- /usr/local/bin/bazel
key: bazelisk-cache-${{ hashFiles('.bazeliskversion') }}
- name: Install & Configure Bazelisk
if: steps.bazelisk-cache.outputs.cache-hit != 'true'
run: |
BAZELISK_VERSION=`cat .bazeliskversion`
curl -LO "https://github.com/bazelbuild/bazelisk/releases/download/${BAZELISK_VERSION}/bazelisk-linux-amd64"
sudo mv bazelisk-linux-amd64 /usr/local/bin/bazel
sudo chmod +x /usr/local/bin/bazel
- name: Mount bazel caches
uses: actions/cache@v2
with:
path: |
- /home/runner/.cache/bazel/_bazel_runner/cache/repos/v1
- /home/runner/.cache/bazel-disk-cache
key: bazel-cache- ${{ hashFiles('.bazelversion', 'WORKSPACE') }}
- name: Configure
run: |
mkdir -p /home/runner/.cache/bazel-disk-cache
sudo cp ${GITHUB_WORKSPACE}/.github/workflows/.bazelrc-ci /etc/bazel.bazelrc
bazel info
- name: Test
run: |
bazel test //...
- name: Synth
run: |
bazel build infra:synth
find dist/bin/infra/cdk.out -type d -exec chmod 0755 {} \;
- name: Upload Cloud Assembly
uses: actions/upload-artifact@v1
with:
name: cdk.out
path: dist/bin/infra/cdk.out
diff:
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@v1
- name: Mount node_modules
uses: actions/cache@v1
id: cache-node
with:
path: node_modules
key: package - ${{ hashFiles('package.json') }}
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: eu-west-1
- name: Download Cloud Assembly
uses: actions/download-artifact@v1
with:
name: cdk.out
- run: npm install
if: steps.cache-node.outputs.cache-hit != 'true'
- name: Run CDK diff
run: node_modules/.bin/cdk diff -c aws-cdk:enableDiffNoFail=true --no-color --app cdk.out "*" 2>&1 | tee cdk.log
- name: Add comment to PR
env:
URL: ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
jq --raw-input --slurp '{body: .}' cdk.log > cdk.json
curl \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
-d @cdk.json \
-X POST \
$URL