name: Deploy on: push: branches: [main] workflow_dispatch: env: REGISTRY: forgejo.riotpiao.com IMAGE: forgejo.riotpiao.com/riotpiao-poimen/poimen-memory DOCKER_HOST: tcp://localhost:2375 jobs: deploy: name: Tag & Push Latest runs-on: rust steps: - name: Install Docker and curl run: apt-get update && apt-get install -y docker.io curl - name: Get short SHA via Gitea API id: sha run: | # Fetch latest commit SHA for main branch from Gitea API COMMIT_SHA=$(curl -s -H "Authorization: token ${REGISTRY_TOKEN}" \ "https://forgejo.riotpiao.com/api/v1/repos/riotpiao-poimen/poimen-memory/commits?sha=main&limit=1" | \ grep -o '"sha":"[^"]*' | head -1 | cut -d'"' -f4) if [ -z "$COMMIT_SHA" ]; then echo "ERROR: Failed to fetch commit SHA from Gitea API" exit 1 fi SHORT_SHA=$(echo "$COMMIT_SHA" | cut -c1-7) echo "short_sha=$SHORT_SHA" >> $GITHUB_OUTPUT echo "Full SHA: $COMMIT_SHA, Short: $SHORT_SHA" env: REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} - name: Registry login run: | if [ -z "${REGISTRY_USER}" ] || [ -z "${REGISTRY_TOKEN}" ]; then echo "ERROR: Missing REGISTRY_USER or REGISTRY_TOKEN secrets" exit 1 fi echo "${REGISTRY_TOKEN}" | docker login "${REGISTRY}" \ --username "${REGISTRY_USER}" --password-stdin env: REGISTRY_USER: ${{ secrets.FORGEJO_REGISTRY_USER }} REGISTRY_TOKEN: ${{ secrets.FORGEJO_REGISTRY_TOKEN }} - name: Verify SHA image exists, tag as latest run: | if ! docker pull "${IMAGE}:${{ steps.sha.outputs.short_sha }}"; then echo "ERROR: Image ${IMAGE}:${{ steps.sha.outputs.short_sha }} not found. Check build.yaml passed." exit 1 fi docker tag "${IMAGE}:${{ steps.sha.outputs.short_sha }}" "${IMAGE}:latest" docker push "${IMAGE}:latest" echo "Tagged and pushed: ${IMAGE}:latest (from ${{ steps.sha.outputs.short_sha }})" - name: Prune images run: docker image prune -a --force 2>&1 | tail -3 || true