Skip to content

Commit fd7d73e

Browse files
committed
feat(ci): Add workflow to create PRs automatically if new packages are released.
1 parent d3b2d03 commit fd7d73e

2 files changed

Lines changed: 89 additions & 1 deletion

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Upgrade NuGet Packages
2+
3+
on:
4+
schedule:
5+
# Run every Monday at 3:00 AM UTC
6+
- cron: '0 3 * * 1'
7+
workflow_dispatch:
8+
# Allow manual triggering
9+
10+
permissions:
11+
contents: write
12+
pull-requests: write
13+
14+
jobs:
15+
upgrade:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5.6.0
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Install Python dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -e .
31+
32+
- name: Run upgrade
33+
run: python scripts/sync_nuget.py upgrade packages.yml | tee /tmp/upgrade-output.txt
34+
env:
35+
AZ_DEVOPS_PAT: ${{ secrets.AZ_DEVOPS_PAT }}
36+
37+
- name: Build PR body
38+
id: pr-body
39+
run: |
40+
python - <<'EOF'
41+
import os
42+
43+
with open("/tmp/upgrade-output.txt") as f:
44+
lines = f.readlines()
45+
46+
# Collect only packages that gained new versions
47+
entries = []
48+
current_pkg = None
49+
for line in lines:
50+
line = line.rstrip()
51+
if line.startswith("Checking "):
52+
current_pkg = line.removeprefix("Checking ").rstrip(".")
53+
elif "New versions:" in line and current_pkg:
54+
versions = line.split("New versions:", 1)[1].strip()
55+
entries.append(f"| {current_pkg} | {versions} |")
56+
57+
body = "This PR was automatically created by the weekly upgrade workflow.\n\n"
58+
if entries:
59+
body += "## New versions registered\n\n"
60+
body += "| Package | Versions |\n"
61+
body += "| --- | --- |\n"
62+
body += "\n".join(entries)
63+
body += "\n\n"
64+
body += (
65+
"After merging, the daily "
66+
"[Sync NuGet Packages](../actions/workflows/sync-nuget.yml) "
67+
"workflow will push the new versions to the GitHub Package Registry, "
68+
"or you can trigger it manually."
69+
)
70+
71+
with open(os.environ["GITHUB_OUTPUT"], "a") as f:
72+
f.write(f"body<<EOF\n{body}\nEOF\n")
73+
EOF
74+
75+
- name: Create Pull Request
76+
uses: peter-evans/create-pull-request@v7
77+
with:
78+
token: ${{ secrets.GH_NUGET_TOKEN }}
79+
branch: chore/upgrade-nuget-packages
80+
commit-message: "chore: register new NuGet package versions"
81+
title: "chore: register new NuGet package versions"
82+
body: ${{ steps.pr-body.outputs.body }}
83+
labels: automated
84+
delete-branch: true

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@ Some package availability changes from time to time. Please view the `CHANGELOG.
1010

1111
### Via GitHub Actions
1212

13+
New versions of existing packages are registered automatically every Monday by the [Upgrade NuGet Packages](https://github.com/Keyfactor/public-nuget-packages/actions/workflows/upgrade-packages.yml) workflow, which opens a PR with any changes. Once merged, the daily [Sync NuGet Packages](https://github.com/Keyfactor/public-nuget-packages/actions/workflows/sync-nuget.yml) workflow pushes the new versions to the GitHub Package Registry.
14+
15+
To add a brand new package or manually trigger a sync:
16+
1317
1. Add the package and version(s) to [`packages.yml`](./packages.yml).
1418
2. Trigger the [Sync NuGet Packages](https://github.com/Keyfactor/public-nuget-packages/actions/workflows/sync-nuget.yml) workflow.
1519

16-
Once complete, the package will be available in the Keyfactor Public GitHub Package Registry (GPR). The workflow runs automatically on a daily schedule and skips any versions already published.
20+
Once complete, the package will be available in the Keyfactor Public GitHub Package Registry (GPR). The sync workflow runs automatically on a daily schedule and skips any versions already published.
1721

1822
> [!IMPORTANT]
1923
> The package and version must already exist in the Azure DevOps feed before adding it to `packages.yml`:

0 commit comments

Comments
 (0)