Skip to content

sftp-test

sftp-test #7

Workflow file for this run

# 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 sshpass
run: sudo apt-get install -y sshpass
- name: Delete existing files on remote server
env:
SSHPASS: ${{ secrets.SFTP_PASSWORD }}
run: |
sshpass -e sftp -o StrictHostKeyChecking=no ${{ secrets.SFTP_USER }}@${{ secrets.SFTP_HOST }} <<EOF
rm -rf /upload/*
mkdir /upload/resume
mkdir /upload/homepage
bye
EOF
- name: Upload files to remote server
env:
SSHPASS: ${{ secrets.SFTP_PASSWORD }}
run: |
sshpass -e sftp -o StrictHostKeyChecking=no -b - ${{ secrets.SFTP_USER }}@${{ secrets.SFTP_HOST }} <<EOF
put -r build/* /upload/
bye
EOF
#name: Node.js CI
#on:
# push:
# branches:
# - main
#
#jobs:
# build:
# runs-on: self-hosted
#
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
#
# - name: Run a script
# run: echo "Running on CentOS 8.2"
# ftp,ubuntu版本
#name: Node.js CI
##on: [push]
#on:
# push:
# branches: [ "master",]
## pull_request:
## branches: [ "master" ]
#jobs:
# build:
# runs-on: centos-8.2
# 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: FTP Deploy
# uses: SamKirkland/FTP-Deploy-Action@3.0.0
# with:
# ftp-server: sftp://sftp.yangmufa.com
# ftp-username: ${{secrets.sftp_user }}
# ftp-password: ${{ secrets.sftp_pwd }}
# local-dir: build/
# 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: ${{ secrets.sftp_user }}
## key: ${{ secrets.sftp_pwd }}
# username: "sftpuser"
# key: "sftppassword"
# # -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
# 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