-
Notifications
You must be signed in to change notification settings - Fork 0
136 lines (115 loc) · 3.87 KB
/
preview.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
name: Build Preview Frontend
on:
push:
branches: [ main ]
jobs:
build_and_pack_frontend:
runs-on: ubuntu-20.04
steps:
- name: Install required packages
run: |
sudo apt-get update
sudo apt-get install -y zip unzip
- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '22.7'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 9.9.0
- name: Install dependencies
run: pnpm install --frozen-lockfile
- name: Build project
run: pnpm build
- name: Get date and commit hash
run: |
echo "DATE=$(date +'%Y%m%d')" >> $GITHUB_ENV
echo "COMMIT_HASH=${{github.sha}}" >> $GITHUB_ENV
- name: Truncate commit hash
run: |
HASH=${{ env.COMMIT_HASH }}
TRUNCATED_HASH=${HASH:0:8}
echo "TRUNCATED_HASH=${TRUNCATED_HASH}" >> $GITHUB_ENV
- name: Zip dist directory
run: zip -r preview-dist.zip ./dist
- name: Upload Artifacts
uses: actions/upload-artifact@v3
with:
name: preview-dist.zip
path: ./preview-dist.zip
release:
needs:
- build_and_pack_frontend
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Download From Artifacts
uses: actions/download-artifact@v3
with:
name: preview-dist.zip
- name: Set release name
run: |
DATE=$(date +"%Y%m%d")
SHORT_COMMIT_HASH=$(git rev-parse --short HEAD)
echo "RELEASE_NAME=v${DATE}-${SHORT_COMMIT_HASH}" >> $GITHUB_ENV
- name: Create release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
tag_name: ${{ env.RELEASE_NAME }}
release_name: Release Preview ${{ env.RELEASE_NAME }}
draft: false
prerelease: false
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: preview-dist.zip
asset_name: preview-dist.zip
asset_content_type: application/zip
deploy_to_server:
needs:
- build_and_pack_frontend
runs-on: ubuntu-latest
steps:
- name: Download From Artifacts
uses: actions/download-artifact@v3
with:
name: preview-dist.zip
- name: Backup existing files
uses: appleboy/ssh-action@master
with:
host: legion-4g.yaklang.io
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /root/
if [ -d "preview-dist.zip" ]; then
mv preview-dist.zip preview-dist.zip.$(date +"%Y%m%d").bak
fi
- name: Upload dist files
uses: appleboy/scp-action@master
with:
host: legion-4g.yaklang.io
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
source: preview-dist.zip
target: /root/
- name: Deploy
uses: appleboy/ssh-action@master
with:
host: legion-4g.yaklang.io
username: root
key: ${{ secrets.SSH_PRIVATE_KEY }}
script: |
cd /root/
unzip -o preview-dist.zip
rm preview-dist.zip