Обновить Gitea Actions, compose и URL репозитория. Co-authored-by: Cursor <[email protected]>
101 lines
3.6 KiB
YAML
101 lines
3.6 KiB
YAML
name: Build and Push EvoFirewall Docker Image
|
|
|
|
on:
|
|
push:
|
|
branches: [main, develop, 'feature/**', 'release/**', 'hotfix/**']
|
|
tags: ['v*']
|
|
paths: ['**']
|
|
pull_request:
|
|
branches: [main, develop]
|
|
paths: ['**']
|
|
|
|
jobs:
|
|
build-and-push:
|
|
if: startsWith(gitea.ref, 'refs/tags/v') || (gitea.ref_name == 'main' && gitea.event_name == 'push')
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to Gitea Registry
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: git.shx.one
|
|
username: ${{ gitea.actor }}
|
|
password: ${{ secrets.ACTIONS_PAT }}
|
|
|
|
- name: Create version file
|
|
run: |
|
|
VERSION=$(cat VERSION)
|
|
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
|
|
BRANCH="${{ gitea.ref_name }}"
|
|
echo "APP_VERSION=${VERSION}" > ./version.txt
|
|
echo "BUILD_DATE=${BUILD_DATE}" >> ./version.txt
|
|
echo "GIT_BRANCH=${BRANCH}" >> ./version.txt
|
|
echo "GIT_COMMIT=${{ gitea.sha }}" >> ./version.txt
|
|
echo "GIT_COMMIT_SHORT=$(echo ${{ gitea.sha }} | cut -c1-7)" >> ./version.txt
|
|
echo "BUILD_TIMESTAMP=$(date -u +%s)" >> ./version.txt
|
|
|
|
# Docker registry refs must be lowercase (repo name is EvoFirewall).
|
|
- name: Lowercase image repository
|
|
id: image
|
|
run: echo "repo=$(echo '${{ gitea.repository }}' | tr '[:upper:]' '[:lower:]')" >> "$GITHUB_OUTPUT"
|
|
|
|
- name: Docker meta
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: git.shx.one/${{ steps.image.outputs.repo }}
|
|
tags: |
|
|
type=semver,pattern={{version}}
|
|
type=raw,value=latest,enable=${{ gitea.ref_name == 'main' }}
|
|
type=sha,prefix={{date 'YYYYMMDD'}}-,enable=${{ gitea.ref_name == 'main' }}
|
|
|
|
- name: Build and push Docker image
|
|
uses: docker/build-push-action@v5
|
|
with:
|
|
context: .
|
|
file: ./Dockerfile
|
|
push: true
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|
|
build-args: |
|
|
NODE_VERSION=22.23.0-bookworm-slim
|
|
cache-from: type=registry,ref=git.shx.one/${{ steps.image.outputs.repo }}:buildcache
|
|
cache-to: type=registry,ref=git.shx.one/${{ steps.image.outputs.repo }}:buildcache,mode=max
|
|
provenance: true
|
|
|
|
create-release:
|
|
needs: build-and-push
|
|
if: startsWith(gitea.ref, 'refs/tags/v')
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Generate changelog
|
|
id: changelog
|
|
run: |
|
|
LAST_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "")
|
|
if [[ -n "$LAST_TAG" ]]; then
|
|
CHANGELOG=$(git log --pretty=format:"- %s (%h)" ${LAST_TAG}..HEAD)
|
|
else
|
|
CHANGELOG=$(git log --pretty=format:"- %s (%h)" -n 20)
|
|
fi
|
|
echo "CHANGELOG<<EOF" >> $GITHUB_OUTPUT
|
|
echo "$CHANGELOG" >> $GITHUB_OUTPUT
|
|
echo "EOF" >> $GITHUB_OUTPUT
|
|
|
|
- name: Create Gitea Release
|
|
run: |
|
|
curl -X POST \
|
|
-H "Authorization: token ${{ secrets.GITEA_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
"https://git.shx.one/api/v1/repos/${{ gitea.repository }}/releases" \
|
|
-d "{\"tag_name\":\"${{ gitea.ref_name }}\",\"name\":\"${{ gitea.ref_name }}\",\"body\":$(echo '${{ steps.changelog.outputs.CHANGELOG }}' | jq -Rs .)}"
|