-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds a script and action to delete PR previews for closed PRs. See 3a29f15 for an example. --------- Co-authored-by: Eric Arellano <[email protected]>
- Loading branch information
1 parent
149c265
commit 1ae2ef3
Showing
5 changed files
with
144 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This code is a Qiskit project. | ||
# | ||
# (C) Copyright IBM 2024. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
name: PR preview cleanup | ||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- "main" | ||
|
||
jobs: | ||
preview-cleanup: | ||
name: PR preview cleanup | ||
runs-on: ubuntu-latest | ||
if: github.repository_owner == 'Qiskit' | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
|
||
- name: Clean up PR previews | ||
run: scripts/pr_previews/cleanup.py | ||
env: | ||
GH_TOKEN: ${{ github.token }} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# This code is a Qiskit project. | ||
# | ||
# (C) Copyright IBM 2024. | ||
# | ||
# This code is licensed under the Apache License, Version 2.0. You may | ||
# obtain a copy of this license in the LICENSE file in the root directory | ||
# of this source tree or at http://www.apache.org/licenses/LICENSE-2.0. | ||
# | ||
# Any modifications or derivative works of this code must retain this | ||
# copyright notice, and modified files need to carry a notice indicating | ||
# that they have been altered from the originals. | ||
|
||
import json | ||
import logging | ||
import shutil | ||
from pathlib import Path | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
from utils import ( | ||
configure_logging, | ||
run_subprocess, | ||
setup_git_account, | ||
switch_branch, | ||
changed_files, | ||
commit_all_and_push, | ||
) | ||
|
||
|
||
def main() -> None: | ||
setup_git_account() | ||
|
||
with switch_branch("gh-pages"): | ||
delete_closed_pr_folders() | ||
|
||
if not changed_files(): | ||
logger.info("No changed files detected, so no push made to gh-pages") | ||
return | ||
|
||
commit_all_and_push("Clean up PR previews") | ||
logger.info("Pushed updates to gh-pages branch") | ||
|
||
|
||
def get_active_pr_folders() -> set[str]: | ||
raw = run_subprocess( | ||
["gh", "pr", "list", "--state", "open", "--json", "number", "--limit", "1000"] | ||
).stdout | ||
# `raw` is JSON string of form: { number: int }[] | ||
return {f"pr-{obj['number']}" for obj in json.loads(raw)} | ||
|
||
|
||
def delete_closed_pr_folders() -> None: | ||
active_pr_folders = get_active_pr_folders() | ||
for folder in Path(".").glob("pr-*"): | ||
if folder.name not in active_pr_folders: | ||
logger.info(f"Deleting {folder}") | ||
shutil.rmtree(folder) | ||
|
||
|
||
if __name__ == "__main__": | ||
configure_logging() | ||
main() |
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
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