-
Notifications
You must be signed in to change notification settings - Fork 14
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
53
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 all commits
Commits
Show all changes
53 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 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,109 +3,67 @@ name: Remove old wheels | |
| on: | ||
| # Run daily at 1:23 UTC | ||
| schedule: | ||
| - cron: '23 1 * * *' | ||
| - cron: '23 1 * * *' | ||
| workflow_dispatch: | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| # Needed for micromamba pickup | ||
| defaults: | ||
| run: | ||
| shell: bash -l {0} | ||
|
|
||
| env: | ||
| N_LATEST_UPLOADS: 5 | ||
| ANACONDA_USER: "scientific-python-nightly-wheels" | ||
|
|
||
| jobs: | ||
| remove: | ||
|
|
||
| get-pkgs: | ||
| runs-on: ubuntu-latest | ||
| if: github.repository_owner == 'scientific-python' | ||
| # Set required workflow secrets in the environment for additional security | ||
| # https://github.com/scientific-python/upload-nightly-action/settings/environments | ||
| environment: | ||
| name: remove-old-wheels | ||
|
|
||
| outputs: | ||
| pkgnames: ${{ steps.set-outputs.outputs.pkgnames }} | ||
|
|
||
| steps: | ||
| - name: Install micromamba and anaconda-client | ||
| uses: mamba-org/setup-micromamba@d7c9bd84e824b79d2af72a2d4196c7f4300d3476 # v3.0.0 | ||
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| - name: Set up pixi | ||
| uses: prefix-dev/setup-pixi@a09b6247153796b190642a2b53fac4241043cf6f # v0.10.0 | ||
| with: | ||
| environment-name: remove-wheels | ||
| create-args: >- | ||
| anaconda-client==1.14.0 | ||
| curl | ||
| jq | ||
|
|
||
| - name: Show environment | ||
| run: env | ||
|
|
||
| - name: Show CLI API info | ||
| run: | | ||
| anaconda show --help | ||
| echo "" | ||
| anaconda remove --help | ||
| locked: true | ||
|
|
||
| - name: Query package index for packages | ||
| - name: Generate list of package names | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this package list generation still necessary?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| id: set-outputs | ||
| shell: pixi run --manifest-path pixi.toml bash -e {0} | ||
| run: | | ||
| curl https://raw.githubusercontent.com/scientific-python/upload-nightly-action/main/packages-ignore-from-cleanup.txt --output packages-ignore-from-cleanup.txt | ||
| anaconda show "${ANACONDA_USER}" &> >(grep "${ANACONDA_USER}/") | \ | ||
| pkgs_json=$(anaconda show "${ANACONDA_USER}" 2>&1 | grep "${ANACONDA_USER}/" | \ | ||
| awk '{print $1}' | \ | ||
| sed 's|.*/||g' | \ | ||
| grep -vf packages-ignore-from-cleanup.txt > package-names.txt | ||
|
|
||
| - name: Remove old uploads to save space | ||
| run: | | ||
| # 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 seperated) token | ||
| for package_name in $(cat package-names.txt); do | ||
|
|
||
| echo -e "\n# package: ${package_name}" | ||
| grep -vf packages-ignore-from-cleanup.txt | \ | ||
| python -c 'import sys, json; print(json.dumps([line.strip() for line in sys.stdin if line.strip()]))') | ||
| echo "pkgnames=${pkgs_json}" >> "$GITHUB_OUTPUT" | ||
|
|
||
| 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 | ||
| remove: | ||
| runs-on: ubuntu-latest | ||
| if: github.repository_owner == 'scientific-python' | ||
| # Set required workflow secrets in the environment for additional security | ||
| # https://github.com/scientific-python/upload-nightly-action/settings/environments | ||
| environment: | ||
| name: remove-old-wheels | ||
|
|
||
| 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 | ||
| needs: [get-pkgs] | ||
|
|
||
| for package_version in $(cat remove-package-versions.txt); do | ||
| echo "# Removing ${ANACONDA_USER}/${package_name}/${package_version}" | ||
| anaconda --token ${{ secrets.ANACONDA_TOKEN }} remove \ | ||
| --force \ | ||
| "${ANACONDA_USER}/${package_name}/${package_version}" | ||
| done | ||
| fi | ||
| strategy: | ||
| matrix: | ||
| pkgname: ${{fromJSON(needs.get-pkgs.outputs.pkgnames)}} | ||
|
|
||
| done | ||
| fi | ||
| steps: | ||
| - uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0 | ||
| - name: Remove old wheels | ||
| uses: ./remove-wheels | ||
| with: | ||
| n_latest_uploads_to_keep: ${{ env.N_LATEST_UPLOADS }} | ||
| anaconda_nightly_upload_organization: ${{ env.ANACONDA_USER }} | ||
| anaconda_nightly_token: ${{ secrets.ANACONDA_TOKEN }} | ||
| package_name: ${{ matrix.pkgname }} | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this in the last commit in 7f6204c as a means to test the action on PRs (otherwise it runs only on a daily schedule and on manual triggers). Please let me know in case you think this is not ideal – I'll revert. Thanks!