-
Notifications
You must be signed in to change notification settings - Fork 61
197 lines (168 loc) · 6.47 KB
/
preview.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
name: Preview
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
branches:
- lts-2025
workflow_dispatch:
inputs:
branch_name:
description: 'The name of the branch to preview.'
default: 'lts-2025'
required: true
caller_id:
description: 'run identifier'
default: 'lts-2025'
type: string
required: false
env:
DOCKER_REGISTRY: us-east1-docker.pkg.dev
DOCKER_IMAGE: ${{ secrets.GKE_PROJECT }}/webui/nuxeo-web-ui
GKE_CLUSTER: jx-prod
GKE_ZONE: us-east1-b
jobs:
id:
name: Remote Caller ID ${{ github.event.inputs.caller_id }}
runs-on: ubuntu-latest
steps:
- name: ${{ github.event.inputs.id }}
run: echo run identifier ${{ github.event.inputs.id }}
preview:
needs: id
name: Setup
outputs:
url: ${{ steps.preview.outputs.url }}
if: (github.event.action == 'labeled' && github.event.label.name == 'preview') || contains(github.event.pull_request.labels.*.name, 'preview') || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://packages.nuxeo.com/repository/npm-public/'
scope: '@nuxeo'
- name: Setup branch name (pull_request)
if: github.event_name == 'pull_request'
run: |
BRANCH_NAME=${GITHUB_HEAD_REF##*/}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Setup branch name (workflow_dispatch)
if: github.event_name == 'workflow_dispatch'
run: |
BRANCH_NAME=${{ github.event.inputs.branch_name }}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
- name: Determine nuxeo-web-ui branch to use
uses: nuxeo/ui-team-gh-actions/get-branch@ca09d5c52a62e297502d3572c36d813be927982a
id: pick_nuxeo_web_ui_branch
with:
repository: nuxeo/nuxeo-web-ui
branch: ${BRANCH_NAME}
default-branch: lts-2025
- uses: actions/checkout@v3
with:
ref: ${{ steps.pick_nuxeo_web_ui_branch.outputs.branch }}
- name: Prepare environment
run: |
echo "VERSION=$(npx -c 'echo "$npm_package_version"')-$BRANCH_NAME" >> $GITHUB_ENV
echo "PREVIEW_NAMESPACE=$(printf '%.53s' $(echo nuxeo-web-ui-$(echo $BRANCH_NAME | sed 's/[^[:alnum:]-]/-/g' | tr '[:upper:]' '[:lower:]')))" >> $GITHUB_ENV
- name: Determine nuxeo-elements branch to use
id: pick_nuxeo_elements_branch
uses: nuxeo/ui-team-gh-actions/get-branch@ca09d5c52a62e297502d3572c36d813be927982a
with:
repository: nuxeo/nuxeo-elements
branch: ${BRANCH_NAME}
default-branch: lts-2025
- name: Checkout the nuxeo-elements repo
uses: actions/checkout@v2
with:
repository: nuxeo/nuxeo-elements
path: nuxeo-elements
fetch-depth: 1
ref: ${{ steps.pick_nuxeo_elements_branch.outputs.branch }}
- name: Install
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
run: |
npm install nuxeo-elements/core
npm install nuxeo-elements/ui
npm install nuxeo-elements/dataviz
npm install
- name: Webpack build
run: |
npm run build
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: _json_key
password: ${{ secrets.GKE_SA_KEY }}
- name: Build and push server image
uses: docker/build-push-action@v2
with:
context: server
pull: true
push: true
file: server/Dockerfile
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}/server:${{ env.VERSION }}
- name: Build and push image
uses: docker/build-push-action@v2
with:
context: .
pull: true
push: true
file: Dockerfile
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}:${{ env.VERSION }}
build-args: SERVER_IMAGE=${{ env.DOCKER_REGISTRY }}/${{ env.DOCKER_IMAGE }}/server:${{ env.VERSION }}
- name: Get GKE credentials
uses: google-github-actions/[email protected]
with:
cluster_name: ${{ env.GKE_CLUSTER }}
location: ${{ env.GKE_ZONE }}
project_id: ${{ secrets.GKE_PROJECT }}
credentials: ${{ secrets.GKE_SA_KEY }}
- name: Check preview namespace
id: preview_ns
run: |
echo ::set-output name=exists::$(kubectl get namespace ${PREVIEW_NAMESPACE})
- name: Create preview namespace
if: ${{ !steps.preview_ns.outputs.exists }}
run: |
kubectl create namespace ${PREVIEW_NAMESPACE}
- name: Install preview
id: preview
working-directory: ./charts/preview
run: |
# add helm jx repo
helm repo add jx https://jenkins-x-charts.github.io/v2/
# substitute env variables in values.yaml
mv values.yaml values.yaml.tosubst
envsubst < values.yaml.tosubst > values.yaml
# update helm deps
helm dependency update .
# install
helm upgrade --install --namespace ${PREVIEW_NAMESPACE} ${PREVIEW_NAMESPACE} .
# ensure the deployment is restarted to pull the new preview image
kubectl rollout restart deployment ${PREVIEW_NAMESPACE}-preview --namespace ${PREVIEW_NAMESPACE}
echo "PREVIEW_URL=https://preview-${PREVIEW_NAMESPACE}.webui.dev.nuxeo.com" >> $GITHUB_ENV
echo ::set-output name=url::"https://preview-${PREVIEW_NAMESPACE}.webui.dev.nuxeo.com"
- uses: actions/[email protected]
if: github.event_name == 'pull_request'
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `:star: PR built and available [here](${process.env.PREVIEW_URL})`
})
result:
name: "Result: ${{ needs.preview.outputs.url }}"
needs: preview
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'
steps:
- name: "Result: ${{ needs.preview.outputs.url }}"
run: |
echo ${{ needs.preview.outputs.url }}