|
| 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 |
0 commit comments