-
Notifications
You must be signed in to change notification settings - Fork 1
143 lines (121 loc) · 3.84 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
name: CI
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+*'
pull_request:
branches: ['main']
env:
REGISTRY: demery
IMAGE_NAME: docker-react
NODE_VERSION: 18.18.0
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Configure node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install packages
run: npm ci
- name: Build
run: npm run build
- name: Test
run: npm t
- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: artifacts
path: |
dist
bin
Dockerfile
.dockerignore
nginx.conf
docker-react-entrypoint.sh
.npmignore
package*.json
README.md
publish-npm:
needs: build
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: nowsprinting/check-version-format-action@v3
id: version
with:
prefix: 'v'
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
if: steps.version.outputs.is_valid == 'true'
- name: set package json version
uses: jaywcjlove/github-action-package@main
with:
data: |
{
"version": "${{steps.version.outputs.full_without_prefix}}"
}
if: steps.version.outputs.is_valid == 'true'
- name: Configure node
uses: actions/setup-node@v3
with:
node-version: ${{ env.NODE_VERSION }}
if: steps.version.outputs.is_valid == 'true'
- name: Authenticate with npm
run: echo "//registry.npmjs.org/:_authToken=${{secrets.NPM_TOKEN}}" > ~/.npmrc
if: steps.version.outputs.is_valid == 'true'
- name: Install packages
run: npm ci --omit=dev
if: steps.version.outputs.is_valid == 'true'
- name: Publish to npm (stable channel)
run: npm publish --access public
if: steps.version.outputs.is_valid == 'true' && steps.version.outputs.is_stable == 'true'
- name: Publish to npm (beta channel)
run: npm publish --access public --tag beta
if: steps.version.outputs.is_valid == 'true' && steps.version.outputs.is_stable == 'false'
publish-docker:
needs: publish-npm
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/v')
steps:
- uses: nowsprinting/check-version-format-action@v3
id: version
with:
prefix: 'v'
- name: Download artifacts
uses: actions/download-artifact@v3
with:
name: artifacts
if: steps.version.outputs.is_valid == 'true'
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
if: steps.version.outputs.is_valid == 'true'
- name: Install packages
run: npm ci --omit=dev
if: steps.version.outputs.is_valid == 'true'
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=${{ steps.version.outputs.is_stable == 'true' && 'true' || 'false' }}
if: steps.version.outputs.is_valid == 'true'
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DOCKER_REACT_VERSION=${{ steps.version.outputs.full }}
if: steps.version.outputs.is_valid == 'true'