-
Notifications
You must be signed in to change notification settings - Fork 0
150 lines (140 loc) · 5.27 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
name: CI
on:
push:
branches:
- develop
- main
workflow_dispatch:
env:
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
SLACK_SIGNING_SECRET: ${{ secrets.SLACK_SIGNING_SECRET }}
SLACK_TOKEN: ${{ secrets.SLACK_TOKEN }}
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
id: node
with:
node-version: 20.11.1
- name: Send Slack notification
uses: codedsolar/slack-action@v1
if: ${{ github.event_name != 'pull_request' }}
id: slack
with:
fields: |
{STATUS}
{REF}
Node.js: ${{ steps.node.outputs.node-version }}
Hadolint issues: Checking...
Prettier issues: Checking...
status: in-progress
- name: Enable corepack
run: corepack enable
- name: Install Prettier
run: yarn global add prettier
- name: Lint using Prettier
run: prettier --check . || true
- name: Output Prettier results
id: prettier-output
run: echo "issues=$(prettier --list-different . | wc -l)" >> $GITHUB_OUTPUT
- name: Lint using Hadolint (official)
uses: hadolint/[email protected]
id: hadolint-official
with:
dockerfile: ./official/Dockerfile
no-fail: true
- name: Lint using Hadolint (tshock)
uses: hadolint/[email protected]
id: hadolint-tshock
with:
dockerfile: ./tshock/Dockerfile
no-fail: true
- name: Output Hadolint results
id: hadolint-output
run: |
official_issues="$(echo '${{ steps.hadolint-official.outputs.results }}' | sed '/^$/d' | sed '$!N; /^\n$/D' | wc -l)"
tshock_issues="$(echo '${{ steps.hadolint-tshock.outputs.results }}' | sed '/^$/d' | sed '$!N; /^\n$/D' | wc -l)"
echo "official-issues=$official_issues" >> $GITHUB_OUTPUT
echo "tshock-issues=$tshock_issues" >> $GITHUB_OUTPUT
echo "issues=$((official_issues + tshock_issues))" >> $GITHUB_OUTPUT
- name: Check results
run: |
hadolint_official_issues="${{ steps.hadolint-output.outputs.official-issues }}"
hadolint_tshock_issues="${{ steps.hadolint-output.outputs.tshock-issues }}"
hadolint_issues="${{ steps.hadolint-output.outputs.issues }}"
prettier_issues="${{ steps.prettier-output.outputs.issues }}"
echo "Hadolint issues (official): $hadolint_official_issues"
echo "Hadolint issues (tshock): $hadolint_tshock_issues"
echo "Total Hadolint issues: $((hadolint_official_issues + hadolint_tshock_issues))"
echo "Total Prettier issues: $prettier_issues"
exit_code=1
if [ "$prettier_issues" = '0' ] && [ "$hadolint_official_issues" = '0' ] && [ "$hadolint_tshock_issues" = '0' ]; then
exit_code=0
fi
exit "$exit_code"
- name: Update Slack notification
uses: codedsolar/slack-action@v1
if: ${{ github.event_name != 'pull_request' && always() }}
with:
fields: |
{STATUS}
{REF}
Node.js: ${{ steps.node.outputs.node-version }}
Hadolint issues: ${{ steps.hadolint-output.outputs.issues || 'Skipped' }}
Prettier issues: ${{ steps.prettier-output.outputs.issues || 'Skipped' }}
status: ${{ job.status }}
timestamp: ${{ steps.slack.outputs.slack-timestamp }}
test:
runs-on: ubuntu-latest
steps:
- name: Check out
uses: actions/checkout@v4
- name: Send Slack notification
uses: codedsolar/slack-action@v1
if: ${{ github.event_name != 'pull_request' }}
id: slack
with:
fields: |
{STATUS}
{REF}
Passed Bats tests: Testing...
status: in-progress
- name: Install Bats
run: |
sudo apt-get update
sudo apt-get install -y bats
- name: Test using Bats
id: bats
run: |
output="$(bats ./official/entrypoint/)"
tests_passed="$(echo "$output" | grep -c '^ok')"
tests_total="$(bats -c ./official/entrypoint/)"
echo "$output"
echo "output=$bats_output" >> $GITHUB_OUTPUT
echo "tests-passed=$tests_passed" >> $GITHUB_OUTPUT
echo "tests-total=$tests_total" >> $GITHUB_OUTPUT
- name: Check results
run: |
tests_passed="${{ steps.bats.outputs.tests-passed }}"
tests_total="${{ steps.bats.outputs.tests-total }}"
echo "Passed Bats tests: $tests_passed"
echo "Total Bats tests: $tests_total"
exit_code=1
if [ "$tests_passed" = "$tests_total" ]; then
exit_code=0
fi
exit "$exit_code"
- name: Update Slack notification
uses: codedsolar/slack-action@v1
if: ${{ github.event_name != 'pull_request' && always() }}
with:
fields: |
{STATUS}
{REF}
Passed Bats tests: ${{ steps.bats.outputs.tests-passed || '-' }} / ${{ steps.bats.outputs.tests-total || '-' }}
status: ${{ job.status }}
timestamp: ${{ steps.slack.outputs.slack-timestamp }}