From 4398579dc9f31279dabd5ed3fe60dd3ae24aca42 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Mon, 26 May 2025 03:15:54 -0400 Subject: [PATCH] Build attempt --- .gitea/workflows/release.yml | 127 +++++++++++++++++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..e0a166a --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,127 @@ +# .gitea/workflows/release.yml + +name: Build and Release Docker Image + +on: + push: + branches: + - main # Or your default branch, e.g., master + tags: + - 'v*.*.*' # Trigger on version tags like v1.0.0, v1.2.3-alpha + pull_request: # Optional: build on PRs for testing, no push or release + branches: + - main # Or your default branch + +env: + # Assumes your Gitea instance FQDN is correctly identified by gitea.instance + # e.g., gitea.example.com + # The image will be named: //: + REGISTRY_HOST: ${{ gitea.instance }} + IMAGE_NAME_PATH: ${{ gitea.owner }}/${{ gitea.repository_name }} + +jobs: + build-and-push-image: + runs-on: ubuntu-latest # Ensure your Gitea runner supports Docker + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + # Ensure GITEA_TOKEN secret is created in your repository settings. + # It needs permissions to write to packages (container registry). + # gitea.actor is the user who triggered the workflow. + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY_HOST }} + username: ${{ gitea.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY_HOST }}/${{ env.IMAGE_NAME_PATH }} + tags: | + # For pushes to the default branch (e.g., main) + type=raw,value=latest,enable={{is_default_branch}} + type=sha,prefix=,format=short,enable={{is_default_branch}} # e.g., sha-1234567 + + # For version tags like v1.2.3 + # Produces: 1.2.3 from tag v1.2.3 + type=semver,pattern={{version}} + # Produces: 1.2 from tag v1.2.3 + type=semver,pattern={{major}}.{{minor}} + # Produces: 1 from tag v1.2.3 + type=semver,pattern={{major}} + # Also tag vX.Y.Z as 'latest' + type=raw,value=latest,enable=${{ startsWith(gitea.ref, 'refs/tags/v') }} + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + # Only push if it's not a pull request event + push: ${{ gitea.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + # Enable build cache using Gitea Actions cache + cache-from: type=gha + cache-to: type=gha,mode=max + + create-gitea-release: + needs: build-and-push-image + # Only run this job if the trigger was a tag push matching 'v*.*.*' + if: startsWith(gitea.ref, 'refs/tags/v') + runs-on: ubuntu-latest + steps: + - name: Get tag name + id: get_tag + # GITEA_REF is like 'refs/tags/v1.2.3', this extracts 'v1.2.3' + run: echo "TAG_NAME=${GITEA_REF#refs/tags/}" >> $GITEA_ENV + + - name: Create Gitea Release + env: + # GITEA_TOKEN needs permissions to create releases (e.g., repository:write). + # It can be the same token used for registry login if it has sufficient scope. + GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} + TAG_NAME: ${{ env.TAG_NAME }} # From previous step + OWNER: ${{ gitea.owner }} + REPO: ${{ gitea.repository_name }} + # gitea.server_url is like https://gitea.example.com + GITEA_API_URL: ${{ gitea.server_url }}/api/v1 + run: | + echo "Creating Gitea release for tag: $TAG_NAME" + RELEASE_API_ENDPOINT="$GITEA_API_URL/repos/$OWNER/$REPO/releases" + + # You can customize the release body, e.g., by fetching changelog notes + RELEASE_BODY="Official release for version $TAG_NAME." + + # Create the release using Gitea API + response=$(curl --request POST \ + --url "$RELEASE_API_ENDPOINT" \ + --header "Authorization: token $GITEA_TOKEN" \ + --header "Content-Type: application/json" \ + --data @- <