-
Notifications
You must be signed in to change notification settings - Fork 4
153 lines (128 loc) · 4.55 KB
/
node.js.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
name: Node.js CI
on:
push:
branches: [master]
tags: ['v*']
pull_request:
branches: [master]
# see https://github.community/t/treating-warnings-as-errors-because-process-env-ci-true/18032
env:
CI: false
jobs:
build_and_test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run start &
- name: Wait for the app to start
uses: iFaxity/[email protected]
with:
resource: http://localhost:3000
- name: Run tests
uses: nick-fields/retry@v3
with:
max_attempts: 2
retry_on: error
timeout_seconds: 240
command: npm test
deploy-to-github-registry:
needs: [build_and_test]
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}-web
# when we run this action as depenabot, we need to give it write permissions to the package registry and to the statuses
permissions:
contents: read
packages: write
statuses: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
submodules: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/[email protected]
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# see https://github.com/docker/build-push-action/issues/513#issuecomment-987951050
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# it seems that cache is not giving any benefit in speed, lets keep it disabled for now
# cache-from: type=gha
# cache-to: type=gha,mode=max
build-args: |
BUILDKIT_CONTEXT_KEEP_GIT_DIR=true
DEPLOYMENT=dev
deploy_gh_pages:
runs-on: ubuntu-latest
needs: [build_and_test]
steps:
- name: Checkout 🛎️
uses: actions/checkout@v4
with:
submodules: recursive
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install 🔧
run: npm install
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
cache: 'npm'
- name: webfactory/ssh-agent for dev 🖥️
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
uses: webfactory/[email protected]
with:
# Private SSH key to register in the SSH agent
ssh-private-key: ${{ secrets.WEBDEV }}
- name: Deploy to dev instance 🚀
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
run: |
git remote set-url origin [email protected]:yaptide/web_dev.git
npm run deploy -- -u "github-actions-bot <[email protected]>" -r "[email protected]:yaptide/web_dev.git"
- name: webfactory/ssh-agent for production 🖥️
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
uses: webfactory/[email protected]
with:
# Private SSH key to register in the SSH agent
ssh-private-key: ${{ secrets.WEBPROD }}
- name: Deploy to prod instance 🚀
# this action is being triggered on release tags (named v*)
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/v')
run: |
git remote set-url origin [email protected]:yaptide/yaptide.github.io.git
npm run deploy -- -u "github-actions-bot <[email protected]>" -r "[email protected]:yaptide/yaptide.github.io.git"