|
4 | 4 | name: .NET |
5 | 5 |
|
6 | 6 | on: |
7 | | - push: |
8 | | - branches: [ "master" ] |
9 | 7 | pull_request: |
10 | 8 | branches: [ "master" ] |
| 9 | + push: |
| 10 | + branches: [ "master" ] |
11 | 11 |
|
12 | | - # Trigger build workflow ONLY after Auto Sync Lock Files workflow completes for dependabot NuGet branches |
13 | | - repository_dispatch: |
14 | | - types: [ dependabot-auto-sync-completed ] |
| 12 | +concurrency: |
| 13 | + group: build-${{ github.event.pull_request.number || github.ref }} |
| 14 | + cancel-in-progress: true |
15 | 15 |
|
16 | 16 | jobs: |
| 17 | + auto-sync: |
| 18 | + name: Auto Sync Lock Files (Dependabot only) |
| 19 | + if: github.event_name == 'pull_request' && github.actor == 'dependabot[bot]' && startsWith(github.head_ref, 'dependabot/nuget/') |
| 20 | + uses: ./.github/workflows/nuget-lockfile-sync.yml |
| 21 | + |
17 | 22 | build: |
| 23 | + name: Build |
| 24 | + needs: [auto-sync] |
18 | 25 | runs-on: ubuntu-latest |
19 | | - # For repository_dispatch, always run (it's triggered only when Auto Sync completes successfully) |
20 | | - # For push/pull_request, exclude dependabot PRs (they use repository_dispatch) |
21 | | - if: | |
22 | | - github.event_name == 'repository_dispatch' || |
23 | | - (github.event_name != 'repository_dispatch' && !(github.actor == 'dependabot[bot]' && github.event_name == 'pull_request')) |
24 | | -
|
| 26 | + if: needs.auto-sync.result != 'failure' && (needs.auto-sync.outputs.commit_pushed != 'true') |
25 | 27 | steps: |
26 | | - - uses: actions/checkout@v4 |
27 | | - with: |
28 | | - # For repository_dispatch, checkout the PR branch using client_payload data |
29 | | - ref: ${{ github.event_name == 'repository_dispatch' && github.event.client_payload.head_sha || github.ref }} |
30 | | - |
31 | | - - name: Create check run for dependabot PR |
32 | | - if: github.event_name == 'repository_dispatch' |
33 | | - id: check_run |
34 | | - uses: actions/github-script@v7 |
35 | | - with: |
36 | | - script: | |
37 | | - const { data: checkRun } = await github.rest.checks.create({ |
38 | | - owner: context.repo.owner, |
39 | | - repo: context.repo.repo, |
40 | | - name: 'Build (.NET)', |
41 | | - head_sha: '${{ github.event.client_payload.head_sha }}', |
42 | | - status: 'in_progress', |
43 | | - started_at: new Date().toISOString(), |
44 | | - }); |
45 | | - core.setOutput('check_run_id', checkRun.id); |
46 | | - return checkRun.id; |
47 | | - |
48 | | - - name: Setup .NET |
49 | | - uses: actions/setup-dotnet@v4 |
50 | | - with: |
51 | | - dotnet-version: 9.0.304 |
52 | | - - name: Restore dependencies |
53 | | - run: dotnet restore |
54 | | - - name: Build |
55 | | - run: dotnet build --no-restore |
56 | | - |
57 | | - - name: Update check run on success |
58 | | - if: github.event_name == 'repository_dispatch' && success() |
59 | | - uses: actions/github-script@v7 |
60 | | - with: |
61 | | - script: | |
62 | | - await github.rest.checks.update({ |
63 | | - owner: context.repo.owner, |
64 | | - repo: context.repo.repo, |
65 | | - check_run_id: '${{ steps.check_run.outputs.check_run_id }}', |
66 | | - status: 'completed', |
67 | | - conclusion: 'success', |
68 | | - completed_at: new Date().toISOString(), |
69 | | - }); |
70 | | - |
71 | | - - name: Update check run on failure |
72 | | - if: github.event_name == 'repository_dispatch' && failure() |
73 | | - uses: actions/github-script@v7 |
74 | | - with: |
75 | | - script: | |
76 | | - await github.rest.checks.update({ |
77 | | - owner: context.repo.owner, |
78 | | - repo: context.repo.repo, |
79 | | - check_run_id: '${{ steps.check_run.outputs.check_run_id }}', |
80 | | - status: 'completed', |
81 | | - conclusion: 'failure', |
82 | | - completed_at: new Date().toISOString(), |
83 | | - }); |
| 28 | + - name: Checkout |
| 29 | + uses: actions/checkout@v4 |
| 30 | + with: |
| 31 | + ref: ${{ github.head_ref || github.ref }} |
| 32 | + - name: Setup .NET |
| 33 | + uses: actions/setup-dotnet@v4 |
| 34 | + with: |
| 35 | + dotnet-version: 9.0.304 |
| 36 | + - name: Restore dependencies |
| 37 | + run: dotnet restore --locked-mode |
| 38 | + - name: Build |
| 39 | + run: dotnet build --no-restore |
0 commit comments