|
| 1 | +name: Update NuGet dependencies (daily) |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Runs daily at 02:00 UTC (adjust as you like) |
| 6 | + - cron: "0 2 * * *" |
| 7 | + workflow_dispatch: |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: write |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: update-nuget-deps |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +jobs: |
| 17 | + update: |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + # Needed so we can push back using GITHUB_TOKEN |
| 25 | + persist-credentials: true |
| 26 | + fetch-depth: 0 |
| 27 | + |
| 28 | + - name: Setup .NET |
| 29 | + uses: actions/setup-dotnet@v4 |
| 30 | + with: |
| 31 | + dotnet-version: "10.0.x" |
| 32 | + |
| 33 | + - name: Show .NET info |
| 34 | + run: dotnet --info |
| 35 | + |
| 36 | + - name: Locate solution |
| 37 | + id: sln |
| 38 | + shell: bash |
| 39 | + run: | |
| 40 | + set -euo pipefail |
| 41 | + SLN="$(ls -1 *.sln 2>/dev/null | head -n 1 || true)" |
| 42 | + if [[ -z "${SLN}" ]]; then |
| 43 | + SLN="$(find . -maxdepth 4 -name '*.sln' -print | head -n 1 || true)" |
| 44 | + fi |
| 45 | + if [[ -z "${SLN}" ]]; then |
| 46 | + echo "No .sln file found." |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + echo "Found solution: ${SLN}" |
| 50 | + echo "sln=${SLN}" >> "$GITHUB_OUTPUT" |
| 51 | +
|
| 52 | + - name: Restore |
| 53 | + run: dotnet restore "${{ steps.sln.outputs.sln }}" |
| 54 | + |
| 55 | + - name: Update NuGet package references |
| 56 | + # .NET 10+ command that updates PackageReference versions |
| 57 | + # When no package names are provided, it attempts to update all packages in the project/solution. |
| 58 | + run: dotnet package update --project "${{ steps.sln.outputs.sln }}" |
| 59 | + |
| 60 | + - name: Build |
| 61 | + run: dotnet build "${{ steps.sln.outputs.sln }}" -c Release --no-restore |
| 62 | + |
| 63 | + - name: Test |
| 64 | + run: dotnet test "${{ steps.sln.outputs.sln }}" -c Release --no-build |
| 65 | + |
| 66 | + - name: Commit and push if there are changes |
| 67 | + shell: bash |
| 68 | + env: |
| 69 | + GH_PAT: ${{ secrets.ACTIONS_PUSH_PAT }} |
| 70 | + run: | |
| 71 | + set -euo pipefail |
| 72 | + git config user.name "agray" |
| 73 | + git config user.email "agray@users.noreply.github.com" |
| 74 | + export GIT_AUTHOR_NAME="agray" |
| 75 | + export GIT_AUTHOR_EMAIL="agray@users.noreply.github.com" |
| 76 | + export GIT_COMMITTER_NAME="agray" |
| 77 | + export GIT_COMMITTER_EMAIL="agray@users.noreply.github.com" |
| 78 | +
|
| 79 | + git add -A |
| 80 | +
|
| 81 | + if git diff --cached --quiet; then |
| 82 | + echo "✅ No changes detected after running sync-package-versions.ps1" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | +
|
| 86 | + git commit -m "Automated version sync" |
| 87 | + git pull --rebase origin master |
| 88 | +
|
| 89 | + echo "🔐 Using PAT to push changes..." |
| 90 | + git push "https://x-access-token:${GH_PAT}@github.com/${{ github.repository }}" HEAD:master |
| 91 | +
|
| 92 | + echo "🚀 Changes committed and pushed to master via PAT." |
0 commit comments