name: Docker build and release on: push: branches: [main] jobs: build-and-push: runs-on: ubuntu-latest permissions: contents: read packages: write outputs: tag: ${{ steps.meta.outputs.tag }} steps: - name: Checkout uses: https://gitea.com/actions/checkout@v4 with: fetch-depth: 0 - name: Set release tag id: meta run: | echo "tag=v$(date +%Y%m%d)-${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT - name: Extract registry host id: registry run: | echo "host=${GITHUB_SERVER_URL#https://}" >> $GITHUB_OUTPUT # REGISTRY_TOKEN: Personal Access Token с правом write:package (или токен из Package Registry) - name: Log in to Gitea Container Registry run: | if [ -z "${{ secrets.REGISTRY_TOKEN }}" ]; then echo "::error::REGISTRY_TOKEN не задан. Добавьте секрет с токеном (scope: write:package)." exit 1 fi echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ steps.registry.outputs.host }} -u ${{ github.actor }} --password-stdin - name: Build and push run: | REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]') IMAGE="${{ steps.registry.outputs.host }}/$REPO_LOWER" TAG="${{ steps.meta.outputs.tag }}" docker build -t "$IMAGE:$TAG" -t "$IMAGE:latest" . docker push "$IMAGE:$TAG" docker push "$IMAGE:latest" release: runs-on: ubuntu-latest needs: build-and-push permissions: contents: write steps: - name: Checkout uses: https://gitea.com/actions/checkout@v4 with: fetch-depth: 0 - name: Generate release notes id: notes run: | PREV=$(git describe --tags --abbrev=0 2>/dev/null || echo "") if [ -z "$PREV" ]; then echo "## Changes" > release_notes.md echo "" >> release_notes.md git log --pretty=format:"- %s (%h)" >> release_notes.md || echo "- Initial release" >> release_notes.md else echo "## Changes since $PREV" > release_notes.md echo "" >> release_notes.md git log "$PREV"..HEAD --pretty=format:"- %s (%h)" >> release_notes.md fi - name: Create release uses: https://gitea.com/actions/gitea-release-action@v1 with: token: ${{ secrets.REGISTRY_TOKEN }} tag_name: ${{ needs.build-and-push.outputs.tag }} body_path: release_notes.md target_commitish: ${{ github.sha }}