1.github action
· 2 min read
github action 在线自动部署
to cloud platform
eg1:
name: WEBSITE DEPLOY CI
on:
push:
branches:
- main
- feature-1.0
paths-ignore:
- README.md
- LICENSE
jobs:
deploy_job:
runs-on: ubuntu-latest
name: build
steps:
# check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
run: yarn
- name: Build
run: yarn build
- name: deploy file to test server
if: github.ref == 'refs/heads/feature-1.0'
uses: wlixcc/SFTP-Deploy-Action@v1.0
with:
username: '${{secrets.YOUR_WEBSITE_USER}}'
server: '${{ secrets.YOUR_WEBSITE_SERVER_IP }}'
ssh_private_key: ${{ secrets.YOUR_WEBSITE_PAGES_DEPLOY }}
local_path: './build/*'
remote_path: ${{ secrets.YOUR_WEBSITE_REMOTE_PATH_DEV }}
- name: deploy file to prod server
if: github.ref == 'refs/heads/main'
uses: wlixcc/SFTP-Deploy-Action@v1.0
with:
username: '${{secrets.YOUR_WEBSITE_USER}}'
server: '${{ secrets.YOUR_WEBSITE_SERVER_IP }}'
ssh_private_key: ${{ secrets.YOUR_WEBSITE_PAGES_DEPLOY }}
local_path: './build/*'
remote_path: ${{ secrets.YOUR_WEBSITE_REMOTE_PATH_PROD }}
to another Repo
eg2.
name: DEPLOY CI - push to another rpo
on:
push:
branches:
- master
paths-ignore:
- README.md
- LICENSE
jobs:
deploy_job:
runs-on: ubuntu-latest
name: build
steps:
# check out the repository
- name: Checkout
uses: actions/checkout@v2
- name: Install Dependencies
run: yarn
- name: Build
run: yarn build
- name: Pushes to another repository
uses: cpina/github-action-push-to-another-repository@main
env:
API_TOKEN_GITHUB: ${{ secrets.API_TOKEN_GITHUB }}
with:
source-directory: 'build'
destination-github-username: ${{ secrets.DESTINATION_GITHUB_NAME }}
destination-repository-name: 'zzzzz'
target-directory: 'xxxx'
user-email: ${{ secrets.UESR_EMAIL }}
target-branch: gh-pages
关于服务器免登录问题
建立 SSH 密钥对
mac 用户:
mkdir -p ~/.ssh && cd ~/.ssh
ssh-keygen -t rsa -f fileName
1、如果是远程用户,将 fileName.pub 复制到目标服务器的 authorized_keys 文件当中,这样就不用密码登录;
2、如果是在 目标服务器运行的上述命令,同样把 fileName.pub 的内容复制到 authorized_keys 文件当中,或者直接 cat mysite.pub >> authorized_keys 另外一个私钥文件 fileName 则可以复制到 github secrets 当中的 ssh_private_key 中(可以让 github 访问目标服务器而不用密码,公钥已经在 authorized_keys 中,已授权)。