forked from elastic/elastic-charts
-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (130 loc) · 5.92 KB
/
branch_deployment.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
#########################################################################################################
# Handles deployment of key branches to firebase
#
# expected inputs via client_payload
# - sha
# - environment
# - branch_name
#########################################################################################################
name: Branch Deployment
concurrency:
group: '${{ github.workflow }} - ${{ github.event.client_payload.environment }}'
cancel-in-progress: true
env:
NODE_VERSION: '16.13.2' # should match version in .nvmrc
on:
repository_dispatch: # Only triggers workflow from master
types:
- 'Deployment | Branch'
jobs:
# deployment-waiting-check:
# name: Deployment Waiting check
# uses: elastic/elastic-charts/.github/workflows/e2e_waiting.reusable.yml@master
# with:
# sha: ${{ github.event.client_payload.sha }}
# current_run_url: "${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
# environment: "${{ github.event.client_payload.environment }}"
#########################################################################################################
build-deploy:
name: "Deploy | ${{ github.event.client_payload.environment }}"
runs-on: ubuntu-latest
environment:
name: ${{ github.event.client_payload.environment }}
outputs:
# environment_url: https://ech-e2e-ci--alpha-zfvo4b6u.web.app # TODO this
environment_url: ${{ steps.deploy.outputs.details_url }}
steps:
- run: echo "Placeholder"
- name: Checkout & Setup node
uses: nickofthyme/checkout-node-setup@v1
with:
repository: ${{ github.repo }}
ref: ${{ github.event.client_payload.sha }} # github context always points to latest master
# See https://github.com/bahmutov/npm-install/issues/80
skip-npm-install: true # This fails on deployment events
- run: yarn install --frozen-lockfile # TODO: fix caching
#########################################################################################################
- name: Building storybook
working-directory: storybook
run: yarn build:firebase # Outputs build to /e2e_server/public
- name: Generate e2e server files
run: yarn test:e2e:generate
- name: Build e2e server inside storybook output directory
run: yarn test:e2e:server:build -o '../public/e2e' # Outputs build to /e2e_server/public/e2e
#########################################################################################################
- name: Deploy build to firebase
id: deploy
uses: FirebaseExtended/action-hosting-deploy@v0
with:
expires: 14d # this updates for every new deployment
entryPoint: 'e2e_server'
repoToken: '${{ secrets.GITHUB_TOKEN }}'
# New project on elastic's GCP org
# See https://console.cloud.google.com/iam-admin/iam?project=ech-e2e-ci
firebaseServiceAccount: '${{ secrets.FIREBASE_SERVICE_ACCOUNT_ECH_E2E_CI }}'
projectId: 'ech-e2e-ci'
channelId: ${{ github.event.client_payload.branch_name }} # e.g. next, v40.0.0, etc.
- name: Outputs # TODO: remove
shell: python
run: |
print("""${{ toJSON(steps.deploy.outputs) }}""")
#########################################################################################################
cleanup:
name: Cleanup
runs-on: ubuntu-latest
needs: build-deploy
steps:
# Github automatically creates a deployment reference for build-deploy job
# that points to the wrong commit (from master via repository_dispatch).
- name: Update deployment status with environment url
uses: actions/github-script@v5
with:
script: | # This is javascript :)
const { data: [deployment]} = await github.rest.repos.listDeployments({
...context.repo,
task: "deploy",
per_page: 1,
sha: "${{ github.event.client_payload.sha }}",
ref: "${{ github.event.client_payload.branch_name }}",
environment: "${{ github.event.client_payload.environment }}",
});
if (deployment) {
await github.rest.repos.createDeploymentStatus({
...context.repo,
state: 'success',
deployment_id: deployment.id,
log_url: deployment.log_url,
environment_url: "${{ needs.build-deploy.outputs.environment_url }}",
});
}
github-token: ${{ secrets.GITHUB_TOKEN }}
#########################################################################################################
# e2e-tests:
# name: e2e Tests
# uses: elastic/elastic-charts/.github/workflows/e2e_tests.reusable.yml@master
# if: ${{ success() }}
# needs: [build-deploy, cleanup]
# with:
# status_context: Playwright e2e
# sha: ${{ github.event.client_payload.sha }}
# commit_sha: "${{ github.event.client_payload.sha }}"
# current_run_url: "${{ github.event.repository.html_url }}/actions/runs/${{ github.run_id }}"
# environment: "${{ github.event.client_payload.environment }}"
# environment_url: "${{ needs.build-deploy.outputs.environment_url }}"
#########################################################################################################
# failure-check:
# name: Print context on failure
# # if: ${{ failure() }} # TODO this
# if: ${{ always() }}
# needs: [build-deploy, cleanup, e2e-tests]
# runs-on: ubuntu-latest
# steps:
# - name: Print github context
# shell: python
# run: |
# print("""${{ toJSON(github) }}""")
# - name: Print needs context
# shell: python
# run: |
# print("""${{ toJSON(needs) }}""")
#########################################################################################################