name: Build Docker Linux ARM64 Release
run-name: Release-Docker-Linux-ARM64

on:
  push:
    tags: [ "v*" ]

jobs:
  build-docker-linux-arm64-release:
    runs-on: [self-hosted, linux, arm64, docker]
    steps:
      - name: Install packages
        run: apk add --no-cache git curl wget unzip bash nodejs npm docker

      - name: Clone the repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Get Version
        id: get_version
        run: |
          VERSION=${GITHUB_REF#refs/tags/}
          echo "VERSION=$VERSION" >> $GITHUB_ENV
          echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV

      - name: Login to own image registry
        uses: docker/login-action@v3
        with:
          registry: gitea.penry.de
          username: ${{ secrets.REGISTRY_USER }}
          password: ${{ secrets.REGISTRY_PASSWORD }}

      - name: Setup .NET10
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: '10.0.x'

      - name: Build Linux ARM64 Docker Image
        run: |
          docker build \
            -t gitea.penry.de/${{ env.REPO_LC }}:${{ env.VERSION }} \
            -t gitea.penry.de/${{ env.REPO_LC }}:latest \
            --label "org.opencontainers.image.source=https://gitea.penry.de/${{ github.repository }}" \
            .

      - name: Push Images
        run: |
          docker push gitea.penry.de/${{ env.REPO_LC }}:${{ env.VERSION }}
          docker push gitea.penry.de/${{ env.REPO_LC }}:latest

      - name: Make Tar from image
        run: |
          docker save -o couchlog-linux-arm64-${{ env.VERSION }}.tar gitea.penry.de/${{ env.REPO_LC }}:${{ env.VERSION }}

      - name: Release
        if: startsWith(github.ref, 'refs/tags/v')
        uses: akkuman/gitea-release-action@v1
        with:
          files: |-
            couchlog-linux-arm64-${{ env.VERSION }}.tar