77 # -- TESTS ------------------------------------------------------------------
88 tests :
99 runs-on : ubuntu-latest
10-
10+
1111 strategy :
1212 matrix :
13- node-version : [12.x]
13+ node : ['16']
14+ mongodb : ['5.0']
1415
1516 steps :
1617 - name : Checkout
17- uses : actions/checkout@v2
18+ uses : actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
1819
19- - name : Use Node.js ${{ matrix.node-version }}
20- uses : actions/setup-node@v1
20+ - name : Setup Node.js ${{ matrix.node }}
21+ uses : actions/setup-node@56337c425554a6be30cdef71bf441f15be286854 # tag=v3
2122 with :
22- node-version : ${{ matrix.node-version }}
23+ node-version : ${{ matrix.node }}
24+ check-latest : true
2325
2426 - name : Install dependencies
2527 run : npm install
2628
29+ - name : Start MongoDB
30+ uses : supercharge/mongodb-github-action@e815fd8a9dfede09fd6e6c144f2c9f4875e933df # tag=1.7.0
31+ with :
32+ mongodb-version : ${{ matrix.mongodb }}
33+ mongodb-db : encryptionAPI
34+
2735 - name : Run Unit-Tests + Code Coverage
2836 run : npm run test:coverage
2937
3038 - name : Save Code Coverage
31- uses : actions/upload-artifact@v2
39+ uses : actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
3240 with :
3341 name : code-coverage
3442 path : coverage
3543
36- sonarcloud :
44+ # -- SONARCLOUD -------------------------------------------------------------
45+ code-quality :
3746 runs-on : ubuntu-latest
3847 needs : tests
3948
4049 steps :
4150 - name : Checkout
42- uses : actions/checkout@v2
43-
51+ uses : actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
52+
4453 - name : Download Code Coverage
45- uses : actions/download-artifact@v2
54+ uses : actions/download-artifact@fb598a63ae348fa914e94cd0ff38f362e927b741 # tag=v3.0.0
4655 with :
4756 name : code-coverage
4857 path : coverage
6675
6776 # - name: Build docker image
6877 # run: docker build -t timoa/nodejs-encryption-api-example .
69-
78+
7079 # - name: Start Docker container
7180 # run: docker-compose up -d
7281
@@ -78,25 +87,92 @@ jobs:
7887
7988 # - name: Run Functional tests
8089 # run: npm run test:functional
81-
90+
8291 # - name: Stop Docker container
8392 # run: docker-compose down
8493
94+ # -- SAST SCAN --------------------------------------------------------------
95+ code-security :
96+ runs-on : ubuntu-latest
97+ needs : tests
98+ # Skip any PR created by dependabot to avoid permission issues
99+ if : (github.actor != 'dependabot[bot]')
100+
101+ steps :
102+ - name : Checkout
103+ uses : actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 # tag=v3
104+
105+ - name : Perform Scan
106+ uses : ShiftLeftSecurity/scan-action@master
107+
108+ env :
109+ WORKSPACE : https://github.com/${{ github.repository }}/blob/${{ github.sha }}
110+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
111+ SCAN_ANNOTATE_PR : true
112+
113+ - uses : actions/upload-artifact@6673cd052c4cd6fcf4b4e6e60ea986c889389535 # tag=v3.0.0
114+ with :
115+ name : reports
116+ path : reports
117+
118+ # -- RELEASE ----------------------------------------------------------------
119+ release :
120+ runs-on : ubuntu-latest
121+ needs :
122+ - code-quality
123+ - code-security
124+ if : github.ref == 'refs/heads/master'
125+
126+ steps :
127+ - name : Checkout
128+ uses : actions/checkout@dcd71f646680f2efd8db4afa5ad64fdcba30e748 # tag=v3
129+
130+ - name : Semantic Release
131+ uses : cycjimmy/semantic-release-action@v3
132+ env :
133+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
134+
85135 # -- BUILD ------------------------------------------------------------------
86136 build :
87137 runs-on : ubuntu-latest
88- needs : tests
138+ needs : release
89139 if : github.ref == 'refs/heads/master'
90140
91141 steps :
92142 - name : Checkout
93- uses : actions/checkout@v2
143+ uses : actions/checkout@a12a3943b4bdde767164f792f33f40b04645d846 # tag=v3.0.0
94144
95- - name : Docker Build
96- uses : docker/build-push-action@v1
145+ - name : Docker meta
146+ id : meta
147+ uses : docker/metadata-action@e5622373a38e60fb6d795a4421e56882f2d7a681 # tag=v3.6.2
148+ with :
149+ images : ${{ github.repository }}
150+ tags : |
151+ type=schedule
152+ type=ref,event=branch
153+ type=ref,event=pr
154+ type=semver,pattern={{version}}
155+ type=semver,pattern={{major}}.{{minor}}
156+ type=semver,pattern={{major}}
157+ type=sha
158+ type=raw,value=latest
159+
160+ - name : Set up QEMU
161+ uses : docker/setup-qemu-action@27d0a4f181a40b142cce983c5393082c365d1480 # tag=v1.2.0
162+
163+ - name : Set up Docker Buildx
164+ uses : docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25 # tag=v1.6.0
165+
166+ - name : Login to DockerHub
167+ uses : docker/login-action@dd4fa0671be5250ee6f50aedf4cb05514abda2c7 # tag=v1.14.1
97168 with :
98169 username : ${{ secrets.DOCKER_USERNAME }}
99170 password : ${{ secrets.DOCKER_PASSWORD }}
100- repository : timoa/nodejs-encryption-api-example
101- tags : latest
102171
172+ - name : Build and push
173+ uses : docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a # tag=v2.10.0
174+ with :
175+ context : .
176+ push : true
177+ tags : ${{ steps.meta.outputs.tags }}
178+ labels : ${{ steps.meta.outputs.labels }}
0 commit comments