|
| 1 | +# |
| 2 | +# Periodically removes obsolete artifacts from GitHub Packages. |
| 3 | +# |
| 4 | +# Only non-release artifacts—those containing "SNAPSHOT" in their version name—are eligible |
| 5 | +# for removal. The latest non-release artifacts will be retained, with the exact number determined |
| 6 | +# by the `VERSION_COUNT_TO_KEEP` environment variable. |
| 7 | +# |
| 8 | +# Please note the following details: |
| 9 | +# |
| 10 | +# 1. An artifact cannot be deleted if it is public and has been downloaded more than 5,000 times. |
| 11 | +# In this scenario, contact GitHub support for further assistance. |
| 12 | +# |
| 13 | +# 2. This workflow only applies to artifacts published from this repository. |
| 14 | +# |
| 15 | +# 3. A maximum of 100 artifacts can be removed per run from each package; |
| 16 | +# if there are more than 100 obsolete artifacts, either manually restart the workflow |
| 17 | +# or wait for the next scheduled removal. |
| 18 | +# |
| 19 | +# 4. When artifacts with version `x.x.x-SNAPSHOT` are published, GitHub automatically appends |
| 20 | +# the current timestamp, resulting in versions like `x.x.x-SNAPSHOT.20241024.173759`. |
| 21 | +# All such artifacts are grouped into one package and treated as a single package |
| 22 | +# in GitHub Packages with the version `x.x.x-SNAPSHOT`. Consequently, it is not possible |
| 23 | +# to remove obsolete versions within a package; only the entire package can be deleted. |
| 24 | +# |
| 25 | + |
| 26 | +name: Remove obsolete Maven artifacts from GitHub Packages |
| 27 | + |
| 28 | +on: |
| 29 | + schedule: |
| 30 | + - cron: '0 0 * * *' # Run every day at midnight. |
| 31 | + |
| 32 | +env: |
| 33 | + VERSION_COUNT_TO_KEEP: 5 # Number of most recent SNAPSHOT versions to retain. |
| 34 | + |
| 35 | +jobs: |
| 36 | + retrieve-package-names: |
| 37 | + name: Retrieve the package names published from this repository |
| 38 | + runs-on: ubuntu-latest |
| 39 | + outputs: |
| 40 | + package-names: ${{ steps.request-package-names.outputs.package-names }} |
| 41 | + steps: |
| 42 | + - uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + submodules: 'true' |
| 45 | + |
| 46 | + - name: Retrieve the names of packages |
| 47 | + id: request-package-names |
| 48 | + shell: bash |
| 49 | + run: | |
| 50 | + repoName=$(echo ${{ github.repository }} | cut -d '/' -f2) |
| 51 | + chmod +x ./config/scripts/request-package-names.sh |
| 52 | + ./config/scripts/request-package-names.sh ${{ github.token }} \ |
| 53 | + $repoName ${{ github.repository_owner }} ./package-names.json |
| 54 | + echo "package-names=$(<./package-names.json)" >> $GITHUB_OUTPUT |
| 55 | +
|
| 56 | + delete-obsolete-artifacts: |
| 57 | + name: Remove obsolete artifacts published from this repository to GitHub Packages |
| 58 | + needs: retrieve-package-names |
| 59 | + runs-on: ubuntu-latest |
| 60 | + strategy: |
| 61 | + matrix: |
| 62 | + package-name: ${{ fromJson(needs.retrieve-package-names.outputs.package-names) }} |
| 63 | + steps: |
| 64 | + - name: Remove obsolete artifacts from '${{ matrix.package-name }}' package |
| 65 | + uses: actions/delete-package-versions@v5 |
| 66 | + with: |
| 67 | + owner: ${{ github.repository_owner }} |
| 68 | + package-name: ${{ matrix.package-name }} |
| 69 | + package-type: 'maven' |
| 70 | + token: ${{ github.token }} |
| 71 | + min-versions-to-keep: ${{ env.VERSION_COUNT_TO_KEEP }} |
| 72 | + # Ignores artifacts that do not contain the word "SNAPSHOT". |
| 73 | + ignore-versions: '^(?!.+SNAPSHOT).*$' |
0 commit comments