-
-
Notifications
You must be signed in to change notification settings - Fork 105
184 lines (174 loc) · 5.33 KB
/
release.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
on:
push:
tags:
- 'v*'
name: Release (core)
jobs:
build:
name: Main Build
runs-on: ubuntu-22.04
outputs:
release_url: ${{ steps.create_release.outputs.upload_url }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v4
with:
node-version: 20.x
- name: Start MongoDB
uses: supercharge/[email protected]
with:
mongodb-version: 4.4
- name: Start Redis
uses: supercharge/[email protected]
with:
redis-version: 6
- name: Setup pnpm
uses: pnpm/[email protected]
with:
version:
run_install: false
- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
- name: Cache pnpm modules
uses: actions/cache@v4
env:
cache-name: cache-pnpm-modules
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Install Dependencies
run: |
pnpm i
- name: Build project
run: |
pnpm run bundle
- name: Test Bundle Server
run: |
bash scripts/workflow/test-server.sh
- name: Zip Assets
run: |
sh apps/core/zip-asset.sh
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: ${{ github.ref_name }}
draft: false
prerelease: ${{ contains(fromJSON('["alpha", "beta"]'), github.ref_name) }}
- run: npx changelogithub
continue-on-error: true
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release.zip
asset_name: release-linux.zip
asset_content_type: application/zip
deploy:
name: Deploy To Remote Server
runs-on: ubuntu-latest
needs: [build]
steps:
- uses: robinraju/[email protected]
name: Download release
with:
tag: ${{ github.ref_name }}
fileName: 'release-linux.zip'
- name: copy file via ssh password
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
# port: ${{ secrets.PORT }}
key: ${{ secrets.KEY }}
source: 'release-linux.zip'
target: '/tmp/mx-core'
- name: Exec deploy script with SSH
uses: appleboy/ssh-action@master
env:
JWTSECRET: ${{ secrets.JWTSECRET }}
MX_ENCRYPT_KEY: ${{ secrets.MX_ENCRYPT_KEY }}
with:
command_timeout: 5m
host: ${{ secrets.HOST }}
username: ${{ secrets.USER }}
password: ${{ secrets.PASSWORD }}
key: ${{ secrets.KEY }}
envs: JWTSECRET,MX_ENCRYPT_KEY
script_stop: true
script: |
whoami
cd
source ~/.zshrc
cd mx
ls -a
node server-deploy.js --jwtSecret=$JWTSECRET --encrypt_key=$MX_ENCRYPT_KEY --encrypt_enable --scp_path=/tmp/mx-core/release-linux.zip
docker:
name: Docker Release
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
arch: ['amd64', 'arm64']
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
innei/mx-server
tags: |
type=ref,event=branch
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Copy .env
run: |
cp .env.example .env
- name: Build and export to Docker
uses: docker/build-push-action@v6
with:
context: .
load: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }},innei/mx-server:latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Test
run: |
bash ./scripts/workflow/test-docker.sh
sudo rm -rf ./data
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}