name: Update ZIMFarm Definitions

on:
  push:
    branches: [main]
    paths:
      - 'offliner-definition.json'
  release:
    types: [published]

  workflow_dispatch:
    inputs:
      version:
        description: 'Version to publish'
        required: false
        default: 'dev'

jobs:
  prepare-json:
    runs-on: ubuntu-24.04
    outputs:
      offliner_definition_b64: ${{ steps.read-json.outputs.offliner_definition_b64 }}
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - id: read-json
        run: |
          if [ ! -f "offliner-definition.json" ]; then
            echo "File not found!" >&2
            exit 1
          fi
          json_b64=$(base64 -w0 <<< "$(jq -c . offliner-definition.json)")
          echo "offliner_definition_b64=$json_b64" >> $GITHUB_OUTPUT
  call-workflow:
    needs: prepare-json
    uses: openzim/overview/.github/workflows/update-zimfarm-offliner-definition.yaml@main
    with:
      version: ${{ github.event_name == 'release' && github.event.release.tag_name || (github.event.inputs.version || 'dev') }}
      offliner: phet
      offliner_definition_b64: ${{ needs.prepare-json.outputs.offliner_definition_b64 }}
    secrets:
      zimfarm_ci_secret: ${{ secrets.ZIMFARM_CI_SECRET }}
