name: Deploy C++

on:
  workflow_dispatch:
    inputs:
        publish-pypi:
            type: boolean
            description: Publish to PyPI

jobs:

  build-wheels:
    uses: ./.github/workflows/build-wheels.yml

  upload-awkward-cpp:
    needs: [build-wheels]
    runs-on: ubuntu-latest
    if: inputs.publish-pypi
    permissions:
      id-token: write
      attestations: write
      contents: read
    environment:
      name: "pypi"
      url: "https://pypi.org/project/awkward-cpp/"
    steps:

    - uses: actions/download-artifact@v7
      with:
        pattern: "awkward-cpp*"
        path: dist
        merge-multiple: true

    - name: List distributions to be deployed
      run: ls -l dist/

    - name: Generate artifact attestation for sdist and wheel
      uses: actions/attest-build-provenance@96278af6caaf10aea03fd8d33a09a777ca52d62f # v3.2.0
      with:
        subject-path: "dist/awkward*cpp-*"

    - uses: pypa/gh-action-pypi-publish@v1.13.0
