-
Notifications
You must be signed in to change notification settings - Fork 96
139 lines (122 loc) · 4.87 KB
/
pkgs-delete.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
name: Package Cleanup
on:
schedule:
- cron: '0 0 * * *' # Run every day at 24:00
jobs:
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: 'EpicChain.VM,EpicChain.Json,EpicChain.IO,Neo,EpicChain.ConsoleService,EpicChain.Extensions' # EpicChain.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 EpicChain.Cryptography.BLS12_381 Package
uses: actions/delete-package-versions@v4
with:
package-name: EpicChain.Cryptography.BLS12_381
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain.VM Package
uses: actions/delete-package-versions@v4
with:
package-name: EpicChain.VM
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain.Json Package
uses: actions/delete-package-versions@v4
with:
package-name: EpicChain.Json
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain.IO Package
uses: actions/delete-package-versions@v4
with:
package-name: EpicChain.IO
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain Package (nuget)
uses: actions/delete-package-versions@v4
with:
package-name: Neo
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain Package (docker)
uses: actions/delete-package-versions@v4
with:
package-name: Neo
package-type: docker
min-versions-to-keep: 1
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain.ConsoleService Package
uses: actions/delete-package-versions@v4
with:
package-name: EpicChain.ConsoleService
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"
- name: Delete EpicChain.Extensions Package
uses: actions/delete-package-versions@v4
with:
package-name: EpicChain.Extensions
package-type: nuget
min-versions-to-keep: 3
delete-only-pre-release-versions: "true"
token: "${{ secrets.GITHUB_TOKEN }}"