This repository has been archived by the owner on Dec 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
155 lines (133 loc) · 4.34 KB
/
ci.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
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
148
149
150
151
152
153
154
155
name: CI
on:
pull_request:
push:
branches: main
permissions:
id-token: write
contents: read
pull-requests: write
env:
LOG_COLOR: always
STACKCTL_CHANGES: /tmp/changes.md
STACKCTL_VERSION: 1.6.0.0
jobs:
validate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install cfn-lint
- run: cfn-lint
changes:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- id: filter
uses: dorny/paths-filter@v3
with:
filters: |
yamls:
- 'cg-app/stacks/**/*.yaml'
- 'cg-app/templates/**/*.json'
- 'cg-app/templates/**/*.yaml'
list-files: csv
# Make the paths relative to cg-app
- id: format
run: |
{
echo 'files<<EOF'
sed 's%cg-app/%%g' <<'EOM'
${{ steps.filter.outputs.yamls_files }}
EOM
echo 'EOF'
} >> "$GITHUB_OUTPUT"
outputs:
files: ${{ steps.format.outputs.files }}
comment-changes:
if: ${{ github.ref != 'refs/heads/main' }}
needs: changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pbrisbin/setup-tool-action@v2
with:
name: stackctl
version: ${{ env.STACKCTL_VERSION }}
url: "https://github.com/freckle/{name}/releases/download/v{version}/{name}-{arch}-{os}.{ext}"
arch: x86_64
os-darwin: osx
subdir: "{name}"
- run: echo 'STACKCTL_FILTER=${{ needs.changes.outputs.files }}' >>"$GITHUB_ENV"
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
- if: ${{ needs.changes.outputs.files != '' }}
working-directory: cg-app
run: stackctl changes --format pr "$STACKCTL_CHANGES"
- run: |
if [[ ! -s "$STACKCTL_CHANGES" ]]; then
echo 'No Stack changes produced by this PR' | tee "$STACKCTL_CHANGES"
fi
- uses: mshick/add-pr-comment@v2
with:
message-path: ${{ env.STACKCTL_CHANGES }}
refresh-message-position: "true"
deploy-changes:
if: ${{ github.ref == 'refs/heads/main' }}
needs: changes
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pbrisbin/setup-tool-action@v2
with:
name: stackctl
version: ${{ env.STACKCTL_VERSION }}
url: "https://github.com/freckle/{name}/releases/download/v{version}/{name}-{arch}-{os}.{ext}"
arch: x86_64
os-darwin: osx
subdir: "{name}"
- run: echo 'STACKCTL_FILTER=${{ needs.changes.outputs.files }}' >>"$GITHUB_ENV"
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
- if: ${{ needs.changes.outputs.files != '' }}
working-directory: cg-app
run: |
stackctl deploy --save-change-sets /tmp/changes --no-confirm --clean
- if: ${{ always() }}
id: notification
env:
GH_TOKEN: ${{ github.token }}
run: |
cat /tmp/changes/*.json |
jq --raw-output '.changes[].resourceChange.action | select(.)' |
sort | uniq -c > changes.txt || true
if [[ ! -s changes.txt ]]; then
echo 'No changes' > changes.txt
fi
{
echo "slack-message<<EOM"
echo '```'
cat changes.txt
echo '```'
echo
gh run view "${{ github.run_id }}" --json jobs --jq ".jobs[] | select(.name == \"${{ github.job }}\") | .url"
echo "EOM"
} >>"$GITHUB_OUTPUT"
- if: ${{ always() }}
uses: zulip/github-actions-zulip/send-message@v1
with:
api-key: ${{ secrets.ZULIP_API_KEY }}
email: ${{ secrets.ZULIP_EMAIL }}
organization-url: ${{ secrets.ZULIP_ORGANIZATION_URL }}
to: 'core team'
type: 'stream'
topic: 'Infra Deployments'
content: |
${{ job.status == 'success' && ':check:' || ':warning:' }} `restyled-io/ops` deployed
${{ steps.notification.outputs.slack-message }}