Skip to content

Commit f1cc2d8

Browse files
authored
Workflow refactoring and improvements (#273)
* Remove code coverage PR commenting * Only run markdown-link-check when markdown files are updated * Declare CI workflow permissions * Refactor release workflow and declare permissions * Pin all actions to SHAs * Run CI manually, on all pushes to main, or if code changes in a PR * NuGet publishing doesn't need any permissions
1 parent adb95c8 commit f1cc2d8

File tree

5 files changed

+112
-49
lines changed

5 files changed

+112
-49
lines changed

.github/workflows/ci.yml renamed to .github/workflows/ci-build-test.yml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
11
name: Build and Test
22

33
on:
4+
# Manual trigger
5+
workflow_dispatch:
6+
7+
# Run CI for all pushes to main
48
push:
59
branches: ["main"]
10+
11+
# Run CI for pull requests to all branches, but only if code changed
612
pull_request:
7-
branches: ["main"]
13+
paths:
14+
- ".github/workflows/ci-*.yml"
15+
- "*.sln"
16+
- "*.props"
17+
- "Makefile"
18+
- "src/**"
19+
- "tests/**"
20+
- "samples/**"
21+
22+
permissions:
23+
contents: read
824

925
jobs:
1026
build:
@@ -18,12 +34,12 @@ jobs:
1834

1935
steps:
2036
- name: Clone the repo
21-
uses: actions/checkout@v4
37+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
2238
with:
2339
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
2440

2541
- name: Set up .NET
26-
uses: actions/setup-dotnet@v4
42+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
2743
with:
2844
dotnet-version: |
2945
9.0.x
@@ -35,7 +51,7 @@ jobs:
3551
run: sudo apt-get install -y mono-devel
3652

3753
- name: Set up Node.js
38-
uses: actions/setup-node@v3
54+
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4.3.0
3955
with:
4056
node-version: '20'
4157

@@ -68,13 +84,13 @@ jobs:
6884
6985
- name: Upload test results artifact
7086
if: always()
71-
uses: actions/upload-artifact@v4
87+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
7288
with:
7389
name: testresults-${{ matrix.os }}-${{ matrix.configuration }}
7490
path: testresults/**
7591

7692
publish-coverage:
7793
if: github.actor != 'dependabot[bot]'
7894
needs: build
79-
uses: ./.github/workflows/code-coverage.yml
95+
uses: ./.github/workflows/ci-code-coverage.yml
8096
secrets: inherit

.github/workflows/code-coverage.yml renamed to .github/workflows/ci-code-coverage.yml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ name: Code Coverage
33
on:
44
workflow_call:
55

6+
permissions:
7+
contents: read
8+
69
jobs:
710
publish-coverage:
811
runs-on: ubuntu-latest
912
steps:
10-
- uses: actions/checkout@v4
13+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1114
- name: Setup .NET
12-
uses: actions/setup-dotnet@v4
15+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
1316
with:
1417
dotnet-version: |
1518
9.0.x
1619
8.0.x
1720
1821
- name: Download test results
19-
uses: actions/download-artifact@v4
22+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
2023
with:
2124
pattern: testresults-*
2225

@@ -33,14 +36,14 @@ jobs:
3336
toolpath: "reportgeneratortool"
3437

3538
- name: Upload combined coverage XML
36-
uses: actions/upload-artifact@v4
39+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
3740
with:
3841
name: coverage
3942
path: ${{ github.workspace }}/report
4043
retention-days: 7
4144

4245
- name: Publish code coverage report
43-
uses: irongut/[email protected]
46+
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
4447
with:
4548
filename: "report/Cobertura.xml"
4649
badge: true
@@ -53,19 +56,12 @@ jobs:
5356
thresholds: "60 80"
5457

5558
- name: Upload combined coverage markdown
56-
uses: actions/upload-artifact@v4
59+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
5760
with:
5861
name: coverage-markdown
5962
path: ${{ github.workspace }}/code-coverage-results.md
6063
retention-days: 7
6164

62-
- name: Add Coverage PR Comment
63-
uses: marocchino/sticky-pull-request-comment@v2
64-
if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository
65-
with:
66-
recreate: true
67-
path: ${{ github.workspace }}/code-coverage-results.md
68-
6965
- name: Coverage on step summary
7066
if: always()
7167
run: cat "${{ github.workspace }}/report/SummaryGithub.md" >> $GITHUB_STEP_SUMMARY

.github/workflows/docs.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77

88
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
99
permissions:
10-
actions: read
10+
contents: read
1111
pages: write
12-
id-token: write
12+
id-token: write # Required for actions/deploy-pages
1313

1414
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
1515
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
@@ -27,21 +27,21 @@ jobs:
2727
runs-on: ubuntu-latest
2828
steps:
2929
- name: Checkout
30-
uses: actions/checkout@v3
30+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3131

3232
- name: .NET Setup
33-
uses: actions/setup-dotnet@v4
33+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
3434
with:
3535
dotnet-version: 9.x
3636

3737
- name: Generate documentation
3838
run: make generate-docs
3939

4040
- name: Upload Pages artifact
41-
uses: actions/upload-pages-artifact@v3
41+
uses: actions/upload-pages-artifact@56afc609e74202658d3ffba0e8f6dda462b719fa # v3.0.1
4242
with:
4343
path: 'artifacts/_site'
4444

4545
- name: Deploy to GitHub Pages
4646
id: deployment
47-
uses: actions/deploy-pages@v4
47+
uses: actions/deploy-pages@d6db90164ac5ed86f2b6aed7e0febac5b3c0c03e # v4.0.5
Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
name: Check Markdown links
22

33
on:
4-
push:
5-
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
4+
push:
5+
branches: [ "main" ]
6+
paths: "**.md"
7+
pull_request:
8+
branches: [ "main" ]
9+
paths: "**.md"
10+
11+
permissions:
12+
contents: read
813

914
jobs:
1015
markdown-link-check:
1116
runs-on: ubuntu-latest
1217
steps:
1318
- name: Checkout
14-
uses: actions/checkout@main
19+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
1520

1621
- name: Markup Link Checker (mlc)
17-
uses: becheran/[email protected]
22+
uses: becheran/mlc@c925f90a9a25e16e4c4bfa29058f6f9ffa9f0d8c # v0.21.0
1823
with:
1924
# Ignore external links that result in 403 errors during CI. Do not warn for redirects where we want to keep the vanity URL in the markdown or for GitHub links that redirect to the login.
2025
args: --ignore-links "https://www.anthropic.com/*,https://hackerone.com/anthropic-vdp/*" --do-not-warn-for-redirect-to "https://modelcontextprotocol.io/*,https://github.com/login?*" ./

.github/workflows/release.yml

Lines changed: 64 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,17 @@ jobs:
4040

4141
runs-on: ${{ matrix.os }}
4242

43+
permissions:
44+
contents: read
45+
4346
steps:
4447
- name: Clone the repo
45-
uses: actions/checkout@v4
48+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4649
with:
4750
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
4851

4952
- name: Set up .NET
50-
uses: actions/setup-dotnet@v4
53+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
5154
with:
5255
dotnet-version: 9.0.x
5356

@@ -61,14 +64,17 @@ jobs:
6164
runs-on: windows-latest
6265
needs: build-all-configs
6366

67+
permissions:
68+
contents: read
69+
6470
env:
6571
version_suffix_args: ${{ github.event_name != 'release' && format('--version-suffix "{0}"', inputs.version_suffix_override || format('ci.{0}', github.run_number)) || '' }}
6672

6773
steps:
68-
- uses: actions/checkout@v4
74+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
6975

7076
- name: Setup .NET
71-
uses: actions/setup-dotnet@v2
77+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
7278
with:
7379
dotnet-version: |
7480
9.0.x
@@ -81,32 +87,29 @@ jobs:
8187
--output "${{ github.workspace }}/artifacts/packages"
8288

8389
- name: Upload artifact
84-
uses: actions/upload-artifact@v4
90+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2
8591
if: ${{ !cancelled() }}
8692
with:
8793
name: build-artifacts
8894
path: ${{ github.workspace }}/artifacts
8995

90-
publish-package:
96+
publish-github:
9197
needs: build-package
9298
runs-on: ubuntu-latest
99+
100+
permissions:
101+
packages: write
102+
93103
steps:
94-
- uses: actions/checkout@v4
104+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
95105

96106
- name: Setup .NET
97-
uses: actions/setup-dotnet@v2
107+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
98108
with:
99109
dotnet-version: 9.0.x
100110

101111
- name: Download build artifacts
102-
uses: actions/download-artifact@v4
103-
104-
- name: Upload release asset
105-
if: github.event_name == 'release'
106-
run: gh release upload ${{ github.event.release.tag_name }}
107-
${{ github.workspace }}/build-artifacts/packages/*.*nupkg
108-
env:
109-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
112+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
110113

111114
- name: Authenticate to GitHub registry
112115
run: dotnet nuget add source
@@ -123,9 +126,52 @@ jobs:
123126
--api-key ${{ secrets.GITHUB_TOKEN }}
124127
--skip-duplicate
125128

129+
publish-release:
130+
if: github.event_name == 'release'
131+
needs: build-package
132+
runs-on: ubuntu-latest
133+
134+
permissions:
135+
contents: write
136+
packages: write
137+
138+
steps:
139+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
140+
141+
- name: Setup .NET
142+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
143+
with:
144+
dotnet-version: 9.0.x
145+
146+
- name: Download build artifacts
147+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
148+
149+
- name: Upload release asset
150+
run: gh release upload ${{ github.event.release.tag_name }}
151+
${{ github.workspace }}/build-artifacts/packages/*.*nupkg
152+
env:
153+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
154+
155+
publish-nuget:
156+
# Only publish to NuGet.org from the modelcontextprotocol/csharp-sdk repository
157+
if: ${{ github.event_name == 'release' && github.repository == 'modelcontextprotocol/csharp-sdk' }}
158+
needs: build-package
159+
runs-on: ubuntu-latest
160+
161+
permissions: { }
162+
163+
steps:
164+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
165+
166+
- name: Setup .NET
167+
uses: actions/setup-dotnet@67a3573c9a986a3f9c594539f4ab511d57bb3ce9 # v4.3.1
168+
with:
169+
dotnet-version: 9.0.x
170+
171+
- name: Download build artifacts
172+
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4.2.1
173+
126174
- name: Publish to NuGet.org (Releases only)
127-
# Only publish to NuGet.org from the modelcontextprotocol/csharp-sdk repository
128-
if: ${{ github.event_name == 'release' && github.repository == 'modelcontextprotocol/csharp-sdk' }}
129175
run: dotnet nuget push
130176
${{github.workspace}}/build-artifacts/packages/*.nupkg
131177
--source https://api.nuget.org/v3/index.json

0 commit comments

Comments
 (0)