Skip to content

Commit 5b2b1c8

Browse files
authored
Merge pull request #1 from Keyfactor/package_sync_ci
Package sync ci
2 parents bd148d0 + 3759afd commit 5b2b1c8

File tree

9 files changed

+468
-0
lines changed

9 files changed

+468
-0
lines changed

.github/workflows/sync-nuget.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Sync NuGet Packages
2+
3+
on:
4+
schedule:
5+
# Run weekly on Sunday at 2:00 AM UTC
6+
- cron: '0 2 * * 0'
7+
workflow_dispatch:
8+
# Allow manual triggering
9+
10+
jobs:
11+
sync-packages:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Checkout repository
16+
uses: actions/checkout@v4
17+
18+
- name: Set up Python
19+
uses: actions/[email protected]
20+
with:
21+
python-version: '3.12'
22+
23+
- name: Set up .NET Core
24+
uses: actions/[email protected]
25+
with:
26+
dotnet-version: '8.0.x'
27+
28+
- name: Install NuGet CLI
29+
uses: nuget/[email protected]
30+
with:
31+
nuget-version: '5.x'
32+
33+
- name: Install Python dependencies
34+
run: |
35+
python -m pip install --upgrade pip
36+
pip install -e .
37+
38+
- name: Create NuGet config
39+
run: |
40+
mkdir -p ~/.nuget/NuGet
41+
echo '<?xml version="1.0" encoding="utf-8"?>' > ~/.nuget/NuGet/NuGet.Config
42+
echo '<configuration>' >> ~/.nuget/NuGet/NuGet.Config
43+
echo ' <packageSources>' >> ~/.nuget/NuGet/NuGet.Config
44+
echo ' <add key="Azure DevOps" value="https://pkgs.dev.azure.com/Keyfactor/_packaging/KeyfactorPackages/nuget/v3/index.json" />' >> ~/.nuget/NuGet/NuGet.Config
45+
echo ' </packageSources>' >> ~/.nuget/NuGet/NuGet.Config
46+
echo ' <packageSourceCredentials>' >> ~/.nuget/NuGet/NuGet.Config
47+
echo ' <Azure_x0020_DevOps>' >> ~/.nuget/NuGet/NuGet.Config
48+
echo ' <add key="Username" value="user" />' >> ~/.nuget/NuGet/NuGet.Config
49+
echo ' <add key="ClearTextPassword" value="${{ secrets.AZ_DEVOPS_PAT }}" />' >> ~/.nuget/NuGet/NuGet.Config
50+
echo ' </Azure_x0020_DevOps>' >> ~/.nuget/NuGet/NuGet.Config
51+
echo ' </packageSourceCredentials>' >> ~/.nuget/NuGet/NuGet.Config
52+
echo '</configuration>' >> ~/.nuget/NuGet/NuGet.Config
53+
54+
- name: Run NuGet sync script
55+
run: python scripts/sync_nuget.py
56+
env:
57+
GITHUB_TOKEN: ${{ secrets.GH_NUGET_TOKEN }}
58+
# Add any other environment variables needed by your script

packages.yml

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
---
2+
packages:
3+
- name: Keyfactor.Logging
4+
versions:
5+
- 1.0.0
6+
- 1.1.0
7+
- 1.1.1
8+
- 1.1.2
9+
- 1.2.0
10+
- 1.3.0
11+
- name: Keyfactor.Orchestrators.Common
12+
versions:
13+
- 2.3.6
14+
- 2.3.7
15+
- 2.4.1
16+
- 2.5.0
17+
- 2.9.0
18+
- 3.0.0
19+
- 3.1.0
20+
- 3.1.1
21+
- 3.1.2
22+
- 3.2.0
23+
# - 3.3.0
24+
- name: Keyfactor.Orchestrators.IOrchestratorJobExtensions
25+
versions:
26+
- 1.0.0
27+
- name: Keyfactor.PKI
28+
versions:
29+
- 4.0.1
30+
- 3.2.0
31+
- 3.4.7
32+
- 3.4.8
33+
- 5.0.0
34+
- 5.5.0
35+
- 5.7.0
36+
- 6.3.0
37+
- 7.8.0
38+
- 8.1.0
39+
- 8.1.1
40+
# - 8.3.0
41+
- name: Keyfactor.Orchestrators.IOrchestratorRegistrationUpdater
42+
versions:
43+
- 1.0.2
44+
- 1.0.3
45+
- name: Keyfactor.Common
46+
versions:
47+
- 2.3.6
48+
- 2.3.7
49+
- 2.4.1
50+
- 2.5.0
51+
- 2.8.0
52+
- 2.8.1
53+
- 2.8.2
54+
- 2.9.0
55+
- name: Keyfactor.AnyGateway.IAnyCAPlugin
56+
versions:
57+
- 2.0.0
58+
- 3.0.0
59+
- 3.1.0
60+
# - 3.2.0
61+
- name: Keyfactor.Platform.IPAMProvider
62+
versions:
63+
- 1.0.0
64+
- name: Keyfactor.Extensions.Pam.Utilities
65+
versions:
66+
- 1.0.0
67+
- 1.0.1
68+
- 1.0.2
69+
- name: Keyfactor.Platform.IOrchestratorRegistrationHandler
70+
versions:
71+
- 2.0.0
72+
- 2.0.0.1 #weird version, but this is how it was released
73+
- 3.0.0
74+
- name: Keyfactor.Orchestrators.ISslJobExtension
75+
versions:
76+
- 1.0.0
77+
- 1.0.1
78+
- 1.0.2
79+
- 1.0.3
80+
- 1.0.4
81+
- name: Keyfactor.Workflows.IWorkflowStep
82+
versions:
83+
- 1.0.0
84+
- 1.1.0
85+
- 2.0.0
86+
- 2.0.1
87+
- 2.1.0
88+
- 2.2.0
89+
- 2.3.0
90+
- 2.4.0
91+
- 2.5.0
92+
- name: Keyfactor.Workflows
93+
versions:
94+
- 1.0.0
95+
- 1.1.0
96+
- 2.0.0
97+
- 2.1.0
98+
- 2.2.0
99+
- 2.3.0
100+
- 2.4.0
101+
- 2.5.0
102+
- name: Keyfactor.Platform.IOrchestratorJobCompleteHandler
103+
versions:
104+
- 1.0.0.1

pyproject.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[build-system]
2+
requires = ["setuptools>=42", "wheel"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "nuget-syncer"
7+
version = "0.1.0"
8+
description = "Sync NuGet packages from Azure DevOps to GitHub Packages"
9+
authors = [
10+
{name = "Keyfactor", email = "[email protected]"}
11+
]
12+
readme = "README.md"
13+
requires-python = ">=3.8"
14+
license = {file = "LICENSE"}
15+
dependencies = [
16+
"pyyaml>=6.0"
17+
]
18+
19+
[project.optional-dependencies]
20+
dev = [
21+
"pytest>=7.0",
22+
"black>=23.0",
23+
"isort>=5.12.0"
24+
]
25+
26+
[tool.setuptools]
27+
packages = ["scripts"]
28+
29+
[tool.black]
30+
line-length = 100
31+
target-version = ["py38"]
32+
33+
[tool.isort]
34+
profile = "black"
35+
line_length = 100

scripts/sync_devops.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env bash
2+
3+
# CONFIG
4+
AZURE_PAT="${AZ_DEVOPS_PAT}"
5+
GITHUB_PAT="${GITHUB_TOKEN}"
6+
GITHUB_ORG="keyfactor"
7+
AZURE_ORG="Keyfactor"
8+
AZURE_PROJECT="Engineering" # Adjust if needed
9+
#AZURE_FEED="KeyfactorPackages"
10+
AZURE_FEED="b9291bd8-a79d-4353-8a07-09631feaa444"
11+
12+
13+
TMP_DIR="./nupkgs"
14+
mkdir -p "$TMP_DIR"
15+
16+
# Get packages
17+
PACKAGES_URL="https://feeds.dev.azure.com/${AZURE_ORG}/_apis/packaging/feeds/${AZURE_FEED}/packages?api-version=7.1"
18+
19+
echo "Fetching packages..."
20+
echo curl -u ":$AZURE_PAT" "$PACKAGES_URL"
21+
curl -u ":$AZURE_PAT" "$PACKAGES_URL"
22+
PACKAGE_LIST=$(curl -s -u ":$AZURE_PAT" "$PACKAGES_URL")
23+
echo "$PACKAGE_LIST" > packages.json
24+
echo "$PACKAGE_LIST" | jq -c '.value[]' | while read -r pkg; do
25+
NAME=$(echo "$pkg" | jq -r '.name')
26+
VERSIONS_URL=$(echo "$pkg" | jq -r '.versionsUrl')
27+
28+
echo "Fetching versions for $NAME..."
29+
curl -u ":$AZURE_PAT" "$VERSIONS_URL?api-version=7.1"
30+
VERSION_LIST=$(curl -s -u ":$AZURE_PAT" "$VERSIONS_URL?api-version=7.1")
31+
32+
echo $VERSION_LIST
33+
echo "$VERSION_LIST" | jq -c '.value[]' | while read -r ver; do
34+
VERSION=$(echo "$ver" | jq -r '.version')
35+
DOWNLOAD_URL=$(echo "$ver" | jq -r '._links.content.href')
36+
37+
FILE="$TMP_DIR/${NAME}.${VERSION}.nupkg"
38+
if [ -f "$FILE" ]; then
39+
echo "Already downloaded: $FILE"
40+
else
41+
echo "Downloading $NAME $VERSION..."
42+
curl -s -u ":$AZURE_PAT" -L "$DOWNLOAD_URL" -o "$FILE"
43+
fi
44+
45+
echo "Pushing $NAME $VERSION to GitHub Packages..."
46+
dotnet nuget push "$FILE" \
47+
--source "https://nuget.pkg.github.com/$GITHUB_ORG/index.json" \
48+
--api-key "$GITHUB_PAT" \
49+
--skip-duplicate
50+
done
51+
done
52+
53+
echo "Done!"

0 commit comments

Comments
 (0)