Skip to content

Commit 263b9fd

Browse files
committed
feat: Update GitHub Actions workflow to improve CI permissions and version handling
1 parent af69eed commit 263b9fd

File tree

2 files changed

+85
-52
lines changed

2 files changed

+85
-52
lines changed

.github/workflows/build.yml

Lines changed: 84 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,74 @@
1-
name: Build and Test
1+
name: .NET Build and Test
2+
3+
permissions:
4+
contents: read
5+
checks: write
6+
pull-requests: write
27

38
on:
49
push:
5-
branches: [ main ]
6-
tags: [ 'v*' ]
10+
branches: [ main, develop ]
11+
tags: [ 'v*' ] # Trigger on version tags
712
pull_request:
8-
branches: [ main ]
13+
branches: [ main, develop ]
914

1015
env:
11-
DOTNET_VERSION: '9.x'
12-
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 'true'
13-
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'
16+
DOTNET_VERSION: '9.0.x'
17+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
18+
DOTNET_NOLOGO: true
19+
DOTNET_CLI_TELEMETRY_OPTOUT: true
20+
CI: true
1421

1522
jobs:
23+
# Check if we should skip build for markdown-only changes
1624
check-changes:
1725
runs-on: ubuntu-latest
1826
outputs:
19-
should-skip: ${{ steps.skip-check.outputs.should_skip }}
27+
should-skip: ${{ steps.skip-check.outputs.should-skip }}
28+
paths-result: ${{ steps.skip-check.outputs.paths-result }}
2029
steps:
21-
- id: skip-check
30+
- name: Checkout code
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
35+
- name: Check for non-markdown changes
36+
id: skip-check
2237
uses: fkirc/skip-duplicate-actions@v5
2338
with:
24-
concurrent_skipping: 'same_content_newer'
25-
skip_after_successful_duplicate: 'true'
26-
paths_ignore: '["**/*.md", "**/docs/**"]'
39+
# Skip if only markdown files changed
40+
paths_ignore: '["**/*.md", "doc/**", "**/README*", "**/CHANGELOG*", "**/LICENSE*"]' # Don't skip on main branch or tags
41+
skip_after_successful_duplicate: 'false'
2742

43+
# Simple job for markdown-only changes
44+
markdown-check:
45+
runs-on: ubuntu-latest
46+
needs: check-changes
47+
if: needs.check-changes.outputs.should-skip == 'true'
48+
steps:
49+
- name: Documentation changes only
50+
run: |
51+
echo "✅ Only documentation files were changed - skipping build"
52+
echo "📝 Changes detected in markdown files only"
2853
build:
29-
runs-on: ${{ matrix.os }}
54+
runs-on: ubuntu-latest
3055
needs: check-changes
3156
if: needs.check-changes.outputs.should-skip != 'true'
3257

33-
strategy:
34-
matrix:
35-
os: [ubuntu-latest, windows-latest, macos-latest]
36-
configuration: [Release]
37-
3858
steps:
3959
- name: Checkout code
4060
uses: actions/checkout@v4
61+
with:
62+
fetch-depth: 0 # Shallow clones should be disabled for better analysis
4163

4264
- name: Setup .NET
4365
uses: actions/setup-dotnet@v4
4466
with:
4567
dotnet-version: ${{ env.DOTNET_VERSION }}
4668

69+
- name: Display .NET info
70+
run: dotnet --info
71+
4772
- name: Cache NuGet packages
4873
uses: actions/cache@v4
4974
with:
@@ -56,7 +81,7 @@ jobs:
5681
run: dotnet restore
5782

5883
- name: Build solution
59-
run: dotnet build --configuration ${{ matrix.configuration }} --no-restore --verbosity minimal
84+
run: dotnet build --configuration Release --no-restore --verbosity minimal
6085

6186
- name: Test solution
6287
run: |
@@ -65,7 +90,7 @@ jobs:
6590
6691
if [ -n "$TEST_PROJECTS" ]; then
6792
echo "Found test projects, running tests..."
68-
dotnet test --configuration ${{ matrix.configuration }} --no-build --verbosity minimal --logger "trx;LogFileName=test-results-${{ matrix.configuration }}.trx" --results-directory TestResults/
93+
dotnet test --configuration Release --no-build --verbosity minimal --logger "trx;LogFileName=test-results-Release.trx" --results-directory TestResults/
6994
else
7095
echo "No test projects found - skipping tests"
7196
mkdir -p TestResults
@@ -74,33 +99,60 @@ jobs:
7499
continue-on-error: false
75100

76101
- name: Build demo application
77-
run: dotnet build demo --configuration ${{ matrix.configuration }} --no-restore --verbosity minimal
102+
run: dotnet build demo --configuration Release --no-restore --verbosity minimal
78103

79104
- name: Publish test results
80105
uses: dorny/test-reporter@v1
81106
if: success() || failure()
82107
with:
83-
name: Test Results (${{ matrix.configuration }})
108+
name: Test Results (Release)
84109
path: TestResults/*.trx
85110
reporter: dotnet-trx
86111
fail-on-error: false
87112
fail-on-empty: false
113+
env:
114+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
88115

89116
- name: Upload build artifacts
90-
if: matrix.configuration == 'Release'
91117
uses: actions/upload-artifact@v4
92118
with:
93-
name: build-artifacts-${{ matrix.os }}
119+
name: build-artifacts-Release
94120
path: |
95-
src/*/bin/Release/
121+
src/NLWebNet/bin/Release/
96122
demo/bin/Release/
97123
retention-days: 7
98124

99-
security-scan:
125+
code-quality:
100126
runs-on: ubuntu-latest
101-
needs: check-changes
127+
needs: [check-changes, build]
102128
if: needs.check-changes.outputs.should-skip != 'true'
129+
130+
steps:
131+
- name: Checkout code
132+
uses: actions/checkout@v4
133+
with:
134+
fetch-depth: 0
135+
136+
- name: Setup .NET
137+
uses: actions/setup-dotnet@v4
138+
with:
139+
dotnet-version: ${{ env.DOTNET_VERSION }}
103140

141+
- name: Restore dependencies
142+
run: dotnet restore
143+
144+
- name: Run code analysis
145+
run: |
146+
dotnet build --configuration Release --verbosity minimal --warnaserror
147+
148+
- name: Check formatting
149+
run: dotnet format --verify-no-changes --verbosity diagnostic
150+
151+
security-scan:
152+
runs-on: ubuntu-latest
153+
needs: [check-changes, build]
154+
if: needs.check-changes.outputs.should-skip != 'true'
155+
104156
steps:
105157
- name: Checkout code
106158
uses: actions/checkout@v4
@@ -122,7 +174,6 @@ jobs:
122174
else
123175
echo "✅ No vulnerable packages found."
124176
fi
125-
126177
package-validation:
127178
runs-on: ubuntu-latest
128179
needs: [check-changes, build]
@@ -137,9 +188,6 @@ jobs:
137188
with:
138189
dotnet-version: ${{ env.DOTNET_VERSION }}
139190

140-
- name: Fetch all tags for versioning
141-
run: git fetch --tags --force
142-
143191
- name: Restore dependencies
144192
run: dotnet restore
145193

@@ -150,9 +198,7 @@ jobs:
150198
if [[ $GITHUB_REF == refs/tags/v* ]]; then
151199
# Extract version from tag (remove 'v' prefix)
152200
VERSION=${GITHUB_REF#refs/tags/v}
153-
echo "📦 Using tag version: ${VERSION}"
154-
IS_RELEASE_TAG="true"
155-
else
201+
echo "📦 Using tag version: ${VERSION}" else
156202
# Get the latest git tag or use 0.1.0 as default
157203
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.1.0")
158204
@@ -164,25 +210,9 @@ jobs:
164210
SHORT_SHA=$(git rev-parse --short HEAD)
165211
VERSION="${VERSION}-alpha.${COMMITS_SINCE_TAG}+${SHORT_SHA}"
166212
echo "📦 Using development version: ${VERSION}"
167-
IS_RELEASE_TAG="false"
168-
fi
169-
170-
echo "version=${VERSION}" >> $GITHUB_OUTPUT
171-
echo "is_release_tag=${IS_RELEASE_TAG}" >> $GITHUB_OUTPUT
172-
173-
- name: Check version output
174-
run: |
175-
if [ -z "${{ steps.version.outputs.version }}" ]; then
176-
echo "❌ PackageVersion is not set!"
177-
echo "Debug info:"
178-
echo "GITHUB_REF: $GITHUB_REF"
179-
echo "Available tags:"
180-
git tag -l
181-
exit 1
182-
else
183-
echo "✅ PackageVersion: ${{ steps.version.outputs.version }}"
184-
echo "✅ Is release tag: ${{ steps.version.outputs.is_release_tag }}"
185213
fi
214+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
215+
echo "is_release_tag=$([[ $GITHUB_REF == refs/tags/v* ]] && echo 'true' || echo 'false')" >> $GITHUB_OUTPUT
186216
187217
- name: Build (Release) for packaging
188218
run: dotnet build src/NLWebNet --configuration Release --no-restore --verbosity minimal
@@ -223,3 +253,5 @@ jobs:
223253
tag_name: ${{ github.ref_name }}
224254
env:
225255
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
256+
257+

doc/todo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,6 +510,7 @@ Comprehensive testing and validation infrastructure has been implemented coverin
510510
- [x] ✅ Verify symbols package (.snupkg) generation - Package ready
511511
- [x] ✅ Confirm README.md and metadata inclusion - All metadata validated
512512
- [x] ✅ Fix CI versioning issue - Updated GitHub Actions workflow with proper version determination and validation
513+
- [x] ✅ Fix CI permissions issue - Added checks: write permissions and GITHUB_TOKEN for test-reporter action
513514
- [x]**COMPLETED**: Update documentation with confirmed usage patterns
514515

515516
### Phase 11: Deployment & Production Readiness

0 commit comments

Comments
 (0)