-
Notifications
You must be signed in to change notification settings - Fork 11
161 lines (138 loc) · 4.87 KB
/
test-release-publish.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
156
157
158
159
160
161
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Timings CI - release
on:
push:
workflow_dispatch:
inputs:
force-docker:
description: 'Force publish docker image'
default: false
type: boolean
defaults:
run:
shell: bash
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
permissions:
contents: read # for checkout
jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [20.12.x, 21.x, 22.x]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install node modules and run tests
run: |
npm ci --ignore-scripts
npm test
semantic-release:
runs-on: ubuntu-latest
needs: test
if: github.ref_name == 'main' && needs.test.result == 'success'
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
outputs:
last_release_version: ${{ steps.release.outputs.last_release_version }}
new_release_version: ${{ steps.release.outputs.new_release_version }}
new_release_published: ${{ steps.release.outputs.new_release_published }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Print info
run: |
# Echo the version from package.json
echo "Current package version: [$(jq -r .version package.json)]"
echo "Env: ${{ toJSON(env) }}"
- name: Setup NodeJS 21
uses: actions/setup-node@v4
with:
node-version: 21
cache: 'npm'
- name: NPM install
run: |
npm ci --ignore-scripts
- name: Semantic Release [PUBLISH]
id: release
uses: ./.github/actions/semantic
publish-docker:
runs-on: ubuntu-latest
needs: semantic-release
if: github.ref_name == 'main' && (needs.semantic-release.outputs.new_release_published == 'true' || github.event.inputs.force-docker == true)
outputs:
docker_imageid: ${{ steps.docker_build.outputs.imageid }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Print npm package info
run: |
# Echo the version from package.json
echo "Current package version: [$(jq -r .version package.json)]"
- name: Setup NodeJS 21
uses: actions/setup-node@v4
with:
node-version: 21
- name: NPM install
run: |
npm ci --ignore-scripts
- name: Install Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Docker Build and Push
id: docker_build
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
godaddy/timings:latest
godaddy/timings:${{ needs.semantic-release.outputs.new_release_version }}
cache-from: type=gha
cache-to: type=gha,mode=max
finish:
runs-on: ubuntu-latest
needs: [semantic-release, publish-docker]
steps:
- name: Print info
run: |
echo "needs.semantic-release: ${{ toJSON(needs.semantic-release) }}"
- name: Report
run: |
if [ '${{ needs.semantic-release.outputs.new_release_published }}' == 'true' ]; then
echo - A new release was published! >> $GITHUB_STEP_SUMMARY
echo - Last Release: **${{ needs.semantic-release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
echo - New Release: **${{ needs.semantic-release.outputs.new_release_version }}** >> $GITHUB_STEP_SUMMARY
else
echo - No new Release! The current release is: **${{ needs.semantic-release.outputs.last_release_version }}** >> $GITHUB_STEP_SUMMARY
fi
if [ '${{ needs.publish-docker.result }}' == 'success' ]; then
echo - Docker image was published! >> $GITHUB_STEP_SUMMARY
echo - Image ID: **${{ needs.publish-docker.outputs.docker_imageid }}** >> $GITHUB_STEP_SUMMARY
else
echo - Docker image was not published! >> $GITHUB_STEP_SUMMARY
fi