ci(other): update cicd
This commit is contained in:
@@ -12,151 +12,145 @@ jobs:
|
|||||||
runs-on: gitea_act_runner
|
runs-on: gitea_act_runner
|
||||||
container:
|
container:
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
|
env:
|
||||||
|
APP_NAME: jdt-mer-dev
|
||||||
|
APP_PORT: 8083
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup environment
|
||||||
uses: pnpm/action-setup@v3
|
run: |
|
||||||
with:
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||||
version: 8
|
apk add --no-cache curl
|
||||||
|
npm config set registry https://registry.npmmirror.com/
|
||||||
|
corepack enable && corepack prepare pnpm@8 --activate
|
||||||
|
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: pnpm install --frozen-lockfile
|
||||||
npm config set registry https://registry.npmmirror.com/
|
|
||||||
pnpm install
|
|
||||||
|
|
||||||
- name: Build (test)
|
- name: Build
|
||||||
run: pnpm build:test
|
run: pnpm build:test
|
||||||
|
|
||||||
- name: Pack artifacts
|
- name: Pack artifacts
|
||||||
run: |
|
run: tar -zcf dist.tar ./dist ./default.conf ./Dockerfile
|
||||||
rm -rf dist.tar
|
|
||||||
tar -zcvf dist.tar ./dist ./default.conf ./Dockerfile
|
|
||||||
|
|
||||||
- name: Upload artifacts to server
|
- name: Upload to server
|
||||||
uses: appleboy/scp-action@v0.1.7
|
uses: https://gitea.com/appleboy/scp-action@v0.1.7
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST_DEV }}
|
host: ${{ secrets.HOST_DEV }}
|
||||||
username: ${{ secrets.USER_DEV }}
|
username: ${{ secrets.USER_DEV }}
|
||||||
password: ${{ secrets.PWD_DEV }}
|
password: ${{ secrets.PWD_DEV }}
|
||||||
port: 22
|
port: 22
|
||||||
source: 'dist.tar'
|
source: dist.tar
|
||||||
target: '/www/builder'
|
target: /www/builder
|
||||||
strip_components: 0
|
|
||||||
|
|
||||||
- name: Deploy over SSH
|
- name: Deploy
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: https://gitea.com/appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST_DEV }}
|
host: ${{ secrets.HOST_DEV }}
|
||||||
username: ${{ secrets.USER_DEV }}
|
username: ${{ secrets.USER_DEV }}
|
||||||
password: ${{ secrets.PWD_DEV }}
|
password: ${{ secrets.PWD_DEV }}
|
||||||
port: 22
|
port: 22
|
||||||
|
envs: APP_NAME,APP_PORT
|
||||||
script: |
|
script: |
|
||||||
set -e
|
set -e
|
||||||
cd /www/builder
|
cd /www/builder
|
||||||
rm -rf jdt-mer-dev
|
rm -rf $APP_NAME && mkdir -p $APP_NAME
|
||||||
mkdir -p jdt-mer-dev
|
tar -xzf dist.tar -C $APP_NAME && rm -f dist.tar
|
||||||
tar -xzvf dist.tar -C /www/builder/jdt-mer-dev
|
cd $APP_NAME
|
||||||
rm -rf dist.tar
|
docker build -t $APP_NAME .
|
||||||
cd jdt-mer-dev
|
docker rm -f $APP_NAME 2>/dev/null || true
|
||||||
docker build -t jdt-mer-dev .
|
docker run -d -p $APP_PORT:80 --restart=always --name $APP_NAME $APP_NAME
|
||||||
docker stop jdt-mer-dev || true
|
cd .. && rm -rf $APP_NAME
|
||||||
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)
|
- name: Notify WeCom
|
||||||
if: always()
|
if: always()
|
||||||
env:
|
env:
|
||||||
WEBHOOK_KEY: ${{ secrets.QYWX_WEBHOOK_KEY }}
|
WEBHOOK_KEY: ${{ secrets.QYWX_WEBHOOK_KEY }}
|
||||||
STATUS: ${{ job.status }}
|
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: |
|
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 "❌" )
|
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")"
|
MSG="${EMOJI}**${{ gitea.repository }}** (Run #${{ gitea.run_number }})\n"
|
||||||
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}"
|
MSG+=">**构建结果**: ${STATUS}\n"
|
||||||
|
MSG+=">**构建详情**: [点击查看](${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }})\n"
|
||||||
|
MSG+=">**代码分支**: ${{ gitea.ref_name }}\n"
|
||||||
|
MSG+=">**提交标识**: ${{ gitea.sha }}\n"
|
||||||
|
MSG+=">**提交发起**: ${{ gitea.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:
|
build-and-deploy-prod:
|
||||||
if: gitea.ref_name == 'master'
|
if: gitea.ref_name == 'master'
|
||||||
runs-on: gitea_act_runner
|
runs-on: gitea_act_runner
|
||||||
container:
|
container:
|
||||||
image: node:24-alpine
|
image: node:24-alpine
|
||||||
|
env:
|
||||||
|
APP_NAME: jdt-mer-prod
|
||||||
|
APP_PORT: 8083
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Checkout
|
||||||
uses: actions/checkout@v4
|
uses: https://gitea.com/actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup pnpm
|
- name: Setup environment
|
||||||
uses: pnpm/action-setup@v3
|
run: |
|
||||||
with:
|
sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories
|
||||||
version: 8
|
apk add --no-cache curl
|
||||||
|
npm config set registry https://registry.npmmirror.com/
|
||||||
|
corepack enable && corepack prepare pnpm@8 --activate
|
||||||
|
|
||||||
- name: Install deps
|
- name: Install deps
|
||||||
run: |
|
run: pnpm install --frozen-lockfile
|
||||||
npm config set registry https://registry.npmmirror.com/
|
|
||||||
pnpm install
|
|
||||||
|
|
||||||
- name: Build (prod)
|
- name: Build
|
||||||
run: pnpm build:prod
|
run: pnpm build:prod
|
||||||
|
|
||||||
- name: Pack artifacts
|
- name: Pack artifacts
|
||||||
run: |
|
run: tar -zcf dist.tar ./dist ./default.conf ./Dockerfile
|
||||||
rm -rf dist.tar
|
|
||||||
tar -zcvf dist.tar ./dist ./default.conf ./Dockerfile
|
|
||||||
|
|
||||||
- name: Upload artifacts to server
|
- name: Upload to server
|
||||||
uses: appleboy/scp-action@v0.1.7
|
uses: https://gitea.com/appleboy/scp-action@v0.1.7
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST_PROD }}
|
host: ${{ secrets.HOST_PROD }}
|
||||||
username: ${{ secrets.USER_PROD }}
|
username: ${{ secrets.USER_PROD }}
|
||||||
password: ${{ secrets.PWD_PROD }}
|
password: ${{ secrets.PWD_PROD }}
|
||||||
port: 22
|
port: 22
|
||||||
source: 'dist.tar'
|
source: dist.tar
|
||||||
target: '/www/builder'
|
target: /www/builder
|
||||||
strip_components: 0
|
|
||||||
|
|
||||||
- name: Deploy over SSH
|
- name: Deploy
|
||||||
uses: appleboy/ssh-action@v1.0.3
|
uses: https://gitea.com/appleboy/ssh-action@v1.0.3
|
||||||
with:
|
with:
|
||||||
host: ${{ secrets.HOST_PROD }}
|
host: ${{ secrets.HOST_PROD }}
|
||||||
username: ${{ secrets.USER_PROD }}
|
username: ${{ secrets.USER_PROD }}
|
||||||
password: ${{ secrets.PWD_PROD }}
|
password: ${{ secrets.PWD_PROD }}
|
||||||
port: 22
|
port: 22
|
||||||
|
envs: APP_NAME,APP_PORT
|
||||||
script: |
|
script: |
|
||||||
set -e
|
set -e
|
||||||
cd /www/builder
|
cd /www/builder
|
||||||
rm -rf jdt-mer-prod
|
rm -rf $APP_NAME && mkdir -p $APP_NAME
|
||||||
mkdir -p jdt-mer-prod
|
tar -xzf dist.tar -C $APP_NAME && rm -f dist.tar
|
||||||
tar -xzvf dist.tar -C /www/builder/jdt-mer-prod
|
cd $APP_NAME
|
||||||
rm -rf dist.tar
|
docker build -t $APP_NAME .
|
||||||
cd jdt-mer-prod
|
docker rm -f $APP_NAME 2>/dev/null || true
|
||||||
docker build -t jdt-mer-prod .
|
docker run -d -p $APP_PORT:80 --restart=always --name $APP_NAME $APP_NAME
|
||||||
docker stop jdt-mer-prod || true
|
cd .. && rm -rf $APP_NAME
|
||||||
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)
|
- name: Notify WeCom
|
||||||
if: always()
|
if: always()
|
||||||
env:
|
env:
|
||||||
WEBHOOK_KEY: ${{ secrets.QYWX_WEBHOOK_KEY }}
|
WEBHOOK_KEY: ${{ secrets.QYWX_WEBHOOK_KEY }}
|
||||||
STATUS: ${{ job.status }}
|
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: |
|
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 "❌" )
|
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")"
|
MSG="${EMOJI}**${{ gitea.repository }}** (Run #${{ gitea.run_number }})\n"
|
||||||
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}"
|
MSG+=">**构建结果**: ${STATUS}\n"
|
||||||
|
MSG+=">**构建详情**: [点击查看](${{ gitea.server_url }}/${{ gitea.repository }}/actions/runs/${{ gitea.run_id }})\n"
|
||||||
|
MSG+=">**代码分支**: ${{ gitea.ref_name }}\n"
|
||||||
|
MSG+=">**提交标识**: ${{ gitea.sha }}\n"
|
||||||
|
MSG+=">**提交发起**: ${{ gitea.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}"
|
||||||
|
|||||||
Reference in New Issue
Block a user