mengstack-api/.gitea/workflows/ci.yml
MengStack Dev bc5c2889c0
Some checks failed
MengStack CI/CD / Build & Test (push) Failing after 44s
MengStack CI/CD / Deploy to Server (push) Has been skipped
Initial commit: MengStack Go API framework
2026-10-02 23:55:35 +08:00

94 lines
2.3 KiB
YAML

name: MengStack CI/CD
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
env:
GO_VERSION: '1.23'
APP_NAME: mengstack
jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Vet
run: go vet ./...
- name: Build
run: |
mkdir -p build
go build -o build/${{ env.APP_NAME }} ./cmd/server
- name: Test
run: go test ./... -v -race -coverprofile=coverage.out
- name: Upload coverage
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v4
with:
name: coverage
path: coverage.out
retention-days: 7
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: ${{ env.APP_NAME }}-binary
path: build/${{ env.APP_NAME }}
retention-days: 7
deploy:
name: Deploy to Server
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: ${{ env.APP_NAME }}-binary
- name: Deploy via SSH
uses: appleboy/scp-action@v0.1.7
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
source: ${{ env.APP_NAME }}
target: /opt/mengstack/
- name: Restart service
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.DEPLOY_HOST }}
username: ${{ secrets.DEPLOY_USER }}
key: ${{ secrets.DEPLOY_SSH_KEY }}
script: |
chmod +x /opt/mengstack/${{ env.APP_NAME }}
systemctl restart mengstack
sleep 3
systemctl is-active mengstack