-
Notifications
You must be signed in to change notification settings - Fork 0
166 lines (134 loc) · 5.31 KB
/
build-release-push-deploy.yaml
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
162
163
164
165
166
# This workflow will do a clean installation of node dependencies, cache/restore them, 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: 🔄 Build, release, push and deploy
on:
push:
branches: ["main", "beta", "*.*.*"]
pull_request:
branches: ["main", "beta", "*.*.*"]
# Used by the GitHub merge queue feature.
# Documentation: https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/configuring-pull-request-merges/managing-a-merge-queue
merge_group:
env:
NAMESPACE_NAME: "docs"
IMAGE_NAME: "docs"
jobs:
build:
name: ⚙️ Build
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x, current]
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: 🌐 Use Node.js [${{ matrix.node-version }}]
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: 🗂 Cache "node_modules"
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.arch }}-${{ runner.os }}-yarn-
- name: 📦 Install dependencies
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile
- name: ⚙️ Build application
run: yarn run build
- if: steps.yarn-cache.outputs.cache-hit != 'true'
name: 🗃 List the state of node modules
continue-on-error: true
run: yarn list
release:
name: 🔖 Release
runs-on: ubuntu-latest
needs: build
if: ${{ github.event_name != 'merge_group' }} # skip this job if the event is a merge_group
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
with:
# used by semantic-release to bypass the branch protection rules
token: ${{ secrets.GH_TOKEN }}
- name: 🌐 Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
- name: 🗂 Cache "node_modules"
uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: "**/node_modules"
key: ${{ runner.arch }}-${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.arch }}-${{ runner.os }}-yarn-
- name: 🔖 Release application
run: yarn run semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
id: version # save the version to use in an other step/job
outputs:
version: ${{ steps.version.outputs.nextVersion }}
push:
name: 🐳 Build and push image
runs-on: ubuntu-latest
needs: release
steps:
- name: 📥 Checkout repository
uses: actions/checkout@v4
- name: ⚙️ Set up QEMU
uses: docker/setup-qemu-action@v3
- name: 🛠 Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: 📲 Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: 🐳 Build and push image [latest]
uses: docker/build-push-action@v5
with:
context: . # https://github.com/marketplace/actions/build-and-push-docker-images#git-context
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
- name: 🐳 Build and push image [${{ needs.release.outputs.version }}]
uses: docker/build-push-action@v5
if: ${{ needs.release.outputs.version }} # deploy only if there is a new published version
with:
context: . # https://github.com/marketplace/actions/build-and-push-docker-images#git-context
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ needs.release.outputs.version }}
deploy-pre-production:
name: 🚀 Deploy
if: ${{ github.actor != 'dependabot[bot]' }} && ${{ github.event_name != 'merge_group' }}
needs: [push, release]
uses: ./.github/workflows/reusable-kubernetes-deploy.yaml
with:
environment: pre-production
namespace: docs
deployment: docs-prep
image: docs
tag: ${{ needs.release.outputs.version || 'latest' }}
secrets:
kubeconfig: ${{ secrets.OCI_KUBE_CONFIG }}
registry_username: ${{ secrets.DOCKERHUB_USERNAME }}
deploy-production:
name: 🚀 Deploy
if: ${{ github.event_name != 'pull_request' }}
needs: [push, release]
uses: ./.github/workflows/reusable-kubernetes-deploy.yaml
with:
environment: production
namespace: docs
deployment: docs-prod
image: docs
tag: ${{ needs.release.outputs.version || 'latest' }}
secrets:
kubeconfig: ${{ secrets.OCI_KUBE_CONFIG }}
registry_username: ${{ secrets.DOCKERHUB_USERNAME }}