name: release-after

on:
  workflow_call:
    inputs:
      plan:
        required: true
        type: string
  workflow_dispatch:
    inputs:
      plan:
        description: plan json (only used to extract version)
        required: true
        type: string
        default: '{"releases":[{"app_version":"0.2.2"}]}'

permissions:
  contents: read
  packages: write

jobs:
  container-push:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - id: version
        shell: bash
        run: |
          cat >plan.json << 'EOF'
          ${{ inputs.plan }}
          EOF
          VERSION=$(yq -r '.releases[0].app_version' < plan.json)
          echo "VERSION=$VERSION" >> "$GITHUB_OUTPUT"
      - uses: docker/login-action@v4
        with:
          registry: ghcr.io
          username: ${{github.actor}}
          password: ${{secrets.GITHUB_TOKEN}}
      - uses: docker/setup-buildx-action@v4
      - uses: jdx/mise-action@v4
        with:
          # version 2025.5.11, a symlink is created for rust setup
          # without cache, missing components are installed
          # with cache, nothing is installed, but as rust tool is symlinked, it is not cached => missing components failure
          cache: false
      - run: mise run publish:container --version "${{ steps.version.outputs.VERSION }}"
        shell: bash
      - name: run container (for testing)
        run: |
          # mise run run:container
          docker run --rm --name test "ghcr.io/cdviz-dev/cdviz-collector:${{ steps.version.outputs.VERSION }}" --help
        shell: bash
