|
| 1 | +name: NuGet Package Update |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Runs at 00:00 UTC every day |
| 6 | + - cron: '0 0 * * *' |
| 7 | + # Allow manual triggering |
| 8 | + workflow_dispatch: |
| 9 | + |
| 10 | +env: |
| 11 | + DOTNET_VERSION: "9.x.x" |
| 12 | + SOLUTION_DIR: "VisualPairCoding" |
| 13 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 14 | + |
| 15 | +jobs: |
| 16 | + update-nuget: |
| 17 | + name: Update NuGet Packages |
| 18 | + runs-on: ubuntu-latest |
| 19 | + |
| 20 | + steps: |
| 21 | + - name: Checkout repository |
| 22 | + uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + # Fetch all history for all branches and tags |
| 25 | + fetch-depth: 0 |
| 26 | + |
| 27 | + - name: Setup .NET Core |
| 28 | + uses: actions/setup-dotnet@v3 |
| 29 | + with: |
| 30 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 31 | + |
| 32 | + - name: Install NuGet updater |
| 33 | + run: dotnet tool install -g dotnet-outdated-tool |
| 34 | + |
| 35 | + - name: Set up Git identity |
| 36 | + run: | |
| 37 | + git config --global user.name 'github-actions[bot]' |
| 38 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 39 | +
|
| 40 | + - name: Check for outdated packages |
| 41 | + id: check-updates |
| 42 | + run: | |
| 43 | + cd Source/${{ env.SOLUTION_DIR }} |
| 44 | + # Get list of outdated packages |
| 45 | + dotnet list package --outdated --include-transitive --highest-minor | tee outdated.txt |
| 46 | + # Check if there are any updates available |
| 47 | + if grep -q '> ' outdated.txt; then |
| 48 | + echo "updates_available=true" >> $GITHUB_OUTPUT |
| 49 | + else |
| 50 | + echo "No package updates found." |
| 51 | + echo "updates_available=false" >> $GITHUB_OUTPUT |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Update packages |
| 55 | + if: steps.check-updates.outputs.updates_available == 'true' |
| 56 | + run: | |
| 57 | + cd Source/${{ env.SOLUTION_DIR }} |
| 58 | + # Update all packages to latest version |
| 59 | + dotnet outdated -u |
| 60 | + # Restore packages after update |
| 61 | + dotnet restore |
| 62 | +
|
| 63 | + - name: Build and test |
| 64 | + if: steps.check-updates.outputs.updates_available == 'true' |
| 65 | + run: | |
| 66 | + cd Source/${{ env.SOLUTION_DIR }} |
| 67 | + dotnet build --configuration Release --no-restore |
| 68 | + dotnet test --no-build --verbosity normal --logger "console;verbosity=normal" |
| 69 | +
|
| 70 | + - name: Create Pull Request |
| 71 | + if: steps.check-updates.outputs.updates_available == 'true' && github.event_name == 'schedule' |
| 72 | + uses: peter-evans/create-pull-request@v5 |
| 73 | + with: |
| 74 | + commit-message: "chore: update NuGet packages" |
| 75 | + title: "chore: update NuGet packages" |
| 76 | + body: | |
| 77 | + Automated update of NuGet packages. |
| 78 | + |
| 79 | + This PR was automatically generated by the NuGet package update workflow. |
| 80 | + branch: feature/update-nuget-packages |
| 81 | + delete-branch: true |
| 82 | + draft: false |
| 83 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 84 | + |
| 85 | + - name: Commit and push changes |
| 86 | + if: steps.check-updates.outputs.updates_available == 'true' && github.event_name == 'workflow_dispatch' |
| 87 | + run: | |
| 88 | + git add . |
| 89 | + git diff --quiet && git diff --staged --quiet || \ |
| 90 | + (git commit -m "chore: update NuGet packages" && \ |
| 91 | + git push origin HEAD:main) |
0 commit comments