-
Notifications
You must be signed in to change notification settings - Fork 64
74 lines (63 loc) · 2.25 KB
/
deployment.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
name: Deploy to LeanEngine
on:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
required: false
default: 'rnd'
type: 'choice'
options:
- rnd
- prod
targets:
description: 'Targets, e.g `tap,tap-intl,xd,lc`'
required: false
type: 'string'
jobs:
matrix_prep:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
- uses: actions/checkout@v3
- id: set-matrix
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const fs = require('node:fs');
const matrixJson = JSON.parse(fs.readFileSync('./.github/workflows/matrix_includes.json', 'utf-8'));
const env = '${{ inputs.environment }}' || 'rnd';
const targets = '${{ inputs.targets }}'.split(',').filter(Boolean).map((s) => s.trim());
if (env !== 'rnd' && env !== 'prod') {
core.setFailed(`environment: expect 'rnd' or 'prod', found ${env}`);
return;
}
const matrix = (targets?.length
? matrixJson.filter(({ name }) => targets.includes(name))
: matrixJson)
.filter(({ only }) => !only || only === env)
.map((v) => ({ ...v, region: v.region.replace('-', '_'), name: v.name.replace('-', '_') }));
if (!matrix.length) {
core.setFailed('no jobs to do');
return;
}
core.info(`Deploy to ${matrix.map(({ name }) => name).join(', ')} in ${env}`);
core.setOutput(
'matrix',
matrix
);
deployment:
runs-on: ubuntu-latest
needs: matrix_prep
environment: ${{ inputs.environment }}
continue-on-error: true
strategy:
matrix:
include: ${{ fromJson(needs.matrix_prep.outputs.matrix) }}
steps:
- name: trigger webhook
run: |
curl -sS -X POST \
'${{ format('{0}/1.1/engine/groups/{1}/production/version?gitTag={2}&token={3}', vars[format('LEANCLOUD_ENDPOINT_{0}', matrix.region)], matrix.group, matrix.branch, secrets[format('{0}_TOKEN', matrix.name)]) }}' > /dev/null