Skip to content
52 changes: 52 additions & 0 deletions .github/scripts/anaconda-prune/prune.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

grab_prune_version() {
conda search -c "${CHANNEL}" --platform "${platform}" "${PKG}" 2>/dev/null | \
grep "${CHANNEL}" | \
awk -F ' *' '{print $2}' | \
uniq | \
head -n -1 | \
xargs
}

grab_latest_version() {
conda search -c "${CHANNEL}" --platform "${platform}" "${PKG}" 2>/dev/null | \
grep "${CHANNEL}" | \
awk -F ' *' '{print $2}' | \
uniq | \
tail -n 1 | \
xargs
}

grab_specs_for_version() {
conda search -c "${CHANNEL}" --platform "${platform}" "${PKG}" 2>/dev/null | \
grep "${CHANNEL}" | \
grep "$1" | \
awk -F ' *' '{print $3}' | \
uniq | \
xargs
}

set -eou pipefail

CHANNEL=${CHANNEL:-pytorch-nightly}
PKG=${PKG:-pytorch}
PLATFORMS=${PLATFORMS:-noarch osx-64 osx-arm64 linux-64 win-64}

for platform in ${PLATFORMS}; do
latest_version="$(grab_latest_version || true)"
specs_in_latest_version="$(grab_specs_for_version "${latest_version}" || true)"
versions_to_prune="$(grab_prune_version || true)"
for version in ${versions_to_prune}; do
specs_in_prune_version="$(grab_specs_for_version "${version}" || true)"
for spec in ${specs_in_prune_version}; do
# If this spec is included in specs_in_latest_version, then remove it.
if [[ "${specs_in_latest_version}" =~ ${spec} ]];then
(
set -x
anaconda remove --force "${CHANNEL}/${PKG}/${version}/${platform}/${PKG}-${version}-${spec}.tar.bz2"
)
fi
done
done
done
14 changes: 14 additions & 0 deletions .github/scripts/anaconda-prune/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -euo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

CHANNEL=${CHANNEL:-pytorch-nightly}
PACKAGES=${PACKAGES:-pytorch}

for pkg in ${PACKAGES}; do
echo "+ Attempting to prune: ${CHANNEL}/${pkg}"
CHANNEL="${CHANNEL}" PKG="${pkg}" "${DIR}/prune.sh"
echo
done
37 changes: 37 additions & 0 deletions .github/workflows/_prune-anaconda-packages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Prune Anaconda Binaries

on:
workflow_call:
inputs:
packages:
required: true
type: string
description: The packages to prune
channel:
required: true
type: string
description: The channel to prune packages
secrets:
conda-pytorchbot-token:
required: true
description: Conda PyTorchBot token
jobs:
build:
runs-on: ubuntu-22.04
container:
image: continuumio/miniconda3:4.12.0
steps:
- name: Checkout repository test-infra
uses: actions/checkout@v3
with:
repository: pytorch/test-infra
ref: ${{ github.ref }}
- name: Prune binaries
env:
CHANNEl: ${{ inputs.channel }}
PACKAGES: ${{ inputs.packages }}
ANACONDA_API_TOKEN: ${{ secrets.conda-pytorchbot-token }}
run: |
set -ex
conda install -yq anaconda-client
bash ./.github/scripts/anaconda-prune/run.sh
33 changes: 33 additions & 0 deletions .github/workflows/anaconda-prune.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: anaconda-prune

on:
schedule:
- cron: 45 1,7,13,19 * * *
pull_request:
paths:
- .github/workflows/anaconda-prune.yml
- .github/workflows/_prune-anaconda-packages.yml
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
cancel-in-progress: true

jobs:
anaconda-prune-pytorch-nightly:
name: anaconda-prune-pytorch-nightly
uses: ./.github/workflows/_prune-anaconda-packages.yml
with:
packages: "pytorch torchvision torchaudio torchtext torchdata ignite torchcsprng torchserve torcharrow"
channel: pytorch-nightly
secrets:
conda-pytorchbot-token: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}

anaconda-prune-pytorch-test:
name: anaconda-prune-pytorch-test
uses: ./.github/workflows/_prune-anaconda-packages.yml
with:
packages: "pytorch torchvision torchaudio torchtext torchdata ignite torchcsprng"
channel: pytorch-test
secrets:
conda-pytorchbot-token: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}