Clean up #11119
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on: | |
workflow_dispatch: | |
schedule: | |
- cron: "*/5 * * * *" | |
pull_request_target: | |
types: | |
- closed | |
name: Clean up | |
jobs: | |
# We use environments to deploy to a public registry after PRs are merged. | |
# Since we use the same workflows during CI, a default environment that defines | |
# the necessary variables is used instead. Unfortunately, this automatically | |
# also creates an (unwanted) deployment, which we delete with this job. | |
# See also https://github.com/actions/runner/issues/2120 | |
deployments: | |
name: Deployments | |
runs-on: ubuntu-latest | |
permissions: | |
deployments: write | |
steps: | |
- uses: actions/github-script@v6 | |
with: | |
script: | | |
const deployments = await github.rest.repos.listDeployments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
environment: 'default' | |
}); | |
await Promise.all( | |
deployments.data.map(async (deployment) => { | |
await github.rest.repos.createDeploymentStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: deployment.id, | |
state: 'inactive' | |
}); | |
return github.rest.repos.deleteDeployment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
deployment_id: deployment.id | |
}); | |
}) | |
); | |
pr_cleanup: | |
name: Clean up documentation previews | |
if: github.event_name == 'pull_request_target' | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
with: | |
ref: ${{ vars.preview_branch }} | |
- name: Delete preview folder | |
run: | | |
git config --global user.name "cuda-quantum-bot" | |
git config --global user.email "[email protected]" | |
git rm -r "pr-${{ github.event.pull_request.number }}" --ignore-unmatch | |
git commit --allow-empty -m "Cleaning up docs preview for PR #${{ github.event.pull_request.number }}." | |
git config pull.rebase true | |
git pull --no-edit && git push |