Skip to content
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

Update pkgs-delete.yml #3150

Merged
merged 2 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 9 additions & 39 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: ./coverage/lcov.net7.0.info

PublishGithub:
PublishPackage:
if: github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
needs: Test
runs-on: ubuntu-latest
Expand Down Expand Up @@ -76,44 +76,14 @@ jobs:
--disable-buffering \
--no-service-endpoint;

# MyGet isn't working
# PublishMyGet:
# if: github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
# needs: Test
# runs-on: ubuntu-latest
# steps:
# - name: Checkout
# uses: actions/checkout@v4
# with:
# fetch-depth: 0
# - name: Setup .NET
# uses: actions/setup-dotnet@v4
# with:
# dotnet-version: ${{ env.DOTNET_VERSION }}
# - name: Set Version
# run: git rev-list --count HEAD | xargs printf 'CI%05d' | xargs -I{} echo 'VERSION_SUFFIX={}' >> $GITHUB_ENV
# - name : Pack (Neo)
# run: |
# dotnet pack \
# --configuration Debug \
# --output ./out \
# --version-suffix ${{ env.VERSION_SUFFIX }}
# - name: Remove Unwanted Files
# working-directory: ./out
# run: |
# rm -v Neo.CLI*
# rm -v Neo.GUI*
# - name: Publish to MyGet
# working-directory: ./out
# run: |
# for filename in *.nupkg; do
# dotnet nuget push "${filename}" \
# --source https://www.myget.org/F/neo/api/v3/index.json \
# --api-key "${{ secrets.MYGET_TOKEN }}" \
# --disable-buffering \
# --no-service-endpoint;
# done;
# shell: bash
- name: Publish to myGet
working-directory: ./out
run: |
dotnet nuget push * \
--source https://www.myget.org/F/neo/api/v3/index.json \
--api-key "${{ secrets.MYGET_TOKEN }}" \
--disable-buffering \
--no-service-endpoint;

Release:
if: github.ref == 'refs/heads/master' && startsWith(github.repository, 'neo-project/')
Expand Down
101 changes: 89 additions & 12 deletions .github/workflows/pkgs-delete.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,128 @@
name: Nuget Package Cleanup (github)
name: Package Cleanup

on:
schedule:
- cron: '0 0 * * *' # Run every day at 24:00

jobs:
delete-pkgs:

delete-myget-pkgs:
name: Delete Old MyGet Packages
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install Requests
run: pip install requests
- name: Install Packaging
run: pip install packaging
- name: Delete versions below 3.6.1
env:
MYGET_FEED: 'neo'
PACKAGE_NAMES: 'Neo.VM,Neo.Json,Neo.IO,Neo,Neo.ConsoleService,Neo.Extensions' # Neo.Cryptography.BLS12_381 version is 0.x
MYGET_API_KEY: ${{ secrets.MYGET_TOKEN }}
run: |
import requests
from packaging import version
import os

def get_versions(feed, package_name, api_key):
url = f"https://www.myget.org/F/{feed}/api/v2/Packages?$select=Version&$filter=Id eq '{package_name}'&$format=json"
headers = {'Accept': 'application/json'}
response = requests.get(url, headers=headers)
if response.status_code == 200:
versions = response.json()['d']['results']
return [ver['Version'] for ver in versions]
else:
return []

def delete_version(feed, package_name, ver, api_key):
url = f"https://www.myget.org/F/{feed}/api/v2/package/{package_name}/{ver}?hardDelete=true"
headers = {"X-NuGet-ApiKey": api_key}
response = requests.delete(url, headers=headers)
return response.status_code == 200 # Success

feed = os.environ['MYGET_FEED']
package_names = os.environ['PACKAGE_NAMES'].split(',')
api_key = os.environ['MYGET_API_KEY']

for package_name in package_names:
versions_to_delete = get_versions(feed, package_name, api_key)
for ver in versions_to_delete:
if version.parse(ver.split("-", 1)[0]) >= version.Version("3.6.1"):
print(f"Omited {ver} of package {package_name}.")
continue
if delete_version(feed, package_name, ver, api_key):
print(f"Deleted version {ver} of package {package_name}.")
else:
print(f"Failed to delete version {ver} of package {package_name}.")

shell: python

delete-git-pkgs:
name: Delete Old Nuget Packages
runs-on: ubuntu-latest

steps:
- name: Delete Neo Package
- name: Delete Neo.Cryptography.BLS12_381 Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo
package-name: Neo.Cryptography.BLS12_381
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"

- name: Delete Neo.ConsoleService Package
- name: Delete Neo.VM Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo.ConsoleService
package-name: Neo.VM
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"

- name: Delete Neo.ConsoleService Package
- name: Delete Neo.Json Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo.ConsoleService
package-name: Neo.Json
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"

- name: Delete Neo.Json Package
- name: Delete Neo.IO Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo.Json
package-name: Neo.IO
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"

- name: Delete Neo.VM Package
- name: Delete Neo Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo.VM
package-name: Neo
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete Neo.ConsoleService Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo.ConsoleService
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete Neo.Extensions Package
uses: actions/delete-package-versions@v4
with:
package-name: Neo.Extensions
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
Loading