go - 如何通过 github 操作创建 CI/CD Go 应用程序
问题描述
我想创建一个作业操作来构建 Go 应用程序并在 digitalocean 上的 droplet 中进行部署。我正在尝试使用它,但是
name: Countinus Deployments
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
build:
runs-on: ubuntu-latest
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Deploy and rebuild on server
uses: appleboy/ssh-action@master
with:
host: xxxxxxxxxxx
username: root
key: ${{ secrets.serverKey }}
port: 22
script:
cd go/victorydash/ &&
git pull origin master &&
git status &&
echo $PATH &&
go build -o app main.go &&
systemctl restart goweb.service &&
systemctl status goweb
但是这些代码“go build -o app main.go &&”没有在服务器上构建有没有人知道任何解决方案?
解决方案
我已经找到了解决方案
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout the repository
uses: actions/checkout@v2
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: Build app
run: go build -o app main.go
- name: SCP to Ocean
uses: appleboy/scp-action@master
with:
host: ${{ secrets.host }}
username: ${{ secrets.user }}
key: ${{ secrets.serverKey }}
port:
source: "app"
target: "dist"
- name: Deploy and rebuild on server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.host }}
username: ${{ secrets.user }}
key: ${{ secrets.serverKey }}
port: ${{ secrets.port }}
script:
systemctl restart goweb.service &&
systemctl status goweb