concord/.github/workflows/ci.yml
2025-10-30 19:24:35 +03:00

366 lines
9.6 KiB
YAML

name: CI/CD
on:
push:
branches: [ master, dev ]
pull_request:
branches: [ master, dev ]
workflow_dispatch:
env:
GO_VERSION: '1.23.2'
POSTGRES_VERSION: '14'
REDIS_VERSION: '7'
permissions:
contents: read
packages: write
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install Go tools
run: make install-tools
- name: Generate protobuf
run: make proto
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
with:
version: latest
args: --timeout=5m
test:
name: Test
runs-on: ubuntu-latest
needs: lint
services:
postgres:
image: postgres:14-alpine
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: concord_test
POSTGRES_USER: postgres
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
redis:
image: redis:7-alpine
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 6379:6379
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install Go tools
run: make install-tools
- name: Cache Go modules
uses: actions/cache@v3
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: Generate protobuf
run: make proto
- name: Run unit tests
run: make test-unit
env:
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: concord_test
REDIS_HOST: localhost
REDIS_PORT: 6379
- name: Run integration tests
run: make test-integration
env:
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: concord_test
REDIS_HOST: localhost
REDIS_PORT: 6379
build:
name: Build
runs-on: ubuntu-latest
needs: test
strategy:
matrix:
include:
- goos: linux
goarch: amd64
target: api
- goos: linux
goarch: amd64
target: voice
- goos: linux
goarch: arm64
target: api
- goos: linux
goarch: arm64
target: voice
- goos: darwin
goarch: amd64
target: api
- goos: darwin
goarch: amd64
target: voice
- goos: darwin
goarch: arm64
target: api
- goos: darwin
goarch: arm64
target: voice
- goos: windows
goarch: amd64
target: api
- goos: windows
goarch: amd64
target: voice
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache: true
- name: Install protoc
run: |
sudo apt-get update
sudo apt-get install -y protobuf-compiler
- name: Install Go tools
run: make install-tools
- name: Generate protobuf
run: make proto
- name: Build binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
BINARY_NAME="concord-${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}"
if [ "${{ matrix.goos }}" = "windows" ]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
go build -v -ldflags="-s -w" -o "$BINARY_NAME" ./cmd/concord-${{ matrix.target }}
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: concord-${{ matrix.target }}-${{ matrix.goos }}-${{ matrix.goarch }}
path: concord-*
retention-days: 7
docker:
name: Build & Push to GHCR
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Lowercase owner (GHCR requires lowercase)
run: echo "OWNER_LC=$(echo '${{ github.repository_owner }}' | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# ===== API image =====
- name: Docker metadata (api)
id: meta_api
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.OWNER_LC }}/concord-api
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=sha
type=ref,event=branch
- name: Build & push API
uses: docker/build-push-action@v5
with:
context: .
file: ./deploy/Dockerfile.api
push: true
tags: ${{ steps.meta_api.outputs.tags }}
labels: ${{ steps.meta_api.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
# ===== Voice image =====
- name: Docker metadata (voice)
id: meta_voice
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ env.OWNER_LC }}/concord-voice
tags: |
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/master' }}
type=sha
type=ref,event=branch
- name: Build & push Voice
uses: docker/build-push-action@v5
with:
context: .
file: ./deploy/Dockerfile.voice
push: true
tags: ${{ steps.meta_voice.outputs.tags }}
labels: ${{ steps.meta_voice.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
release:
name: Create Release
runs-on: ubuntu-latest
needs: [test, build]
if: github.event_name == 'push' && github.ref == 'refs/heads/master'
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare release binaries
run: |
mkdir -p release
for dir in artifacts/concord-*; do
if [ -d "$dir" ]; then
cp "$dir"/* release/ || true
fi
done
ls -la release/
cd release
sha256sum concord-* > checksums.txt
cd ..
- name: Generate release tag
id: tag
run: |
TAG="v$(date +'%Y%m%d')-${GITHUB_SHA::7}"
echo "tag=$TAG" >> $GITHUB_OUTPUT
echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ steps.tag.outputs.tag }}
name: Concord Release ${{ steps.tag.outputs.date }}
body: |
## Concord - Discord-like Voice & Chat Platform
Release includes both API and Voice server binaries for multiple platforms.
### API Server Downloads
- Linux (amd64): concord-api-linux-amd64
- Linux (arm64): concord-api-linux-arm64
- macOS (Intel): concord-api-darwin-amd64
- macOS (Apple Silicon): concord-api-darwin-arm64
- Windows: concord-api-windows-amd64.exe
### Voice Server Downloads
- Linux (amd64): concord-voice-linux-amd64
- Linux (arm64): concord-voice-linux-arm64
- macOS (Intel): concord-voice-darwin-amd64
- macOS (Apple Silicon): concord-voice-darwin-arm64
- Windows: concord-voice-windows-amd64.exe
### Quick Start
Download and run on Linux:
wget https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/concord-api-linux-amd64
chmod +x concord-api-linux-amd64
./concord-api-linux-amd64
### Verify Downloads
sha256sum -c checksums.txt
### Docker Images
docker pull ghcr.io/${{ github.repository_owner }}/concord-api:${{ github.sha }}
docker pull ghcr.io/${{ github.repository_owner }}/concord-voice:${{ github.sha }}
files: release/*
draft: false
prerelease: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}