forked from KusionStack/konfig
-
Notifications
You must be signed in to change notification settings - Fork 0
142 lines (119 loc) · 4.96 KB
/
apply.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
name: Deploy Apps with Specified Workspace
on:
workflow_dispatch:
inputs:
workspace:
required: true
type: choice
description: The specified Workspace to apply
options:
- default
- remote-test
project-stack-paths:
required: true
description: The paths of the Project and Stack in the repository to apply
jobs:
preview:
runs-on: ubuntu-20.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Kusion
run: curl https://www.kusionstack.io/scripts/install.sh | sh -s 0.12.1-rc.2
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install Pytest Html
run: python3 -m pip install pytest-html pyyaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
- name: Setup K3d&K3s
uses: nolar/setup-k3d-k3s@v1
with:
version: v1.25.15+k3s1
- name: Preview
id: preview
env:
WORKSPACE_NAME: ${{ github.event.inputs.workspace }}
CHANGED_STACKS: ${{ github.event.inputs.project-stack-paths }}
OSS_ACCESS_KEY_ID: ${{ secrets.OSS_ACCESS_KEY_ID }}
OSS_ACCESS_KEY_SECRET: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
WORKSPACE_FILE_DIR: workspaces
run: |
# manually source kusion env file
source "$HOME/.kusion/.env"
# setup remote backend for kusion cli
kusion config set backends.oss_test '{"type":"oss","configs":{"bucket":"kusion-test","endpoint":"oss-cn-shanghai.aliyuncs.com"}}'
kusion config set backends.current oss_test
# switch to the specified workspace
kusion workspace switch $WORKSPACE_NAME
# execute python script for previewing
python3 hack/preview_changed_stacks.py
- name: Upload Report
id: upload-report
if: ${{ steps.preview.outputs.preview_success == 'true' }}
uses: actions/upload-artifact@v4
with:
name: preview-report
path: hack/report/preview-result.zip
- name: Echo Preview Report URL
if: ${{ steps.preview.outputs.preview_success == 'true' }}
run: |
echo "Please check the preview result at: ${{ steps.upload-report.outputs.artifact-url }}"
- name: Approve Preview
if: ${{ steps.preview.outputs.preview_success == 'true' }}
uses: trstringer/manual-approval@v1
with:
secret: ${{ secrets.PACKAGE_TOKEN }}
approvers: "liu-hm19"
minimum-approvals: 1
issue-title: "[Preview] Deploying ${{ github.event.inputs.project-stack-paths }}"
issue-body: "Please check the preview report at: ${{ steps.upload-report.outputs.artifact-url }}"
apply:
needs: [ preview ]
runs-on: ubuntu-20.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install Kusion
run: curl https://www.kusionstack.io/scripts/install.sh | sh -s 0.12.1-rc.2
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.9
- name: Install Pytest Html
run: python3 -m pip install pytest-html pyyaml -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
- name: Setup K3d&K3s
uses: nolar/setup-k3d-k3s@v1
- name: Apply
id: apply
env:
WORKSPACE_NAME: ${{ github.event.inputs.workspace }}
CHANGED_STACKS: ${{ github.event.inputs.project-stack-paths }}
OSS_ACCESS_KEY_ID: ${{ secrets.OSS_ACCESS_KEY_ID }}
OSS_ACCESS_KEY_SECRET: ${{ secrets.OSS_ACCESS_KEY_SECRET }}
WORKSPACE_FILE_DIR: workspaces
run: |
# manually source kusion env file
source "$HOME/.kusion/.env"
# setup remote backend for kusion cli
kusion config set backends.oss_test '{"type":"oss","configs":{"bucket":"kusion-test","endpoint":"oss-cn-shanghai.aliyuncs.com"}}'
kusion config set backends.current oss_test
# switch to the specified workspace
kusion workspace switch $WORKSPACE_NAME
# execute python script for previewing
python3 hack/apply_changed_stacks.py
- name: Upload Report
id: upload-report
if: ${{ steps.apply.outputs.apply_success == 'true' }}
uses: actions/upload-artifact@v4
with:
name: apply-report
path: hack/report/apply-result.zip
- name: Echo Apply Report URL
if: ${{ steps.apply.outputs.apply_success == 'true' }}
run: |
echo "Please check the apply result at: ${{ steps.upload-report.outputs.artifact-url }}"