163 lines
5.5 KiB
YAML
163 lines
5.5 KiB
YAML
name: CI Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- test
|
|
- main
|
|
|
|
jobs:
|
|
build-and-deploy-dev:
|
|
if: gitea.ref_name == 'test'
|
|
runs-on: gitea_act_runner
|
|
container:
|
|
image: node:24-alpine
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v3
|
|
with:
|
|
version: 8
|
|
|
|
- name: Install deps
|
|
run: |
|
|
npm config set registry https://registry.npmmirror.com/
|
|
pnpm install
|
|
|
|
- name: Build (test)
|
|
run: pnpm build:test
|
|
|
|
- name: Pack artifacts
|
|
run: |
|
|
rm -rf dist.tar
|
|
tar -zcvf dist.tar ./dist ./default.conf ./Dockerfile
|
|
|
|
- name: Upload artifacts to server
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.HOST_DEV }}
|
|
username: ${{ secrets.USER_DEV }}
|
|
password: ${{ secrets.PWD_DEV }}
|
|
port: 22
|
|
source: 'dist.tar'
|
|
target: '/www/builder'
|
|
strip_components: 0
|
|
|
|
- name: Deploy over SSH
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.HOST_DEV }}
|
|
username: ${{ secrets.USER_DEV }}
|
|
password: ${{ secrets.PWD_DEV }}
|
|
port: 22
|
|
script: |
|
|
set -e
|
|
cd /www/builder
|
|
rm -rf jdt-mer-dev
|
|
mkdir -p jdt-mer-dev
|
|
tar -xzvf dist.tar -C /www/builder/jdt-mer-dev
|
|
rm -rf dist.tar
|
|
cd jdt-mer-dev
|
|
docker build -t jdt-mer-dev .
|
|
docker stop jdt-mer-dev || true
|
|
docker rm jdt-mer-dev || true
|
|
docker run -d -p 8083:80 --restart=always --name jdt-mer-dev jdt-mer-dev
|
|
cd ..
|
|
rm -rf jdt-mer-dev
|
|
|
|
- name: Notify WeCom (Dev)
|
|
if: always()
|
|
env:
|
|
WEBHOOK_KEY: ${{ secrets.QYWX_WEBHOOK_KEY }}
|
|
STATUS: ${{ job.status }}
|
|
REPO: ${{ gitea.repository }}
|
|
RUN_URL: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}
|
|
BRANCH: ${{ gitea.ref_name }}
|
|
COMMIT: ${{ gitea.sha }}
|
|
ACTOR: ${{ gitea.actor }}
|
|
run: |
|
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories || true
|
|
apk add --no-cache curl jq
|
|
EMOJI=$( [ "$STATUS" = "success" ] && echo "✅" || echo "❌" )
|
|
MSG="$(printf "%s**%s** (Run #%s)\n>**构建结果**: %s\n>**构建详情**: [点击查看](%s)\n>**代码分支**: %s\n>**提交标识**: %s\n>**提交发起**: %s\n" "$EMOJI" "$REPO" "${{ gitea.run_number }}" "$STATUS" "$RUN_URL" "$BRANCH" "$COMMIT" "$ACTOR")"
|
|
curl -sS -H 'Content-Type: application/json' -d "{\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"$MSG\"}}" "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}"
|
|
|
|
build-and-deploy-prod:
|
|
if: gitea.ref_name == 'main'
|
|
runs-on: gitea_act_runner
|
|
container:
|
|
image: node:24-alpine
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup pnpm
|
|
uses: pnpm/action-setup@v3
|
|
with:
|
|
version: 8
|
|
|
|
- name: Install deps
|
|
run: |
|
|
npm config set registry https://registry.npmmirror.com/
|
|
pnpm install
|
|
|
|
- name: Build (prod)
|
|
run: pnpm build:prod
|
|
|
|
- name: Pack artifacts
|
|
run: |
|
|
rm -rf dist.tar
|
|
tar -zcvf dist.tar ./dist ./default.conf ./Dockerfile
|
|
|
|
- name: Upload artifacts to server
|
|
uses: appleboy/scp-action@v0.1.7
|
|
with:
|
|
host: ${{ secrets.HOST_PROD }}
|
|
username: ${{ secrets.USER_PROD }}
|
|
password: ${{ secrets.PWD_PROD }}
|
|
port: 22
|
|
source: 'dist.tar'
|
|
target: '/www/builder'
|
|
strip_components: 0
|
|
|
|
- name: Deploy over SSH
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.HOST_PROD }}
|
|
username: ${{ secrets.USER_PROD }}
|
|
password: ${{ secrets.PWD_PROD }}
|
|
port: 22
|
|
script: |
|
|
set -e
|
|
cd /www/builder
|
|
rm -rf jdt-mer-prod
|
|
mkdir -p jdt-mer-prod
|
|
tar -xzvf dist.tar -C /www/builder/jdt-mer-prod
|
|
rm -rf dist.tar
|
|
cd jdt-mer-prod
|
|
docker build -t jdt-mer-prod .
|
|
docker stop jdt-mer-prod || true
|
|
docker rm jdt-mer-prod || true
|
|
docker run -d -p 8083:80 --restart=always --name jdt-mer-prod jdt-mer-prod
|
|
cd ..
|
|
rm -rf jdt-mer-prod
|
|
|
|
- name: Notify WeCom (Prod)
|
|
if: always()
|
|
env:
|
|
WEBHOOK_KEY: ${{ secrets.QYWX_WEBHOOK_KEY }}
|
|
STATUS: ${{ job.status }}
|
|
REPO: ${{ gitea.repository }}
|
|
RUN_URL: ${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }}
|
|
BRANCH: ${{ gitea.ref_name }}
|
|
COMMIT: ${{ gitea.sha }}
|
|
ACTOR: ${{ gitea.actor }}
|
|
run: |
|
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories || true
|
|
apk add --no-cache curl jq
|
|
EMOJI=$( [ "$STATUS" = "success" ] && echo "✅" || echo "❌" )
|
|
MSG="$(printf "%s**%s** (Run #%s)\n>**构建结果**: %s\n>**构建详情**: [点击查看](%s)\n>**代码分支**: %s\n>**提交标识**: %s\n>**提交发起**: %s\n" "$EMOJI" "$REPO" "${{ gitea.run_number }}" "$STATUS" "$RUN_URL" "$BRANCH" "$COMMIT" "$ACTOR")"
|
|
curl -sS -H 'Content-Type: application/json' -d "{\"msgtype\":\"markdown\",\"markdown\":{\"content\":\"$MSG\"}}" "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${WEBHOOK_KEY}"
|