Skip to content

Commit d67ceb0

Browse files
committed
update workflows
1 parent 4273715 commit d67ceb0

File tree

3 files changed

+82
-114
lines changed

3 files changed

+82
-114
lines changed

.github/workflows/auto_restore.yml

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 25 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,80 +4,36 @@
44
name: .NET
55

66
on:
7-
push:
8-
branches: [ "master" ]
97
pull_request:
108
branches: [ "master" ]
9+
push:
10+
branches: [ "master" ]
1111

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
1515

1616
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+
1722
build:
23+
name: Build
24+
needs: [auto-sync]
1825
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')
2527
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
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Auto Sync Lock Files
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
dotnet-version:
7+
description: 'Dotnet SDK version'
8+
required: false
9+
type: string
10+
default: '9.0.304'
11+
secrets: {}
12+
13+
permissions:
14+
actions: read
15+
contents: write
16+
packages: read
17+
checks: write
18+
pull-requests: write
19+
20+
jobs:
21+
update-lock-files:
22+
name: Auto Sync Lock Files
23+
runs-on: ubuntu-latest
24+
outputs:
25+
commit_pushed: ${{ steps.sync_commit.outputs.commit_pushed }}
26+
steps:
27+
- name: Checkout Repo
28+
uses: actions/checkout@v4
29+
with:
30+
# For PR-triggered parent workflow, head_ref will be available via github.head_ref there; here we just checkout default ref passed in
31+
fetch-depth: 0
32+
33+
- name: Setup .NET
34+
uses: actions/setup-dotnet@v4
35+
with:
36+
dotnet-version: ${{ inputs.dotnet-version }}
37+
38+
- name: Force restore
39+
run: dotnet restore --force-evaluate
40+
41+
- name: Commit and Push Changes
42+
id: sync_commit
43+
shell: bash
44+
run: |
45+
set -euo pipefail
46+
git config --global user.name 'dependabot[bot]'
47+
git config --global user.email 'support@github.com'
48+
git add -A
49+
if git diff --cached --quiet; then
50+
echo 'No staged changes'
51+
echo 'commit_pushed=false' >> $GITHUB_OUTPUT
52+
else
53+
echo 'Committing updated lock files'
54+
git commit -m 'Update lock files'
55+
git push
56+
echo 'commit_pushed=true' >> $GITHUB_OUTPUT
57+
fi

0 commit comments

Comments
 (0)