chore: add gitea ci/cd skeleton
Some checks failed
CI / commitlint (pull_request) Has been cancelled
CI / lint (pull_request) Has been cancelled
CI / test (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / commitlint (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
Some checks failed
CI / commitlint (pull_request) Has been cancelled
CI / lint (pull_request) Has been cancelled
CI / test (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / commitlint (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled
This commit is contained in:
173
.gitea/workflows/ci.yml
Normal file
173
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,173 @@
|
||||
name: CI
|
||||
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
env:
|
||||
REGISTRY: ${{ secrets.DOCKER_REGISTRY || 'registry.local' }}
|
||||
IMAGE_NAME: ${{ secrets.DOCKER_IMAGE || 'mon-projet' }}
|
||||
|
||||
jobs:
|
||||
commitlint:
|
||||
runs-on: docker
|
||||
env:
|
||||
FROM_REF: ${{ github.event.pull_request.base.sha || github.event.before || '' }}
|
||||
TO_REF: ${{ github.sha }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Run commitlint (conventional commits)
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
from="${FROM_REF}"
|
||||
if [ -z "$from" ]; then
|
||||
from="HEAD~1"
|
||||
fi
|
||||
docker run --rm -v "$PWD:/workspace" -w /workspace ghcr.io/conventional-changelog/commitlint:latest --from "$from" --to "$TO_REF"
|
||||
|
||||
lint:
|
||||
runs-on: docker
|
||||
needs: commitlint
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup tools
|
||||
run: |
|
||||
echo "TODO: installer vos dépendances de lint (npm ci, pip install -r requirements.txt, etc.)"
|
||||
|
||||
- name: Lint
|
||||
run: |
|
||||
echo "TODO: remplacer par la commande réelle de lint, ex: npm run lint"
|
||||
|
||||
test:
|
||||
runs-on: docker
|
||||
needs: lint
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
echo "TODO: installer les dépendances de test"
|
||||
|
||||
- name: Test
|
||||
run: |
|
||||
echo "TODO: remplacer par la commande réelle de tests, ex: npm test"
|
||||
|
||||
build:
|
||||
runs-on: docker
|
||||
needs: test
|
||||
env:
|
||||
DOCKER_USER: ${{ secrets.DOCKER_USERNAME }}
|
||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||
DOCKER_REGISTRY: ${{ env.REGISTRY }}
|
||||
DOCKER_IMAGE: ${{ env.IMAGE_NAME }}
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Fetch tags
|
||||
run: git fetch --tags --force
|
||||
|
||||
- name: Compute next version (semver)
|
||||
id: version
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
||||
if [ -z "$last_tag" ]; then
|
||||
base="v0.0.0"
|
||||
commits=$(git log --format=%s%n%b HEAD)
|
||||
else
|
||||
base="$last_tag"
|
||||
commits=$(git log --format=%s%n%b "${last_tag}..HEAD")
|
||||
fi
|
||||
|
||||
bump="patch"
|
||||
if echo "$commits" | grep -qiE "(^| )feat!"; then
|
||||
bump="major"
|
||||
elif echo "$commits" | grep -qiE "BREAKING CHANGE"; then
|
||||
bump="major"
|
||||
elif echo "$commits" | grep -qiE "^feat:"; then
|
||||
bump="minor"
|
||||
elif echo "$commits" | grep -qiE "^fix:"; then
|
||||
bump="patch"
|
||||
fi
|
||||
|
||||
semver="${base#v}"
|
||||
major=${semver%%.*}
|
||||
minor=${semver#*.}; minor=${minor%%.*}
|
||||
patch=${semver##*.}
|
||||
|
||||
case "$bump" in
|
||||
major) major=$((major+1)); minor=0; patch=0 ;;
|
||||
minor) minor=$((minor+1)); patch=0 ;;
|
||||
patch) patch=$((patch+1)) ;;
|
||||
esac
|
||||
|
||||
next="v${major}.${minor}.${patch}"
|
||||
echo "next=$next" >> "$GITHUB_OUTPUT"
|
||||
|
||||
- name: Docker login
|
||||
if: env.DOCKER_USER != '' && env.DOCKER_PASSWORD != ''
|
||||
run: |
|
||||
echo "${DOCKER_PASSWORD}" | docker login "${DOCKER_REGISTRY}" -u "${DOCKER_USER}" --password-stdin
|
||||
|
||||
- name: Build Docker image (latest)
|
||||
run: docker build -t "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest" -f Dockerfile .
|
||||
|
||||
- name: Build Docker image (versioned)
|
||||
run: docker build -t "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${{ steps.version.outputs.next }}" -f Dockerfile .
|
||||
|
||||
- name: Push Docker images
|
||||
if: github.event_name == 'push'
|
||||
run: |
|
||||
docker push "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:latest"
|
||||
docker push "${DOCKER_REGISTRY}/${DOCKER_IMAGE}:${{ steps.version.outputs.next }}"
|
||||
|
||||
- name: Generate changelog
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
id: changelog
|
||||
shell: bash
|
||||
run: |
|
||||
last_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
|
||||
if [ -z "$last_tag" ]; then
|
||||
range="HEAD"
|
||||
last_tag="initial"
|
||||
else
|
||||
range="${last_tag}..HEAD"
|
||||
fi
|
||||
{
|
||||
echo "Changelog since $last_tag"
|
||||
git log --pretty=format:"- %s" $range
|
||||
} > changelog.md
|
||||
|
||||
- name: Create and push tag
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
env:
|
||||
TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
SERVER_URL: ${{ github.server_url }}
|
||||
REPOSITORY: ${{ github.repository }}
|
||||
shell: bash
|
||||
run: |
|
||||
set -euo pipefail
|
||||
tag="${{ steps.version.outputs.next }}"
|
||||
git tag -a "$tag" -m "Release $tag"
|
||||
origin="${SERVER_URL#https://}"
|
||||
origin="${origin#http://}"
|
||||
git push "https://oauth2:${TOKEN}@${origin}/${REPOSITORY}" "$tag"
|
||||
|
||||
- name: Upload changelog
|
||||
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: changelog
|
||||
path: changelog.md
|
||||
Reference in New Issue
Block a user