mirror of
https://github.com/Alexander-D-Karpov/webring.git
synced 2026-03-16 22:07:41 +03:00
245 lines
6.4 KiB
YAML
245 lines
6.4 KiB
YAML
name: CI/CD Pipeline
|
|
|
|
on:
|
|
push:
|
|
branches: [ main, master ]
|
|
pull_request:
|
|
branches: [ main, master ]
|
|
workflow_dispatch:
|
|
|
|
env:
|
|
GO_VERSION: '1.25.0'
|
|
|
|
permissions:
|
|
contents: read
|
|
|
|
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: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Run 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:15
|
|
env:
|
|
POSTGRES_PASSWORD: postgres
|
|
POSTGRES_USER: postgres
|
|
POSTGRES_DB: webring_test
|
|
options: >-
|
|
--health-cmd pg_isready
|
|
--health-interval 10s
|
|
--health-timeout 5s
|
|
--health-retries 5
|
|
ports:
|
|
- 5432:5432
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Install migrate tool
|
|
run: go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest
|
|
|
|
- name: Run migrations
|
|
env:
|
|
DB_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/webring_test?sslmode=disable
|
|
run: |
|
|
migrate -database "$DB_CONNECTION_STRING" -path migrations up
|
|
|
|
- name: Run tests
|
|
env:
|
|
DB_CONNECTION_STRING: postgres://postgres:postgres@localhost:5432/webring_test?sslmode=disable
|
|
CHECKER_DEBUG: "false"
|
|
LOG_FILE_PATH: test.log
|
|
TELEGRAM_BOT_TOKEN: ""
|
|
TELEGRAM_BOT_USERNAME: ""
|
|
PORT: "8080"
|
|
MEDIA_FOLDER: "media"
|
|
SESSION_TTL_HOURS: "2160"
|
|
SESSION_SECURE_COOKIE: "false"
|
|
run: go test -v -race -coverprofile=coverage.out ./...
|
|
|
|
- name: Upload coverage
|
|
uses: codecov/codecov-action@v4
|
|
with:
|
|
file: ./coverage.out
|
|
fail_ci_if_error: false
|
|
token: ${{ secrets.CODECOV_TOKEN }}
|
|
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
|
|
strategy:
|
|
matrix:
|
|
include:
|
|
- goos: linux
|
|
goarch: amd64
|
|
- goos: linux
|
|
goarch: arm64
|
|
- goos: darwin
|
|
goarch: amd64
|
|
- goos: darwin
|
|
goarch: arm64
|
|
- goos: windows
|
|
goarch: amd64
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v5
|
|
with:
|
|
go-version: ${{ env.GO_VERSION }}
|
|
cache: true
|
|
|
|
- name: Build binary
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
run: |
|
|
BINARY_NAME="webring-${{ 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/server/main.go
|
|
|
|
- name: Upload artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: webring-${{ matrix.goos }}-${{ matrix.goarch }}
|
|
path: webring-*
|
|
retention-days: 7
|
|
|
|
docker:
|
|
name: Docker Build
|
|
runs-on: ubuntu-latest
|
|
needs: test
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Build Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
push: false
|
|
tags: webring:latest
|
|
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/main' || 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
|
|
|
|
# Copy all binaries to release folder with clear names
|
|
for dir in artifacts/webring-*; do
|
|
if [ -d "$dir" ]; then
|
|
cp "$dir"/* release/ || true
|
|
fi
|
|
done
|
|
|
|
# List files for debugging
|
|
ls -la release/
|
|
|
|
# Create checksums file
|
|
cd release
|
|
sha256sum webring-* > 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@v2
|
|
with:
|
|
tag_name: ${{ steps.tag.outputs.tag }}
|
|
name: Release ${{ steps.tag.outputs.date }}
|
|
body: |
|
|
## Webring Release
|
|
|
|
### Download Instructions
|
|
|
|
**Linux (amd64):**
|
|
```bash
|
|
wget https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/webring-linux-amd64
|
|
chmod +x webring-linux-amd64
|
|
./webring-linux-amd64
|
|
```
|
|
|
|
**Linux (arm64):**
|
|
```bash
|
|
wget https://github.com/${{ github.repository }}/releases/download/${{ steps.tag.outputs.tag }}/webring-linux-arm64
|
|
chmod +x webring-linux-arm64
|
|
./webring-linux-arm64
|
|
```
|
|
|
|
**macOS (Intel):** `webring-darwin-amd64`
|
|
**macOS (Apple Silicon):** `webring-darwin-arm64`
|
|
**Windows:** `webring-windows-amd64.exe`
|
|
|
|
### Verify Download
|
|
Check the `checksums.txt` file to verify your download:
|
|
```bash
|
|
sha256sum -c checksums.txt
|
|
```
|
|
files: release/*
|
|
draft: false
|
|
prerelease: true
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |