-
Notifications
You must be signed in to change notification settings - Fork 16
150 lines (128 loc) · 4.91 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
name: Preview
on:
pull_request:
types: [opened, synchronize, reopened, labeled]
branches:
- maintenance-3.1.x
env:
DOCKER_REGISTRY: us-east1-docker.pkg.dev
DOCKER_IMAGE: ${{ secrets.GKE_PROJECT }}/webui/nuxeo-elements/storybook
GKE_CLUSTER: jx-prod
GKE_ZONE: us-east1-b
jobs:
storybook:
name: Storybook
if: (github.event.action == 'labeled' && github.event.label.name == 'preview') || contains(github.event.pull_request.labels.*.name, 'preview')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v3
with:
node-version: 18
registry-url: 'https://packages.nuxeo.com/repository/npm-public/'
scope: '@nuxeo'
- name: Prepare environment
run: |
BRANCH_NAME=${GITHUB_HEAD_REF##*/}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV
echo "VERSION=$(npx -c 'echo "$npm_package_version"')-$BRANCH_NAME" >> $GITHUB_ENV
echo "PREVIEW_NAMESPACE=storybook-$(echo $BRANCH_NAME | sed 's/[^[:alnum:]-]/-/g' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Install
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PACKAGES_TOKEN }}
run: |
npm install --no-package-lock
npm run bootstrap
- name: Run analysis
run: npx lerna run analysis --parallel
- name: Build storybook
working-directory: ./storybook
run: |
npx build-storybook -o dist -s ./public
- name: Build and push image
uses: docker/build-push-action@v1
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: _json_key
password: ${{ secrets.GKE_SA_KEY }}
path: ./storybook
push: true
repository: ${{ env.DOCKER_IMAGE }}
tags: ${{ 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})
# Previous preview deployment needs to be scaled to 0 to be replaced correctly
# - name: Cleanup preview namespace
# if: ${{ steps.preview_ns.outputs.exists }}
# continue-on-error: true
# run: |
# kubectl -n ${PREVIEW_NAMESPACE} scale deployment preview --replicas=0
- name: Create preview namespace
if: ${{ !steps.preview_ns.outputs.exists }}
run: |
kubectl create namespace ${PREVIEW_NAMESPACE}
- name: Install preview
id: preview
working-directory: ./storybook/charts/preview
run: |
# install Helm
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 | bash -
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 .
echo "PREVIEW_URL=https://preview-${PREVIEW_NAMESPACE}.webui.dev.nuxeo.com" >> $GITHUB_ENV
- 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: Storybook preview available [here](${process.env.PREVIEW_URL})`
})
webui-preview:
name: Web UI
runs-on: ubuntu-latest
if: (github.event.action == 'labeled' && github.event.label.name == 'webui-preview') || contains(github.event.pull_request.labels.*.name, 'webui-preview')
steps:
- uses: actions/checkout@v2
- name: Prepare environment
run: |
echo "BRANCH_NAME=${GITHUB_HEAD_REF##*/}" >> $GITHUB_ENV
- name: Web UI preview
id: main
uses: nuxeo/ui-team-gh-actions/trigger-workflow@a5b89f35e0d1f3a912f528d7f1c3acdb73c60549
with:
owner: nuxeo
repo: nuxeo-web-ui
workflow-id: preview.yaml
access-token: ${{ secrets.WEBUI_ACCESS_TOKEN_PERSONAL }}
branch-name: maintenance-3.1.x
inputs: |
branch_name: ${{ env.BRANCH_NAME }}
- uses: actions/[email protected]
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: Web UI preview available [here](${{ steps.main.outputs.message }})`
})