name: Develop

on:
  push:
    branches:
      - develop
  workflow_dispatch:

concurrency:
  group: develop-${{ github.ref }}
  cancel-in-progress: true

permissions:
  contents: read
  packages: write

env:
  IMAGE: ghcr.io/vvzvlad/gitmost

jobs:
  # Run the reusable test suite first so a failing test blocks the image build.
  test:
    uses: ./.github/workflows/test.yml

  build:
    needs: test
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3

      - name: Login to GitHub Container Registry
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.repository_owner }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Resolve version
        id: version
        run: echo "value=$(git describe --tags --always)" >> "$GITHUB_OUTPUT"

      - name: Build and push develop image
        uses: docker/build-push-action@v6
        with:
          context: .
          platforms: linux/amd64
          build-args: |
            APP_VERSION=${{ steps.version.outputs.value }}
          push: true
          tags: ${{ env.IMAGE }}:develop
          cache-from: type=gha,scope=develop-amd64
          cache-to: type=gha,scope=develop-amd64,mode=max,ignore-error=true
