-
Notifications
You must be signed in to change notification settings - Fork 19
187 lines (162 loc) · 6.44 KB
/
build.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
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
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Build CI
on:
push:
paths:
- '**'
pull_request:
branches:
- main
workflow_dispatch:
inputs:
ref:
description: "Why trigger?"
required: true
type: string
env:
IMAGE: "docs"
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version:
- 12.x
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install pnpm
run: npm install -g pnpm@6
- name: Get pnpm store directory
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
key: docs-${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
docs-${{ runner.os }}-pnpm-store-
- name: Get current branch
id: get_branch
run: |
if [ "$GITHUB_EVENT_NAME" == "push" ]; then
echo "BRANCH=${GITHUB_REF##*/}" >> $GITHUB_ENV
elif [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then
echo "BRANCH=$GITHUB_HEAD_REF" >> $GITHUB_ENV
fi
- name: Node build
shell: bash
run: |
pnpm install gray-matter json2yaml
node addTime.js
node addTime.js ./translate/translated
node copy-file.js ./docs/zh ./translate/translated false
rm -rf translate/translated/README.md
mv translate/translated/* ./docs
rm -rf ./docs/map.txt
pnpm install
node downloadFile.js ${{ env.BRANCH }}
node downloadCSV.js ${{ env.BRANCH }}
pnpm run build
node copy-file.js
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Log in to ALIYUN Docker Registry
if: ${{ github.repository == 'deepflowio/docs'}}
uses: docker/login-action@v2
with:
registry: "${{ secrets.REGISTRY_ALIYUN_ADDR }}"
username: "${{ secrets.REGISTRY_ALIYUN_USER }}"
password: "${{ secrets.ALIYUN_DF_CLOUD_REGISTRY_PASSWORD }}"
# - name: debug
# shell: bash
# run: |
# more $GITHUB_EVENT_PATH
- name: set env
if: ${{ github.event_name == 'pull_request' && github.repository == 'deepflowio/docs' && github.event.pull_request.base.ref == 'main' }}
run: |
echo "IMAGE_TAG_PREFIX=${{ github.event.pull_request.head.ref }}"|sed 's|main|latest|' >> $GITHUB_ENV
- name: set env
if: ${{ github.event_name == 'push' && github.repository == 'deepflowio/docs'}}
run: |
echo "IMAGE_TAG_PREFIX=${{ github.ref_name }}"|sed 's|main|latest|' >> $GITHUB_ENV
- name: set env
if: ${{ github.event_name == 'workflow_dispatch' && github.repository == 'deepflowio/docs'}}
run: |
echo "IMAGE_TAG_PREFIX=${{ github.ref_name }}"|sed 's|main|latest|' >> $GITHUB_ENV
- name: Build and push docs image
if: ${{ github.repository == 'deepflowio/docs'}}
uses: docker/build-push-action@v2
with:
context: .
file: Dockerfile
platforms: linux/amd64
push: true
tags: |
"${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}-${{ github.run_id }}-${{ github.run_attempt }}"
"${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}"
- name: template
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
echo "TEMPLATE=red" >> $GITHUB_ENV
- name: template
if: ${{ github.event_name == 'push' }}
shell: bash
run: |
echo "TEMPLATE=green" >> $GITHUB_ENV
- name: info
shell: bash
if: ${{ github.repository == 'deepflowio/docs'}}
run: |
curl -X POST -H "Content-Type: application/json" -d \
'{"msg_type":"interactive","card":
{
"config": {
"wide_screen_mode": true
},
"elements": [
{
"tag": "div",
"text": {
"content": "docs分支: ${{ github.ref_name }}\n镜像tag:${{ github.run_id }}-${{ github.run_attempt }}\nmain分支自动更新到测试环境\n更新命令:\nkubectl set image -n deepservice-test deployment deepservice-docs deepservice-docs=${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}-${{ github.run_id }}-${{ github.run_attempt }}",
"tag": "lark_md"
}
}
],
"header": {
"template": "${{ env.TEMPLATE }}",
"title": {
"content": "👻DeepFlow (Community)-docs ${{ github.event_name }} 事件",
"tag": "plain_text"
}
}
}
}' \
${{ secrets.FEISHU_ROBOT }}
- name: set kubeconfig
if: ${{ github.repository == 'deepflowio/docs'}}
shell: bash
run: |
mkdir -p ~/.kube
echo "${{ secrets.DEEPFLOWIOKUBECONFIG}}" >> ~/.kube/config
- name: update
if: ${{ github.event_name == 'pull_request' && github.event.pull_request.base.ref == 'main' && github.repository == 'deepflowio/docs' && github.event.pull_request.merged == true }}
shell: bash
run: |
kubectl set image -n deepservice-test deployment deepservice-docs deepservice-docs=${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}-${{ github.run_id }}-${{ github.run_attempt }}
- name: update
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' && github.repository == 'deepflowio/docs' }}
shell: bash
run: |
kubectl set image -n deepservice deployment deepservice-docs deepservice-docs=${{ secrets.REGISTRY_ALIYUN_ADDR }}/deepservice/${{ env.IMAGE }}:${{ env.IMAGE_TAG_PREFIX }}-${{ github.run_id }}-${{ github.run_attempt }}