-
Notifications
You must be signed in to change notification settings - Fork 9
129 lines (112 loc) · 4.27 KB
/
deploy-staging.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
name: 📤 Deploy Staging
on:
push:
branches:
- main
workflow_dispatch:
inputs:
image-tag:
description: The image tag to deploy (optional, if not provided, the image will be built first)
type: string
default: ''
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{github.event}}
cancel-in-progress: true
jobs:
ci-test:
if: inputs.image-tag == ''
uses: ./.github/workflows/ci-test.yml
secrets: inherit
build:
if: inputs.image-tag == ''
runs-on: ubuntu-latest
timeout-minutes: 60
needs: ci-test
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
token: ${{ secrets.GH_TOKEN }}
- uses: actions/cache@v4
with:
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
path: |
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- name: Set IMAGE_TAG environment variable
run: echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV
# Deploy to dev.univer.plus
- name: Login to Aliyun Container Registry (ACR)
uses: aliyun/acr-login@v1
with:
login-server: '${{ secrets.REGISTRY_CR }}'
region-id: cn-shenzhen
username: '${{ secrets.REGISTRY_USERNAME }}'
password: '${{ secrets.REGISTRY_PASSWORD }}'
- name: check check_image
run: |
echo "IMAGE_EXIST=$(make check_image CR=${{ secrets.REGISTRY_CR }})" >> $GITHUB_ENV
- name: Setup Node.js
uses: ./.github/actions/setup-node
with:
npmtoken: ${{ secrets.VERDACCIO_TOKEN }}
if: env.IMAGE_EXIST != 'true'
# - name: Cache Next.js
# uses: actions/cache@v4
# with:
# path: |
# ${{ github.workspace }}/.next/cache
# key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# restore-keys: |
# ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-
- name: Build
run: |
pnpm lint:types
pnpm build
if: env.IMAGE_EXIST != 'true'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
image: ${{ secrets.REGISTRY_CR }}/devops/binfmt:qemu-v7.0.0
if: env.IMAGE_EXIST != 'true'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
id: buildx
with:
driver-opts: |
image=${{ secrets.REGISTRY_CR }}/devops/buildkit:buildx-stable-1
if: env.IMAGE_EXIST != 'true'
- name: Build and Push Docker Image
run: |
IMAGE_TAG=$(echo "${{ github.sha }}" | cut -c 1-7)
make push_image PUSH_TAG=$IMAGE_TAG BUILDER=${{ steps.buildx.outputs.name }} CR=${{ secrets.REGISTRY_CR }}
if: env.IMAGE_EXIST != 'true'
deploy:
if: inputs.image-tag == ''
runs-on: ubuntu-latest
needs: build
timeout-minutes: 10
steps:
- name: Set IMAGE_TAG environment variable
run: echo "IMAGE_TAG=$(echo ${{ github.sha }} | cut -c 1-7)" >> $GITHUB_ENV
- uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GH_TOKEN }}
repository: dream-num/helm-chart-private
event-type: dispatch
client-payload: '{"service":"univer-site","tag":"${{ env.IMAGE_TAG }}"}'
deploy-trigger:
if: inputs.image-tag != ''
runs-on: arc-runner-set
steps:
- uses: peter-evans/repository-dispatch@v2
with:
token: ${{ secrets.GH_TOKEN }}
repository: dream-num/helm-chart-private
event-type: dispatch
client-payload: '{"service":"univer-site","tag":"${{ inputs.image-tag }}"}'