12
12
default : false
13
13
type : boolean
14
14
15
+ defaults :
16
+ run :
17
+ shell : bash
18
+
19
+ env :
20
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
21
+ NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
22
+
23
+ permissions :
24
+ contents : read # for checkout
25
+
15
26
jobs :
16
27
test :
17
28
runs-on : ubuntu-latest
22
33
steps :
23
34
- name : Checkout
24
35
uses : actions/checkout@v4
36
+ with :
37
+ fetch-depth : 0
38
+ persist-credentials : false
25
39
26
40
- name : Setup Node.js ${{ matrix.node-version }}
27
41
uses : actions/setup-node@v4
@@ -33,66 +47,75 @@ jobs:
33
47
npm ci --ignore-scripts
34
48
npm test
35
49
36
- release :
50
+ semantic- release :
37
51
runs-on : ubuntu-latest
38
52
needs : test
39
- if : github.ref == 'refs/heads/main' && needs.test.result == 'success'
53
+ if : github.ref_name == 'main' && needs.test.result == 'success'
54
+ permissions :
55
+ contents : write # to be able to publish a GitHub release
56
+ issues : write # to be able to comment on released issues
57
+ pull-requests : write # to be able to comment on released pull requests
58
+ id-token : write # to enable use of OIDC for npm provenance
40
59
outputs :
41
60
last_release_version : ${{ steps.release.outputs.last_release_version }}
42
61
new_release_version : ${{ steps.release.outputs.new_release_version }}
43
62
new_release_published : ${{ steps.release.outputs.new_release_published }}
44
63
steps :
45
64
- name : Checkout
46
65
uses : actions/checkout@v4
66
+ with :
67
+ fetch-depth : 0
68
+ persist-credentials : false
47
69
48
- - name : Setup Node.js
70
+ - name : Print info
71
+ run : |
72
+ # Echo the version from package.json
73
+ echo "Current package version: [$(jq -r .version package.json)]"
74
+
75
+ - name : Setup NodeJS 21
49
76
uses : actions/setup-node@v4
50
77
with :
51
78
node-version : 21
52
79
cache : ' npm'
53
80
54
- - name : Install node modules and run tests
81
+ - name : NPM install
55
82
run : |
56
83
npm ci --ignore-scripts
57
84
58
85
- name : Semantic Release [PUBLISH]
59
- uses : ./.github/actions/semantic
60
86
id : release
61
- env :
62
- GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
63
- NPM_TOKEN : ${{ secrets.NPM_TOKEN }}
64
- with :
65
- publish : true
87
+ uses : ./.github/actions/semantic
66
88
67
- deploy :
89
+ publish-docker :
68
90
runs-on : ubuntu-latest
69
- needs : release
70
- if : github.ref == 'refs/heads/main' && (needs.release.outputs.new_release_published == 'true' || github.event.inputs.force-docker == true)
91
+ needs : semantic-release
92
+ if : github.ref_name == 'main' && (needs.semantic-release.outputs.new_release_published == 'true' || github.event.inputs.force-docker == true)
93
+ outputs :
94
+ docker_imageid : ${{ steps.docker_build.outputs.imageid }}
71
95
steps :
72
96
- name : Checkout
73
97
uses : actions/checkout@v4
98
+ with :
99
+ fetch-depth : 0
100
+ persist-credentials : false
101
+
102
+ - name : Print npm package info
103
+ run : |
104
+ # Echo the version from package.json
105
+ echo "Current package version: [$(jq -r .version package.json)]"
74
106
75
- - name : Setup Node.js
107
+ - name : Setup NodeJS 21
76
108
uses : actions/setup-node@v4
77
109
with :
78
110
node-version : 21
79
111
80
- - name : Install node modules and run tests
112
+ - name : NPM install
81
113
run : |
82
114
npm ci --ignore-scripts
83
115
84
- - name : Set up Docker Buildx
85
- id : buildx
116
+ - name : Install Docker Buildx
86
117
uses : docker/setup-buildx-action@v3
87
118
88
- - name : Cache Docker layers
89
- uses : actions/cache@v4
90
- with :
91
- path : /tmp/.buildx-cache
92
- key : ${{ runner.os }}-buildx-${{ github.sha }}
93
- restore-keys : |
94
- ${{ runner.os }}-buildx-
95
-
96
119
- name : Login to Docker Hub
97
120
uses : docker/login-action@v3
98
121
with :
@@ -103,15 +126,35 @@ jobs:
103
126
id : docker_build
104
127
uses : docker/build-push-action@v5
105
128
with :
106
- builder : ${{ steps.buildx.outputs.name }}
129
+ context : .
107
130
push : true
108
131
tags : |
109
132
godaddy/timings:latest
110
- godaddy/timings:${{ needs.release.outputs.new_release_version }}
111
- cache-from : type=local,src=/tmp/.buildx-cache
112
- cache-to : type=local,dest=/tmp/.buildx-cache
133
+ godaddy/timings:${{ needs.semantic- release.outputs.new_release_version }}
134
+ cache-from : type=registry,ref=user/app:buildcache
135
+ cache-to : type=registry,ref=user/app:buildcache,mode=max
113
136
114
- - name : Image digest
115
- run : |
116
- echo Docker image was published sucessfully! >> $GITHUB_STEP_SUMMARY
117
- echo - Image ID: **${{ steps.docker_build.outputs.imageid }}** >> $GITHUB_STEP_SUMMARY
137
+ finish :
138
+ runs-on : ubuntu-latest
139
+ needs : [semantic-release, publish-docker]
140
+ steps :
141
+ - name : Print info
142
+ run : |
143
+ echo "needs.semantic-release: ${{ toJSON(needs.semantic-release) }}"
144
+
145
+ - name : Report
146
+ run : |
147
+ if [ '${{ needs.semantic-release.outputs.new_release_published }}' == 'true' ]; then
148
+ echo - A new release was published! >> $GITHUB_STEP_SUMMARY
149
+ echo - Last Release: **${{ needs.semantic-release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
150
+ echo - New Release: **${{ needs.semantic-release.outputs.new_release_version }}** >> $GITHUB_STEP_SUMMARY
151
+ else
152
+ echo - No new Release! The current release is: **${{ needs.semantic-release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
153
+ fi
154
+ if [ '${{ needs.publish-docker.result }}' == 'success' ]; then
155
+ echo - Docker image was published! >> $GITHUB_STEP_SUMMARY
156
+ echo - Image ID: **${{ needs.publish-docker.outputs.docker_imageid }}** >> $GITHUB_STEP_SUMMARY
157
+ else
158
+ echo - Docker image was not published! >> $GITHUB_STEP_SUMMARY
159
+ fi
160
+
0 commit comments