Skip to content

Speed up ci pipeline #4

Speed up ci pipeline

Speed up ci pipeline #4

Workflow file for this run

name: CI & Deploy
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
cache: false # golangci-lint caching is handled separately
- name: golangci-lint cache
uses: actions/cache@v4
with:
path: ~/.cache/golangci-lint
key: ${{ runner.os }}-golangci-lint-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golangci-lint-
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: latest # Or pin to a specific version
args: --timeout=5m
test:
name: Test
runs-on: ubuntu-latest
# Removed: needs: lint
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
cache: true
- name: Run tests
# Use -p 1 to run tests sequentially due to potential global state issues
run: go test -p 1 -v ./...
build:
name: Build
runs-on: ubuntu-latest
# Removed: needs: test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
cache: true
- name: Build Server
run: go build -v -o ./build/server ./cmd/server
- name: Build CLI
run: go build -v -o ./build/sproto-cli ./cmd/cli
- name: Upload build artifacts (optional)
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: ./build/
deploy:
name: Deploy
runs-on: ubuntu-latest
needs: [lint, test, build] # Run after lint, test, and build succeed
# Only run on push to main branch, not on pull requests
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.24.2'
cache: true
# --- Docker Build & Push ---
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set lower case owner/repo name env var
run: echo "LOWER_REPO=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Build and push Docker image to GHCR
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
ghcr.io/${{ env.LOWER_REPO }}:latest
ghcr.io/${{ env.LOWER_REPO }}:${{ github.sha }}
# --- Build CLI Binaries ---
- name: Build CLI for Linux
run: GOOS=linux GOARCH=amd64 go build -v -o ./build/sproto-cli-linux-amd64 ./cmd/cli
- name: Build CLI for macOS
run: GOOS=darwin GOARCH=amd64 go build -v -o ./build/sproto-cli-darwin-amd64 ./cmd/cli
- name: Build CLI for Windows
run: GOOS=windows GOARCH=amd64 go build -v -o ./build/sproto-cli-windows-amd64.exe ./cmd/cli
# --- Create GitHub Release and Upload Assets ---
- name: Create Release and Upload Assets
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.sha }}
name: Release ${{ github.sha }}
body: "Automated release based on commit ${{ github.sha }}"
draft: false
prerelease: false
files: |
./build/sproto-cli-linux-amd64
./build/sproto-cli-darwin-amd64
./build/sproto-cli-windows-amd64.exe
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}