-
Notifications
You must be signed in to change notification settings - Fork 15
Add a separate action for removing old wheels #95
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
agriyakhetarpal
wants to merge
54
commits into
scientific-python:main
Choose a base branch
from
agriyakhetarpal:feat/separate-action-for-artifact-removals
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 22 commits
Commits
Show all changes
54 commits
Select commit
Hold shift + click to select a range
d6264b8
Add a preliminary action for removing wheels
agriyakhetarpal 9d4f667
Clarify some of the inputs, improve descriptions
agriyakhetarpal 002d2e5
Rename original action to reflect wheel uploads
agriyakhetarpal 40cd6bc
Convert remove wheels step to a bash script
agriyakhetarpal 8a33f20
Fix up messages, improve comments
agriyakhetarpal b18b4a1
Rename org to user in sync with action's YAML
agriyakhetarpal deb3cba
Oops, don't let `pixi` `pip`-install `curl` and `jq`
agriyakhetarpal 05770f3
Use `./remove-wheels` internally
agriyakhetarpal 199b1c8
Don't mention "Anaconda Cloud" explicitly
agriyakhetarpal f8b96a0
Ensure consistency: use ANACONDA_USER
agriyakhetarpal 70f8a3d
Mark TODO about macOS support
agriyakhetarpal 2fac172
Clean up, add more TODOs and comments
agriyakhetarpal 6a1b65e
Merge branch 'main' into feat/separate-action-for-artifact-removals
agriyakhetarpal 8bb7bb6
Rename `anaconda_user` for consistency
agriyakhetarpal bae5ad6
Let ANACONDA_USER env var be empty
agriyakhetarpal f916adc
Merge branch 'main' into feat/separate-action-for-artifact-removals
agriyakhetarpal afedc16
Fix Anaconda org input
agriyakhetarpal 35c9d59
Add some docs sections
agriyakhetarpal 7a7dbbc
Merge branch 'main' into feat/separate-action-for-artifact-removals
bsipocz 7830eae
Merge branch 'main' into feat/separate-action-for-artifact-removals
matthewfeickert 2f62d85
Add some docs suggestions from code review
agriyakhetarpal 1f04be6
Rename upload token to just token for clarity
agriyakhetarpal b6dbd44
Use single line for command
agriyakhetarpal 88ce687
Fixes for `pixi` and shell script filename
agriyakhetarpal 03979b0
Add `jq` from conda-forge as a dependency
agriyakhetarpal bf8e993
Revert change to "Nightly upload" section
agriyakhetarpal 433e7c3
Revert `jq`'s addition to `pixi` global manifest file
agriyakhetarpal 4a3497d
Add a new manifest for the `remove-wheels` environment
agriyakhetarpal 71ede79
Generate `pixi.lock` file for `remove-wheels`
agriyakhetarpal 2d2e62a
Add a note about how tokens for packages work
agriyakhetarpal 556e9a6
Change to secondary-level heading
agriyakhetarpal e403c81
Move docs up, and workflow example below
agriyakhetarpal 15b617e
Update pixi lockfile to be version 5 compliant
agriyakhetarpal 288b2f2
Bump pixi lockfile to newer v6 standard
agriyakhetarpal 9a447eb
Merge main
agriyakhetarpal 6b0a6a1
matrix explosion for cron workflow
Cadair 3d1fb55
Discard changes to packages-ignore-from-cleanup.txt
agriyakhetarpal e8796a6
Bring back package names to ignore from file
agriyakhetarpal b58e1ad
Bring back actions/checkout
agriyakhetarpal 87a34c1
Merge main, fix various issues, update README
agriyakhetarpal dd198a5
Drop "channel" from README line
agriyakhetarpal 8c44b1e
Update actions versions everywhere
agriyakhetarpal ee50125
Update base lockfile to use v7 too
agriyakhetarpal 5bf13a4
Mark oldest versions for deletion, not newest ones
agriyakhetarpal bbe9855
Merge branch 'main' into feat/separate-action-for-artifact-removals
agriyakhetarpal e4df714
Reverted to previous deletion logic
agriyakhetarpal adf07f6
Move `remove_wheels.sh` into `remove_wheels/`
agriyakhetarpal 6f49afb
Rename variable to `n_latest_uploads_to_keep`
agriyakhetarpal 7136973
Use pixi instead of micromamba in remove-wheels job
agriyakhetarpal 0d31db9
Use anaconda-client 1.14.1 everywhere
agriyakhetarpal 8e2cd4f
Refactor into feature, remove previous manifest
agriyakhetarpal 443f68e
Rewrite remove_wheels as a Python script
agriyakhetarpal 7f6204c
Dogfood remove-wheels action on PRs
agriyakhetarpal 49c8194
Merge branch 'main' into feat/separate-action-for-artifact-removals
agriyakhetarpal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,50 @@ | ||
| name: Scientific Python / Remove Old Wheels | ||
| description: A GitHub Action to remove old wheels | ||
| permissions: | ||
| actions: read | ||
| contents: read | ||
| metadata: read | ||
| author: "Scientific-Python" | ||
| # TODO: have to think about versioning; whether to version separately, or | ||
| # for it to be in sync with the version for the upload action | ||
| version: "0.1.0" | ||
|
|
||
| inputs: | ||
| n_latest_uploads: | ||
| description: 'The number of previous wheel uploads to keep' | ||
| required: false | ||
| default: '5' | ||
| anaconda_nightly_upload_organization: | ||
| description: 'Anaconda Cloud organisation name to remove the wheels from' | ||
| required: false | ||
| default: scientific-python-nightly-wheels | ||
| anaconda_nightly_token: | ||
| description: 'Anaconda Cloud API token to authenticate with' | ||
| required: true | ||
|
|
||
| # TODO: Linux only for now, need to see how to add macOS support | ||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: Set up pixi | ||
| uses: prefix-dev/setup-pixi@ba3bb36eb2066252b2363392b7739741bb777659 # v0.8.1 | ||
| with: | ||
| locked: true | ||
| cache: true | ||
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | ||
| # Avoid post cleanup errors if action run multiple times | ||
| post-cleanup: false | ||
|
|
||
| - name: Install dependencies | ||
| shell: bash | ||
| run: | | ||
| sudo apt-get update && sudo apt-get install -y curl jq | ||
|
agriyakhetarpal marked this conversation as resolved.
Outdated
|
||
|
|
||
| - name: Remove old wheels | ||
| shell: bash | ||
| env: | ||
| INPUT_N_LATEST_UPLOADS: ${{ inputs.n_latest_uploads }} | ||
| INPUT_ANACONDA_USER: ${{ inputs.anaconda_user }} | ||
| INPUT_ANACONDA_TOKEN: ${{ inputs.anaconda_token }} | ||
| run: | | ||
| pixi run remove_old_wheels.sh | ||
|
agriyakhetarpal marked this conversation as resolved.
Outdated
|
||
This file contains hidden or 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,109 @@ | ||
| #!/bin/bash | ||
|
|
||
| # fail on undefined variables | ||
| set -u | ||
| # Prevent pipe errors to be silenced | ||
| set -o pipefail | ||
| # Exit if any command exit as non-zero | ||
| set -e | ||
| # enable trace mode (print what it does) | ||
| set -x | ||
|
|
||
| # get the anaconda token from the github secrets | ||
| # | ||
| # this is to prevent accidental removals | ||
| echo "Getting anaconda token from github secrets..." | ||
|
|
||
| ANACONDA_USER="${INPUT_ANACONDA_USER}" | ||
| ANACONDA_TOKEN="${INPUT_ANACONDA_TOKEN}" | ||
| N_LATEST_UPLOADS="${INPUT_N_LATEST_UPLOADS}" | ||
|
|
||
|
|
||
| # if the ANACONDA_TOKEN is empty, exit with status -1 | ||
| # this is to prevent accidental removals | ||
| if [ -z "${ANACONDA_TOKEN}" ]; then | ||
| echo "ANACONDA_TOKEN is empty, exiting..." | ||
| exit -1 | ||
| fi | ||
|
|
||
| # if the N_LATEST_UPLOADS is empty, exit with status -1 | ||
| # as this should be set in by the user and it is better | ||
| # to fail on this to signal a problem. i.e., | ||
| # explicit is better than implicit. | ||
| if [ -z "${N_LATEST_UPLOADS}" ]; then | ||
| echo "N_LATEST_UPLOADS is empty, exiting..." | ||
| exit -1 | ||
| fi | ||
|
|
||
|
|
||
| # Query the package index for packages | ||
| # | ||
| # TODO: should be possible to alter this, since separating the workflow | ||
| # into two steps, one for uploading and one for cleanup, should make it | ||
| # possible for users to manually trigger the cleanup step before/after the | ||
| # upload step has completed in their own repos instead of us having to do it. | ||
| # | ||
| # TODO: raises questions on how to moderate cleanups among multiple users | ||
| # operating on the same channel, but that might be a different issue. | ||
| curl https://raw.githubusercontent.com/scientific-python/upload-nightly-action/main/packages-ignore-from-cleanup.txt --output packages-ignore-from-cleanup.txt | ||
|
agriyakhetarpal marked this conversation as resolved.
Outdated
|
||
| anaconda show "${ANACONDA_USER}" &> >(grep "${ANACONDA_USER}/") | \ | ||
| awk '{print $1}' | \ | ||
| sed 's|.*/||g' | \ | ||
| grep -vf packages-ignore-from-cleanup.txt > package-names.txt | ||
|
|
||
| # Remove old uploads to save space | ||
| # Remove all _but_ the last ${N_LATEST_UPLOADS} package versions and | ||
| # remove all package versions older than 30 days. | ||
| if [ -s package-names.txt ]; then | ||
| threshold_date="$(date +%F -d '30 days ago')" | ||
|
|
||
| # Remember can't quote subshell as need to split on (space separated) token | ||
| for package_name in $(cat package-names.txt); do | ||
| # TODO: this outer loop can be removed when ready since there will be | ||
| # just one package to remove when the action is triggered manually from | ||
| # a user's (different) repo. | ||
|
|
||
| echo -e "\n# package: ${package_name}" | ||
|
agriyakhetarpal marked this conversation as resolved.
Outdated
|
||
|
|
||
| curl --silent https://api.anaconda.org/package/"${ANACONDA_USER}/${package_name}" | \ | ||
| jq -r '.releases[].version' > package-versions.txt | ||
| head --lines "-${N_LATEST_UPLOADS}" package-versions.txt > remove-package-versions.txt | ||
|
|
||
| for package_version in $(cat package-versions.txt); do | ||
| # c.f. https://github.com/Anaconda-Platform/anaconda-client/issues/682#issuecomment-1677283067 | ||
| upload_date=$(curl --silent https://api.anaconda.org/release/"${ANACONDA_USER}/${package_name}/${package_version}" | \ | ||
| jq -r '.distributions[].upload_time' | \ | ||
| sort | \ | ||
| tail --lines 1 | \ | ||
| awk '{print $1}') | ||
|
|
||
| # check upload_date is YYYY-MM-DD formatted | ||
| # c.f. https://github.com/scientific-python/upload-nightly-action/issues/73 | ||
| if [[ "${upload_date}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]; then | ||
| if [[ "${upload_date}" < "${threshold_date}" ]]; then | ||
| echo "# ${ANACONDA_USER}/${package_name}/${package_version} last uploaded on ${upload_date}" | ||
| echo "${package_version}" >> remove-package-versions.txt | ||
| fi | ||
| else | ||
| echo "# ERROR: ${ANACONDA_USER}/${package_name}/${package_version} upload date ${upload_date} is not YYYY-MM-DD." | ||
| fi | ||
|
|
||
| done | ||
|
|
||
| if [ -s remove-package-versions.txt ]; then | ||
| # Guard against duplicate entries from packages over | ||
| # count and time thresholds | ||
| sort --output remove-package-versions.txt --unique remove-package-versions.txt | ||
|
|
||
| for package_version in $(cat remove-package-versions.txt); do | ||
| echo "# Removing ${ANACONDA_USER}/${package_name}/${package_version}" | ||
| anaconda --token "${ANACONDA_TOKEN}" remove \ | ||
| --force \ | ||
| "${ANACONDA_USER}/${package_name}/${package_version}" | ||
| done | ||
| fi | ||
|
|
||
| done | ||
| fi | ||
|
|
||
| echo "Finished removing old wheels except the last ${N_LATEST_UPLOADS} uploads from the ${ANACONDA_USER} channel." | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.