@@ -10,32 +10,12 @@ on: # yamllint disable-line rule:truthy
10
10
11
11
env :
12
12
IMAGE_NAME : algorithm-exercises-js
13
+ ARTIFACT_NAME : algorithm-exercises-js_${{ github.sha }}
13
14
14
15
jobs :
15
- security :
16
- name : " Snyk Container"
17
- runs-on : ubuntu-latest
18
- steps :
19
- - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
20
-
21
- - name : Run Snyk to check Docker image for vulnerabilities
22
- # Snyk can be used to break the build when it detects vulnerabilities.
23
- # In this case we want to upload the issues to GitHub Code Scanning
24
- continue-on-error : true
25
- uses : snyk/actions/docker@master
26
- env :
27
- # yamllint disable rule:line-length
28
- # In order to use the Snyk Action you will need to have a Snyk API token.
29
- # See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token
30
- # or you can sign up for free at https://snyk.io/login
31
- # yamllint enable rule:line-length
32
- SNYK_TOKEN : ${{ secrets.SNYK_TOKEN }}
33
- with :
34
- image : ${{ env.IMAGE_NAME }}:${{ github.sha }}
35
- args : --file=Dockerfile
36
16
37
17
build :
38
- name : " Build & Test in Docker"
18
+ name : " Build Docker images "
39
19
runs-on : ubuntu-latest
40
20
steps :
41
21
- uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
@@ -60,45 +40,45 @@ jobs:
60
40
context : .
61
41
target : lint
62
42
outputs : |
63
- type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_lint.tar
43
+ type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_lint.tar
64
44
tags : |
65
45
${{ env.IMAGE_NAME }}:lint
66
46
- name : " LINT: Upload artifact"
67
47
uses : actions/upload-artifact@v4
68
48
with :
69
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_lint
70
- path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_lint.tar
49
+ name : ${{ env.ARTIFACT_NAME }}_lint
50
+ path : /tmp/${{ env.ARTIFACT_NAME }}_lint.tar
71
51
72
52
- name : " TEST: Build and push"
73
53
uses : docker/build-push-action@v6
74
54
with :
75
55
context : .
76
56
target : testing
77
57
outputs : |
78
- type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_test.tar
58
+ type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_test.tar
79
59
tags : |
80
60
${{ env.IMAGE_NAME }}:test
81
61
- name : " TEST: Upload artifact"
82
62
uses : actions/upload-artifact@v4
83
63
with :
84
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_test
85
- path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_test.tar
64
+ name : ${{ env.ARTIFACT_NAME }}_test
65
+ path : /tmp/${{ env.ARTIFACT_NAME }}_test.tar
86
66
87
67
- name : " PRODUCTION: Build and push"
88
68
uses : docker/build-push-action@v6
89
69
with :
90
70
context : .
91
71
target : production
92
72
outputs : |
93
- type=docker,dest=/tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
73
+ type=docker,dest=/tmp/${{ env.ARTIFACT_NAME }}_prod.tar
94
74
tags : |
95
75
${{ env.IMAGE_NAME }}:latest
96
76
${{ env.IMAGE_NAME }}:${{ github.sha }}
97
77
- name : " PRODUCTION: Upload artifact"
98
78
uses : actions/upload-artifact@v4
99
79
with :
100
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
101
- path : /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
80
+ name : ${{ env.ARTIFACT_NAME }}_prod
81
+ path : /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
102
82
103
83
lint :
104
84
name : " Run in docker: LINT"
@@ -108,17 +88,70 @@ jobs:
108
88
- name : Download artifact
109
89
uses : actions/download-artifact@v4
110
90
with :
111
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
91
+ name : ${{ env.ARTIFACT_NAME }}_lint
112
92
path : /tmp/
113
93
114
94
- name : Load image
115
95
run : |
116
- docker load --input /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod .tar
96
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_lint .tar
117
97
docker image ls -a
118
98
119
99
- name : Run lint
120
100
run : |
121
- make compose/lint
101
+ docker run --rm ${{ env.IMAGE_NAME }}:lint make lint
102
+
103
+ test :
104
+ name : " Run in docker: TEST"
105
+ runs-on : ubuntu-latest
106
+ needs : build
107
+ steps :
108
+ - name : Download artifact
109
+ uses : actions/download-artifact@v4
110
+ with :
111
+ name : ${{ env.ARTIFACT_NAME }}_test
112
+ path : /tmp/
113
+
114
+ - name : Load image
115
+ run : |
116
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_test.tar
117
+ docker image ls -a
118
+
119
+ - name : Run lint
120
+ run : |
121
+ docker run --rm ${{ env.IMAGE_NAME }}:test make test
122
+
123
+ security :
124
+ name : " Snyk Container"
125
+ runs-on : ubuntu-latest
126
+ needs : build
127
+ steps :
128
+ - uses : actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
129
+ - name : Download artifact
130
+ uses : actions/download-artifact@v4
131
+ with :
132
+ name : ${{ env.ARTIFACT_NAME }}_prod
133
+ path : /tmp/
134
+
135
+ - name : Load image
136
+ run : |
137
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
138
+ docker image ls -a
139
+
140
+ - name : Run Snyk to check Docker image for vulnerabilities
141
+ # Snyk can be used to break the build when it detects vulnerabilities.
142
+ # In this case we want to upload the issues to GitHub Code Scanning
143
+ continue-on-error : true
144
+ uses : snyk/actions/docker@master
145
+ env :
146
+ # yamllint disable rule:line-length
147
+ # In order to use the Snyk Action you will need to have a Snyk API token.
148
+ # See https://docs.snyk.io/integrations/ci-cd-integrations/github-actions-integration#getting-your-snyk-token
149
+ # or you can sign up for free at https://snyk.io/login
150
+ # yamllint enable rule:line-length
151
+ SNYK_TOKEN : ${{ secrets.SNYK_TOKEN }}
152
+ with :
153
+ image : ${{ env.IMAGE_NAME }}:${{ github.sha }}
154
+ args : --file=Dockerfile
122
155
123
156
scan :
124
157
name : " Trivy"
@@ -128,12 +161,12 @@ jobs:
128
161
- name : Download artifact
129
162
uses : actions/download-artifact@v4
130
163
with :
131
- name : ${{ env.IMAGE_NAME }}_${{ github.sha }}_prod
164
+ name : ${{ env.ARTIFACT_NAME }}_prod
132
165
path : /tmp/
133
166
134
167
- name : Load image
135
168
run : |
136
- docker load --input /tmp/${{ env.IMAGE_NAME }}_${{ github.sha }}_prod.tar
169
+ docker load --input /tmp/${{ env.ARTIFACT_NAME }}_prod.tar
137
170
docker image ls -a
138
171
139
172
- name : Run Trivy vulnerability scanner
0 commit comments