feat #6
112
.gitea/workflows/README.md
Normal file
112
.gitea/workflows/README.md
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
# Gitea Actions Workflows
|
||||||
|
|
||||||
|
## Workflows
|
||||||
|
|
||||||
|
### 1. CI (`ci.yml`)
|
||||||
|
**Triggers:** Push/PR to `main`, `rewrite`, `feat` branches
|
||||||
|
|
||||||
|
**Jobs:**
|
||||||
|
- Install dependencies
|
||||||
|
- Lint code
|
||||||
|
- Build application
|
||||||
|
- Run unit tests (Vitest)
|
||||||
|
- Run E2E tests (Playwright)
|
||||||
|
- Upload test results as artifacts
|
||||||
|
|
||||||
|
### 2. Docker Build (`docker-build.yml`)
|
||||||
|
**Triggers:**
|
||||||
|
- Tags matching `v*` (e.g., `v1.0.0`)
|
||||||
|
- Push to `main` branch
|
||||||
|
|
||||||
|
**Jobs:**
|
||||||
|
- Build React application
|
||||||
|
- Build Docker image
|
||||||
|
- Push to Docker registry
|
||||||
|
|
||||||
|
**Required Secrets:**
|
||||||
|
- `DOCKER_USERNAME` - Docker registry username
|
||||||
|
- `DOCKER_PASSWORD` - Docker registry password/token
|
||||||
|
|
||||||
|
**Optional Variables:**
|
||||||
|
- `DOCKER_REGISTRY` - Registry URL (default: `docker.io`)
|
||||||
|
|
||||||
|
### 3. Deploy (`deploy.yml`)
|
||||||
|
**Triggers:** Push to `main` branch
|
||||||
|
|
||||||
|
**Jobs:**
|
||||||
|
- SSH to deployment server
|
||||||
|
- Pull latest code
|
||||||
|
- Update Docker containers
|
||||||
|
- Clean up old images
|
||||||
|
|
||||||
|
**Required Secrets:**
|
||||||
|
- `DEPLOY_HOST` - Server hostname/IP
|
||||||
|
- `DEPLOY_USERNAME` - SSH username
|
||||||
|
- `DEPLOY_KEY` - SSH private key
|
||||||
|
|
||||||
|
**Optional Secrets:**
|
||||||
|
- `DEPLOY_PORT` - SSH port (default: 22)
|
||||||
|
|
||||||
|
## Setup Instructions
|
||||||
|
|
||||||
|
### 1. Enable Gitea Actions
|
||||||
|
Make sure Actions is enabled in your Gitea instance:
|
||||||
|
```ini
|
||||||
|
[actions]
|
||||||
|
ENABLED = true
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. Configure Secrets
|
||||||
|
Go to your repository → Settings → Secrets and add:
|
||||||
|
|
||||||
|
**For Docker Build:**
|
||||||
|
```
|
||||||
|
DOCKER_USERNAME=your-username
|
||||||
|
DOCKER_PASSWORD=your-password-or-token
|
||||||
|
```
|
||||||
|
|
||||||
|
**For Deployment:**
|
||||||
|
```
|
||||||
|
DEPLOY_HOST=your-server.com
|
||||||
|
DEPLOY_USERNAME=deploy
|
||||||
|
DEPLOY_KEY=<paste-ssh-private-key>
|
||||||
|
DEPLOY_PORT=22
|
||||||
|
```
|
||||||
|
|
||||||
|
### 3. Configure Variables (Optional)
|
||||||
|
Go to your repository → Settings → Variables and add:
|
||||||
|
|
||||||
|
```
|
||||||
|
DOCKER_REGISTRY=registry.example.com
|
||||||
|
```
|
||||||
|
|
||||||
|
## Workflow Files Location
|
||||||
|
`.gitea/workflows/`
|
||||||
|
|
||||||
|
## Testing Workflows Locally
|
||||||
|
|
||||||
|
You can test workflows locally using [act](https://github.com/nektos/act):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Install act
|
||||||
|
brew install act
|
||||||
|
|
||||||
|
# Run CI workflow locally
|
||||||
|
act push
|
||||||
|
|
||||||
|
# Run with specific job
|
||||||
|
act -j build-and-test
|
||||||
|
|
||||||
|
# Run with verbose output
|
||||||
|
act -v
|
||||||
|
```
|
||||||
|
|
||||||
|
## Badge Examples
|
||||||
|
|
||||||
|
Add these to your README.md:
|
||||||
|
|
||||||
|
```markdown
|
||||||
|
[](https://git.six83.ru/ssa/configucci/actions/workflows/ci.yml)
|
||||||
|
[](https://git.six83.ru/ssa/configucci/actions/workflows/docker-build.yml)
|
||||||
|
[](https://git.six83.ru/ssa/configucci/actions/workflows/deploy.yml)
|
||||||
|
```
|
||||||
46
.gitea/workflows/ci.yml
Normal file
46
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main, rewrite, feat]
|
||||||
|
pull_request:
|
||||||
|
branches: [main, rewrite, feat]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-test:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Lint
|
||||||
|
run: npm run lint
|
||||||
|
|
||||||
|
- name: Build
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Run unit tests
|
||||||
|
run: npm run test
|
||||||
|
|
||||||
|
- name: Install Playwright browsers
|
||||||
|
run: npx playwright install --with-deps chromium
|
||||||
|
|
||||||
|
- name: Run E2E tests
|
||||||
|
run: npm run test:e2e
|
||||||
|
|
||||||
|
- name: Upload test results
|
||||||
|
if: always()
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: test-results
|
||||||
|
path: test-results/
|
||||||
28
.gitea/workflows/deploy.yml
Normal file
28
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
name: Deploy to Server
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Deploy via SSH
|
||||||
|
uses: appleboy/ssh-action@v1.0.3
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
username: ${{ secrets.DEPLOY_USERNAME }}
|
||||||
|
key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
port: ${{ secrets.DEPLOY_PORT || 22 }}
|
||||||
|
script: |
|
||||||
|
cd /opt/configucci
|
||||||
|
git pull origin main
|
||||||
|
docker-compose pull
|
||||||
|
docker-compose up -d
|
||||||
|
docker system prune -f
|
||||||
59
.gitea/workflows/docker-build.yml
Normal file
59
.gitea/workflows/docker-build.yml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
tags:
|
||||||
|
- 'v*'
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-push:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Setup Node.js
|
||||||
|
uses: actions/setup-node@v4
|
||||||
|
with:
|
||||||
|
node-version: '20'
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build application
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Docker Registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: ${{ vars.DOCKER_REGISTRY || 'docker.io' }}
|
||||||
|
username: ${{ secrets.DOCKER_USERNAME }}
|
||||||
|
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
|
|
||||||
|
- name: Extract metadata
|
||||||
|
id: meta
|
||||||
|
uses: docker/metadata-action@v5
|
||||||
|
with:
|
||||||
|
images: ${{ vars.DOCKER_REGISTRY }}/${{ github.repository }}
|
||||||
|
tags: |
|
||||||
|
type=ref,event=branch
|
||||||
|
type=semver,pattern={{version}}
|
||||||
|
type=semver,pattern={{major}}.{{minor}}
|
||||||
|
type=sha,prefix=sha-
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
uses: docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
|
labels: ${{ steps.meta.outputs.labels }}
|
||||||
|
cache-from: type=gha
|
||||||
|
cache-to: type=gha,mode=max
|
||||||
Reference in New Issue
Block a user