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 #919

Merged
merged 2 commits into from
Feb 20, 2024
Merged
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
26 changes: 16 additions & 10 deletions .github/workflows/pkgs-delete.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,30 @@ jobs:
python-version: '3.x'
- name: Install Requests
run: pip install requests
- name: Install Packaging
run: pip install packaging
- name: Get versions below 3.6.0
env:
MYGET_FEED: 'neo'
PACKAGE_NAMES: 'Neo.SmartContract.Framework,Neo.SmartContract.Testing'
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/package/{package_name}/versions"
headers = {"X-MyGet-ApiKey": api_key}
url = f"https://www.myget.org/F/neo/api/v2/Packages?$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()
return [version['Version'] for version in versions['d'] if version['Version'] < '3.6.0']
versions = response.json()['d']['results']
return [ver['Version'] for ver in versions]
else:
return []

def delete_version(feed, package_name, version, api_key):
delete_url = f"https://www.myget.org/F/{feed}/api/v2/package/{package_name}/{version}"
def delete_version(feed, package_name, ver, api_key):
delete_url = f"https://www.myget.org/F/{feed}/api/v2/package/{package_name}/{ver}"
headers = {"X-MyGet-ApiKey": api_key}
response = requests.delete(delete_url, headers=headers)
return response.status_code == 204 # 204 No Content, success
Expand All @@ -50,11 +53,14 @@ jobs:

for package_name in package_names:
versions_to_delete = get_versions(feed, package_name, api_key)
for version in versions_to_delete:
if delete_version(feed, package_name, version, api_key):
print(f"Deleted version {version} of package {package_name}.")
for ver in versions_to_delete:
if version.parse(ver.split("-", 1)[0]) >= version.Version("3.6.0"):
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 {version} of package {package_name}.")
print(f"Failed to delete version {ver} of package {package_name}.")

shell: python

Expand Down
Loading