name: test-container-build

on:
  push:
    branches: [ 'prep-*' ]

permissions:
  contents: read
  packages: write

jobs:
  container-build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Remove unnecessary files to release disk space
        run: |
          sudo rm -rf \
            "$AGENT_TOOLSDIRECTORY" \
            /opt/ghc \
            /opt/google/chrome \
            /opt/microsoft/msedge \
            /opt/microsoft/powershell \
            /opt/pipx \
            /usr/lib/mono \
            /usr/local/julia* \
            /usr/local/lib/android \
            /usr/local/lib/node_modules \
            /usr/local/share/chromium \
            /usr/local/share/powershell \
            /usr/local/share/powershell \
            /usr/share/dotnet \
            /usr/share/swift

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build & push
        uses: docker/build-push-action@v5
        with:
          context: .
          file: Dockerfile
          push: true
          # Tag with prep suffix to avoid conflicts with production
          tags: |
            ghcr.io/${{ github.repository }}:${{ github.ref_name }}