Files
automatic-linkedin-answer-ai/.gitea/workflows/build-release.yml

81 lines
3.0 KiB
YAML

name: Build Docker Image and Release
on:
push:
tags:
- 'v*' # Triggers on version tags like v1.0.0
workflow_dispatch: # Allows manual triggering
jobs:
build-and-release:
runs-on: ubuntu-latest
permissions:
contents: write # Required to create/update releases
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Extract version from tag
id: tag_version
run: |
if [[ "${{ github.ref }}" == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
echo "version=$VERSION" >> $GITHUB_OUTPUT
else
VERSION="latest-$(date +%Y%m%d-%H%M%S)"
echo "version=$VERSION" >> $GITHUB_OUTPUT
fi
- name: Build Docker image
run: |
docker build -t automatic-linkedin-answer-ai:${{ steps.tag_version.outputs.version }} \
-t automatic-linkedin-answer-ai:latest .
- name: Save Docker image as tar
run: |
docker save automatic-linkedin-answer-ai:${{ steps.tag_version.outputs.version }} \
| gzip > automatic-linkedin-answer-ai-${{ steps.tag_version.outputs.version }}.tar.gz
ls -lh automatic-linkedin-answer-ai-*.tar.gz
- name: Create or update release (Gitea API)
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME=${GITHUB_REF#refs/tags/}
RELEASE_NAME="Release $TAG_NAME"
IMAGE_FILE="automatic-linkedin-answer-ai-$TAG_NAME.tar.gz"
# Check if release exists
RELEASE_ID=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"${{ github.api_url }}/repos/${{ github.repository }}/releases/tags/$TAG_NAME" \
| grep -o '"id":[0-9]*' | head -1 | cut -d':' -f2)
if [ -z "$RELEASE_ID" ]; then
# Create new release
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/json" \
-d "{\"tag_name\":\"$TAG_NAME\",\"name\":\"$RELEASE_NAME\",\"draft\":false,\"prerelease\":false}" \
"${{ github.api_url }}/repos/${{ github.repository }}/releases" > /tmp/release.json
RELEASE_ID=$(grep -o '"id":[0-9]*' /tmp/release.json | head -1 | cut -d':' -f2)
fi
# Upload asset
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Content-Type: application/gzip" \
--data-binary "@$IMAGE_FILE" \
"${{ github.api_url }}/repos/${{ github.repository }}/releases/$RELEASE_ID/assets?name=$IMAGE_FILE"
- name: Upload image artifact (for manual builds)
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v3
with:
name: docker-image
path: automatic-linkedin-answer-ai-*.tar.gz
retention-days: 30