mirror of
https://github.com/woodchen-ink/Random-Api.git
synced 2025-07-18 14:02:03 +08:00
53 lines
1.7 KiB
YAML
53 lines
1.7 KiB
YAML
name: Build and Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main # 或者您的主分支名称
|
|
|
|
jobs:
|
|
build-and-deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v2
|
|
|
|
- name: Create artifact
|
|
run: |
|
|
zip -r deployment.zip . -x "*.git*"
|
|
|
|
- name: Deploy to server
|
|
uses: appleboy/scp-action@master
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: root
|
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
|
source: "deployment.zip"
|
|
target: "/tmp"
|
|
|
|
- name: Execute deployment commands
|
|
uses: appleboy/ssh-action@master
|
|
with:
|
|
host: ${{ secrets.SERVER_HOST }}
|
|
username: root
|
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
|
script: |
|
|
# 解压文件
|
|
unzip -o /tmp/deployment.zip -d /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index2
|
|
|
|
# 删除 index 目录下的所有文件
|
|
rm -rf /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index/*
|
|
|
|
# 移动文件,采用覆盖模式
|
|
mv -f /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index2/* /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index/
|
|
|
|
# 删除 index2 文件夹
|
|
rm -rf /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index2
|
|
|
|
# 设置目录及其子文件的所有权和权限
|
|
chown -R 1000:1000 /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index
|
|
chmod -R 0755 /opt/1panel/apps/openresty/openresty/www/sites/random-api-file.czl.net/index
|
|
|
|
# 清理临时文件
|
|
rm /tmp/deployment.zip
|