Skip to content

Commit

Permalink
sftp-test
Browse files Browse the repository at this point in the history
  • Loading branch information
DevCaikun committed Jul 13, 2024
1 parent d956bc2 commit 56429d0
Showing 1 changed file with 107 additions and 56 deletions.
163 changes: 107 additions & 56 deletions .github/workflows/node.js.yml → .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,64 @@
# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs

name: Deploy to Remote Server

on:
push:
branches:
- master # 可以根据需要修改分支名称

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '20' # 你可以根据需要修改 Node.js 版本

- name: Install dependencies
run: npm install

- name: Build project
run: npm run build

- name: Install SSH client
run: sudo apt-get install -y sshpass

- name: Delete existing files on remote server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
run: |
sshpass -e ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST "find /docker/nginx/html/itBlog/upload/* -maxdepth 0 -type d \( -name 'resume' -o -name 'homepage' \) -prune -o -exec rm -rf {} +"
sshpass -e ssh -o StrictHostKeyChecking=no $SSH_USER@$SSH_HOST "find /docker/nginx/html/itBlog/upload/* -maxdepth 0 -type f -exec rm -rf {} +"
- name: Upload files to remote server
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_HOST: ${{ secrets.SSH_HOST }}
run: |
sshpass -e sftp -o StrictHostKeyChecking=no -b - $SSH_USER@$SSH_HOST <<EOF
put -r build/* /docker/nginx/html/itBlog/upload/
bye
EOF
#name: Node.js CI

# ftp,centos或Linux版
#name: CI
#
#on:
# push:
# branches:
Expand Down Expand Up @@ -57,7 +111,6 @@
# env:
# CI: true

# sftp版本,ubuntu系统

#name: Node.js CI
#
Expand Down Expand Up @@ -105,60 +158,58 @@
# source: "build/*"
# target: "/docker/nginx/html/itBlog/upload"
# host: sftp.yangmufa.com
## username: ${{ secrets.sftp_user }}
## key: ${{ secrets.sftp_pwd }}
# username: "sftpuser"
# key: "sftppassword"
# ftp-username: ${{ secrets.sftp_user }}
# ftp-password: ${{ secrets.sftp_pwd }}
# env:
# CI: true

name: Node.js CI

on:
push:
branches: [ "master" ]
## pull_request:
## branches: [ "master" ]
jobs:
build:
# ubuntu系统
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm install
- run: npm run build --if-present
- name: Clean remote directory
uses: appleboy/ssh-action@v0.1.5
with:
host: sftp.yangmufa.com
username: "sftpuser"
key: ${{ secrets.SFTP_PRIVATE_KEY }}
# -mindepth 1 确保不会删除 upload 目录本身,只删除其中的内容
# ! -name 'filename' 用于排除特定文件和文件夹
# -exec rm -rf {} + 将找到的文件和文件夹传递给 rm -rf 命令以进行删除
script: |
find /docker/nginx/html/itBlog/upload -mindepth 1 \
! -name 'resume' \
! -name 'homepage' \
-exec rm -rf {} +
- name: SFTP Deploy
uses: appleboy/scp-action@v0.1.5
with:
source: "build/*"
target: "/docker/nginx/html/itBlog/upload"
host: sftp.yangmufa.com
username: "sftpuser"
key: ${{ secrets.SFTP_PRIVATE_KEY }}
env:
CI: true
#name: Node.js CI
#
#on:
# push:
# branches: [ "master" ]
### pull_request:
### branches: [ "master" ]
#jobs:
# build:
# # ubuntu系统
# runs-on: ubuntu-latest
# strategy:
# matrix:
# node-version: [20.x]
# # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
# steps:
# - uses: actions/checkout@v4
# - name: Use Node.js ${{ matrix.node-version }}
# uses: actions/setup-node@v3
# with:
# node-version: ${{ matrix.node-version }}
# cache: 'npm'
# - run: npm install
# - run: npm run build --if-present
# - name: Clean remote directory
# uses: appleboy/ssh-action@v0.1.5
# with:
# host: sftp.yangmufa.com
# username: "sftpuser"
# key: ${{ secrets.SFTP_PRIVATE_KEY }}
# # -mindepth 1 确保不会删除 upload 目录本身,只删除其中的内容
# # ! -name 'filename' 用于排除特定文件和文件夹
# # -exec rm -rf {} + 将找到的文件和文件夹传递给 rm -rf 命令以进行删除
# script: |
# find /docker/nginx/html/itBlog/upload -mindepth 1 \
# ! -name 'resume' \
# ! -name 'homepage' \
# -exec rm -rf {} +
# - name: SFTP Deploy
# uses: appleboy/scp-action@v0.1.5
# with:
# source: "build/*"
# target: "/docker/nginx/html/itBlog/upload"
# host: sftp.yangmufa.com
# username: "sftpuser"
# key: ${{ secrets.SFTP_PRIVATE_KEY }}
# env:
# CI: true


0 comments on commit 56429d0

Please sign in to comment.