1 - Add CI and build workflows for Forgejo Actions
This commit is contained in:
parent
47375e2b4d
commit
fa85decccb
2 changed files with 202 additions and 0 deletions
56
.forgejo/workflows/build.yml
Normal file
56
.forgejo/workflows/build.yml
Normal file
|
|
@ -0,0 +1,56 @@
|
||||||
|
name: Build and Push Docker Image
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [main]
|
||||||
|
tags: ['v*']
|
||||||
|
paths:
|
||||||
|
- 'Dockerfile'
|
||||||
|
- 'docker/**'
|
||||||
|
- 'app/**'
|
||||||
|
- 'bootstrap/**'
|
||||||
|
- 'config/**'
|
||||||
|
- 'database/**'
|
||||||
|
- 'packages/**'
|
||||||
|
- 'public/**'
|
||||||
|
- 'resources/**'
|
||||||
|
- 'routes/**'
|
||||||
|
- 'composer.lock'
|
||||||
|
- 'package-lock.json'
|
||||||
|
- '.forgejo/workflows/build.yml'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
steps:
|
||||||
|
- uses: https://data.forgejo.org/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: https://data.forgejo.org/docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Login to Forgejo Registry
|
||||||
|
uses: https://data.forgejo.org/docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: forge.lvl0.xyz
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Determine tags
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
if [[ "${{ github.ref }}" == refs/tags/v* ]]; then
|
||||||
|
TAG="${{ github.ref_name }}"
|
||||||
|
echo "tags=forge.lvl0.xyz/lvl0/trove:${TAG},forge.lvl0.xyz/lvl0/trove:latest" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "tags=forge.lvl0.xyz/lvl0/trove:latest" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Build and push
|
||||||
|
uses: https://data.forgejo.org/docker/build-push-action@v5
|
||||||
|
with:
|
||||||
|
context: .
|
||||||
|
file: Dockerfile
|
||||||
|
push: true
|
||||||
|
tags: ${{ steps.meta.outputs.tags }}
|
||||||
146
.forgejo/workflows/ci.yml
Normal file
146
.forgejo/workflows/ci.yml
Normal file
|
|
@ -0,0 +1,146 @@
|
||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: ['release/*']
|
||||||
|
pull_request:
|
||||||
|
branches: [main]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
ci:
|
||||||
|
runs-on: docker
|
||||||
|
container:
|
||||||
|
image: catthehacker/ubuntu:act-latest
|
||||||
|
|
||||||
|
services:
|
||||||
|
db:
|
||||||
|
image: postgres:17-alpine
|
||||||
|
env:
|
||||||
|
POSTGRES_DB: trove
|
||||||
|
POSTGRES_USER: trove
|
||||||
|
POSTGRES_PASSWORD: trove
|
||||||
|
redis:
|
||||||
|
image: redis:7-alpine
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: https://data.forgejo.org/actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up PHP
|
||||||
|
uses: https://github.com/shivammathur/setup-php@v2
|
||||||
|
with:
|
||||||
|
php-version: '8.3'
|
||||||
|
extensions: pdo_pgsql, pdo_sqlite, redis, mbstring, xml, dom, intl, gd, zip
|
||||||
|
coverage: pcov
|
||||||
|
|
||||||
|
- name: Cache Composer dependencies
|
||||||
|
uses: https://data.forgejo.org/actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.composer/cache
|
||||||
|
key: composer-${{ hashFiles('composer.lock') }}
|
||||||
|
restore-keys: composer-
|
||||||
|
|
||||||
|
- name: Install Composer dependencies
|
||||||
|
run: composer install --no-interaction --prefer-dist
|
||||||
|
|
||||||
|
- name: Cache npm dependencies
|
||||||
|
uses: https://data.forgejo.org/actions/cache@v4
|
||||||
|
with:
|
||||||
|
path: ~/.npm
|
||||||
|
key: npm-${{ hashFiles('package-lock.json') }}
|
||||||
|
restore-keys: npm-
|
||||||
|
|
||||||
|
- name: Install npm dependencies
|
||||||
|
run: npm ci
|
||||||
|
|
||||||
|
- name: Build assets
|
||||||
|
run: npm run build
|
||||||
|
|
||||||
|
- name: Prepare environment
|
||||||
|
run: |
|
||||||
|
cp .env.example .env
|
||||||
|
php artisan key:generate
|
||||||
|
|
||||||
|
- name: Wait for services
|
||||||
|
run: |
|
||||||
|
until pg_isready -h db -U trove; do sleep 1; done
|
||||||
|
until redis-cli -h redis ping | grep -q PONG; do sleep 1; done
|
||||||
|
|
||||||
|
- name: Lint (Pint)
|
||||||
|
run: vendor/bin/pint --test
|
||||||
|
|
||||||
|
- name: Static analysis (PHPStan)
|
||||||
|
run: vendor/bin/phpstan analyse --memory-limit=512M
|
||||||
|
|
||||||
|
- name: Tests with coverage
|
||||||
|
env:
|
||||||
|
DB_HOST: db
|
||||||
|
REDIS_HOST: redis
|
||||||
|
run: php artisan test --coverage-clover coverage.xml --coverage-text
|
||||||
|
|
||||||
|
- name: Parse coverage
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
id: coverage
|
||||||
|
run: |
|
||||||
|
COVERAGE=$(php -r '
|
||||||
|
$xml = simplexml_load_file("coverage.xml");
|
||||||
|
if ($xml === false || !isset($xml->project->metrics)) {
|
||||||
|
echo "0";
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
$metrics = $xml->project->metrics;
|
||||||
|
$statements = (int) $metrics["statements"];
|
||||||
|
$covered = (int) $metrics["coveredstatements"];
|
||||||
|
echo $statements > 0 ? round(($covered / $statements) * 100, 2) : 0;
|
||||||
|
')
|
||||||
|
echo "percentage=$COVERAGE" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
|
- name: Comment coverage on PR
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
continue-on-error: true
|
||||||
|
env:
|
||||||
|
FORGEJO_TOKEN: ${{ secrets.FORGEJO_TOKEN }}
|
||||||
|
PR_NUMBER: ${{ github.event.pull_request.number }}
|
||||||
|
COVERAGE: ${{ steps.coverage.outputs.percentage }}
|
||||||
|
REPO: ${{ github.repository }}
|
||||||
|
SERVER_URL: ${{ github.server_url }}
|
||||||
|
COMMIT_SHA: ${{ github.sha }}
|
||||||
|
run: |
|
||||||
|
API_URL="${SERVER_URL}/api/v1/repos/${REPO}/issues/${PR_NUMBER}/comments"
|
||||||
|
MARKER="<!-- trove-ci-coverage-report -->"
|
||||||
|
|
||||||
|
BODY="${MARKER}
|
||||||
|
## Code Coverage Report
|
||||||
|
|
||||||
|
| Metric | Value |
|
||||||
|
|--------|-------|
|
||||||
|
| **Line Coverage** | ${COVERAGE}% |
|
||||||
|
|
||||||
|
_Updated by CI — commit ${COMMIT_SHA}_"
|
||||||
|
|
||||||
|
# Find existing coverage comment
|
||||||
|
EXISTING=$(curl -sf -H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
"${API_URL}?limit=50" | \
|
||||||
|
php -r '
|
||||||
|
$comments = json_decode(file_get_contents("php://stdin"), true);
|
||||||
|
if (!is_array($comments)) exit;
|
||||||
|
foreach ($comments as $c) {
|
||||||
|
if (str_contains($c["body"], "<!-- trove-ci-coverage-report -->")) {
|
||||||
|
echo $c["id"];
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
' || true)
|
||||||
|
|
||||||
|
if [ -n "$EXISTING" ]; then
|
||||||
|
curl -sf -X PATCH \
|
||||||
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$(php -r 'echo json_encode(["body" => $argv[1]]);' "$BODY")" \
|
||||||
|
"${SERVER_URL}/api/v1/repos/${REPO}/issues/comments/${EXISTING}" > /dev/null
|
||||||
|
else
|
||||||
|
curl -sf -X POST \
|
||||||
|
-H "Authorization: token ${FORGEJO_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$(php -r 'echo json_encode(["body" => $argv[1]]);' "$BODY")" \
|
||||||
|
"${API_URL}" > /dev/null
|
||||||
|
fi
|
||||||
Loading…
Reference in a new issue