diff --git a/.github/workflows/deployments.yml b/.github/workflows/deployments.yml index 76ab1720112..edce46409a1 100644 --- a/.github/workflows/deployments.yml +++ b/.github/workflows/deployments.yml @@ -35,6 +35,11 @@ on: description: Build and include macOS wheels and installer. required: false default: true + run_publishing_after: + type: boolean + description: When this deployment completes successfully, automatically trigger the Publishing workflow. + required: false + default: false workflow_run: workflows: - PR merged @@ -162,6 +167,17 @@ jobs: retention-days: 30 if-no-files-found: error + - name: Upload publishing flag + if: github.event_name == 'workflow_dispatch' + run: echo '${{ inputs.run_publishing_after }}' > publishing_requested.txt + - name: Upload publishing_requested artifact + if: github.event_name == 'workflow_dispatch' + uses: actions/upload-artifact@v4 + with: + name: publishing_requested + path: publishing_requested.txt + retention-days: 1 + - name: Checkout repository uses: actions/checkout@v6 with: @@ -825,3 +841,26 @@ jobs: with: cache_base: ${{ needs.metadata.outputs.cache_base }} cudaq_version: ${{ inputs.create_release }} + + trigger_publishing: + name: Trigger Publishing + needs: [summary, python_wheels, binaries] + if: inputs.run_publishing_after + runs-on: ubuntu-latest + permissions: + actions: write + steps: + - name: Trigger Publishing workflow + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.REPO_BOT_ACCESS_TOKEN }} + script: | + await github.rest.actions.createWorkflowDispatch({ + owner: context.repo.owner, + repo: context.repo.repo, + workflow_id: 'publishing.yml', + ref: context.ref.replace('refs/heads/', ''), + inputs: { + deployment_id: context.runId.toString(), + }, + }); diff --git a/.github/workflows/publishing.yml b/.github/workflows/publishing.yml index 9a16f892dbf..1180582f8be 100644 --- a/.github/workflows/publishing.yml +++ b/.github/workflows/publishing.yml @@ -39,9 +39,39 @@ on: name: Publishing jobs: + check_publishing_requested: + name: Check if publishing was requested + runs-on: ubuntu-latest + permissions: + actions: read + outputs: + run_publishing: ${{ steps.check.outputs.run_publishing }} + steps: + - id: check + run: | + if [ "${{ github.event_name }}" != "workflow_run" ]; then + echo "run_publishing=true" >> $GITHUB_OUTPUT + else + artifacts_url='${{ github.event.workflow_run.artifacts_url }}' + artifact_url=$(gh api "$artifacts_url" --paginate -q '.artifacts[] | select(.name=="publishing_requested") | .archive_download_url' | head -1) + if [ -n "$artifact_url" ]; then + gh api "$artifact_url" -o publishing_requested.zip + unzip -o publishing_requested.zip + content=$(cat publishing_requested.txt 2>/dev/null | tr -d '\n' || echo "true") + else + content="true" + fi + echo "run_publishing=$content" >> $GITHUB_OUTPUT + fi + env: + GH_TOKEN: ${{ github.token }} + assets: name: Assets - if: github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' + needs: [check_publishing_requested] + if: >- + (github.event_name == 'workflow_dispatch' || (github.event.workflow_run.conclusion == 'success' + && needs.check_publishing_requested.outputs.run_publishing == 'true')) runs-on: ubuntu-latest permissions: actions: read