Skip to content

Commit f1a634c

Browse files
committed
organization, improves CI
1 parent 0dcaf29 commit f1a634c

File tree

7 files changed

+99
-116
lines changed

7 files changed

+99
-116
lines changed
Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,44 @@
1-
name: build-and-test
1+
name: build-and-test
2+
3+
permissions:
4+
contents: read
5+
6+
concurrency:
7+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
8+
cancel-in-progress: true
9+
210
on:
3-
# Testing - run for any PRs.
411
pull_request:
512
branches:
613
- main
14+
workflow_dispatch:
715

816
env:
9-
"PipelineEnvironment": true
17+
PipelineEnvironment: true
18+
NUGET_XMLDOC_MODE: skip
1019

1120
jobs:
1221
build-and-test:
1322
runs-on: ubuntu-latest
1423

1524
steps:
1625
- uses: actions/checkout@v6
26+
with:
27+
persist-credentials: false
1728

1829
- name: Setup .NET
1930
uses: actions/setup-dotnet@v5
2031
with:
2132
dotnet-version: 10.0.x
2233

23-
- name: Install dependencies with retry
24-
run: |
25-
retries=5
26-
base_wait_time=15
27-
exponent=2
28-
29-
for i in $(seq 1 $retries); do
30-
if dotnet restore; then
31-
break
32-
fi
33-
34-
if [ $i -lt $retries ]; then
35-
wait_time=$(awk "BEGIN {print int($base_wait_time * ($exponent ^ ($i - 1)))}")
36-
echo "dotnet restore failed, retrying in $wait_time seconds..."
37-
sleep $wait_time
38-
else
39-
echo "dotnet restore failed after $retries retries."
40-
exit 1
41-
fi
42-
done
43-
44-
- name: Build
45-
run: dotnet build --configuration Release --no-restore
34+
- name: Restore tests
35+
run: dotnet restore test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --verbosity minimal
36+
37+
- name: Build tests
38+
run: dotnet build test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --configuration Release --no-restore --verbosity minimal
4639

4740
- name: Test
48-
run: dotnet test test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --no-restore --verbosity normal
41+
run: dotnet test test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --configuration Release --no-build --no-restore --verbosity minimal
4942

5043
- name: Pack
51-
run: dotnet pack --no-build --configuration Release --output .
44+
run: dotnet pack src/Soenneker.Utils.Strings.DiceCoefficient/Soenneker.Utils.Strings.DiceCoefficient.csproj --configuration Release --no-build --no-restore --output . --verbosity minimal

.github/workflows/codeql.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
name: codeql
22

3+
concurrency:
4+
group: ${{ github.workflow }}-${{ github.ref }}
5+
cancel-in-progress: true
6+
37
on:
48
push:
59
branches: [ "main" ]
610
paths-ignore:
711
- 'test/**'
12+
workflow_dispatch:
813

9-
concurrency:
10-
group: ${{ github.workflow }}-${{ github.ref }}
11-
cancel-in-progress: true
14+
env:
15+
NUGET_XMLDOC_MODE: skip
1216

1317
permissions:
1418
actions: read
@@ -23,6 +27,8 @@ jobs:
2327
steps:
2428
- name: Checkout repository
2529
uses: actions/checkout@v6
30+
with:
31+
persist-credentials: false
2632

2733
- name: Setup .NET
2834
uses: actions/setup-dotnet@v5
@@ -36,10 +42,10 @@ jobs:
3642
build-mode: manual
3743

3844
- name: Restore src
39-
run: dotnet restore ./src
45+
run: dotnet restore ./src/Soenneker.Utils.Strings.DiceCoefficient/Soenneker.Utils.Strings.DiceCoefficient.csproj --verbosity minimal
4046

4147
- name: Build src
42-
run: dotnet build ./src --no-restore -c Release
48+
run: dotnet build ./src/Soenneker.Utils.Strings.DiceCoefficient/Soenneker.Utils.Strings.DiceCoefficient.csproj --configuration Release --no-restore --verbosity minimal
4349

4450
- name: Perform CodeQL Analysis
4551
uses: github/codeql-action/analyze@v4
Lines changed: 55 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
name: publish-package
2+
23
concurrency:
34
group: ${{ github.workflow }}-${{ github.ref }}
45
cancel-in-progress: true
@@ -9,115 +10,94 @@ on:
910
- main
1011
paths-ignore:
1112
- 'test/**'
13+
workflow_dispatch:
1214

15+
permissions:
16+
contents: write
17+
packages: write
1318

1419
env:
15-
"PipelineEnvironment": true
20+
PipelineEnvironment: true
21+
NUGET_XMLDOC_MODE: skip
1622

1723
jobs:
1824
publish-package:
1925
runs-on: ubuntu-latest
2026

2127
steps:
2228
- uses: actions/checkout@v6
23-
29+
with:
30+
persist-credentials: false
31+
2432
- name: Setting up build version
33+
shell: bash
34+
run: |
35+
echo "BUILD_VERSION=4.0.${GITHUB_RUN_NUMBER}" >> "$GITHUB_ENV"
36+
37+
- name: Get release notes from latest commit
38+
shell: bash
2539
run: |
26-
version=$(($GITHUB_RUN_NUMBER))
27-
echo "BUILD_VERSION=4.0.$version" >> ${GITHUB_ENV}
40+
{
41+
echo "PACKAGE_RELEASE_NOTES<<EOF"
42+
git log -1 --pretty=%B
43+
echo "EOF"
44+
} >> "$GITHUB_ENV"
2845
2946
- name: Setup .NET
3047
uses: actions/setup-dotnet@v5
3148
with:
3249
dotnet-version: 10.0.x
3350

34-
- name: Install dependencies with retry
35-
run: |
36-
retries=5
37-
base_wait_time=15
38-
exponent=2
39-
40-
for i in $(seq 1 $retries); do
41-
if dotnet restore; then
42-
break
43-
fi
44-
45-
if [ $i -lt $retries ]; then
46-
wait_time=$(awk "BEGIN {print int($base_wait_time * ($exponent ^ ($i - 1)))}")
47-
echo "dotnet restore failed, retrying in $wait_time seconds..."
48-
sleep $wait_time
49-
else
50-
echo "dotnet restore failed after $retries retries."
51-
exit 1
52-
fi
53-
done
51+
- name: Restore tests
52+
run: dotnet restore test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --verbosity minimal
5453

5554
- name: Build
56-
run: dotnet build --configuration Release --no-restore
55+
run: dotnet build test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --configuration Release --no-restore --verbosity minimal
5756

5857
- name: Test
59-
run: dotnet test test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --no-restore --verbosity normal
58+
run: dotnet test test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj --configuration Release --no-build --no-restore --verbosity normal
6059

6160
- name: Pack
62-
run: dotnet pack --no-build --configuration Release --output .
61+
shell: bash
62+
run: |
63+
mkdir -p artifacts
64+
dotnet pack src/Soenneker.Utils.Strings.DiceCoefficient/Soenneker.Utils.Strings.DiceCoefficient.csproj \
65+
--configuration Release \
66+
--no-build \
67+
--no-restore \
68+
--output ./artifacts
6369
6470
- name: Publish to NuGet with retry
71+
shell: bash
6572
run: |
66-
nupkg_files=$(find . -name "*.nupkg")
67-
retries=5
68-
base_wait_time=20
69-
exponent=3.5
70-
71-
for i in $(seq 1 $retries); do
72-
if dotnet nuget push $nupkg_files --source 'https://api.nuget.org/v3/index.json' --api-key ${{secrets.NUGET__TOKEN}} --skip-duplicate; then
73-
break
74-
fi
75-
76-
if [ $i -lt $retries ]; then
77-
wait_time=$(awk "BEGIN {print int($base_wait_time * ($exponent ^ ($i - 1)))}")
78-
echo "NuGet publish failed, retrying in $wait_time seconds..."
79-
sleep $wait_time
73+
for i in 1 2 3; do
74+
dotnet nuget push ./artifacts/*.nupkg \
75+
--source "https://api.nuget.org/v3/index.json" \
76+
--api-key "${{ secrets.NUGET__TOKEN }}" \
77+
--skip-duplicate && break
78+
79+
if [ "$i" -lt 3 ]; then
80+
echo "NuGet publish failed, retrying in 10 seconds..."
81+
sleep 10
8082
else
81-
echo "NuGet publish failed after $retries retries."
83+
echo "NuGet publish failed after 3 attempts."
8284
exit 1
8385
fi
8486
done
8587
86-
- name: Add GitHub NuGet Source
87-
run: |
88-
dotnet nuget add source https://nuget.pkg.github.com/soenneker/index.json \
89-
--name "github" \
90-
--username "any" \
91-
--password ${{ secrets.GH__TOKEN }} \
92-
--store-password-in-clear-text
93-
9488
- name: Publish to GitHub Packages
89+
shell: bash
9590
run: |
96-
dotnet nuget push ./*.nupkg \
97-
--source "github" \
98-
--api-key ${{ secrets.GH__TOKEN }}
91+
dotnet nuget push ./artifacts/*.nupkg \
92+
--source "https://nuget.pkg.github.com/soenneker/index.json" \
93+
--api-key "${{ secrets.GH__TOKEN }}" \
94+
--skip-duplicate
9995
10096
- name: Create GitHub Release
97+
env:
98+
GH_TOKEN: ${{ secrets.GH__TOKEN }}
99+
shell: bash
101100
run: |
102-
changelog=$(git log -20 --pretty=format:"- %s")
103-
tag_name="v$BUILD_VERSION"
104-
105-
json_payload=$(
106-
jq -n \
107-
--arg tag_name "$tag_name" \
108-
--arg name "$tag_name" \
109-
--arg body "$changelog" \
110-
'{
111-
tag_name: $tag_name,
112-
name: $name,
113-
body: $body,
114-
draft: false,
115-
prerelease: false
116-
}'
117-
)
118-
119-
curl -s -X POST \
120-
-H "Authorization: Bearer ${{ secrets.GH__TOKEN }}" \
121-
-H "Accept: application/vnd.github+json" \
122-
https://api.github.com/repos/${{ github.repository }}/releases \
123-
-d "$json_payload"
101+
gh release create "v$BUILD_VERSION" \
102+
--title "v$BUILD_VERSION" \
103+
--notes "${{ env.PACKAGE_RELEASE_NOTES }}"

Soenneker.Utils.Strings.DiceCoefficient.slnx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
</Folder>
55
<Folder Name="/.github/workflows/">
66
<File Path=".github/workflows/build-and-test.yml" />
7+
<File Path=".github/workflows/codeql.yml" />
78
<File Path=".github/workflows/publish-package.yml" />
89
</Folder>
910
<Folder Name="/src/">
10-
<Project Path="src/Soenneker.Utils.Strings.DiceCoefficient.csproj" />
11+
<Project Path="src/Soenneker.Utils.Strings.DiceCoefficient/Soenneker.Utils.Strings.DiceCoefficient.csproj" />
1112
</Folder>
1213
<Folder Name="/test/">
1314
<Project Path="test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj" />
1415
</Folder>
15-
</Solution>
16+
</Solution>

src/DiceCoefficientStringUtil.cs renamed to src/Soenneker.Utils.Strings.DiceCoefficient/DiceCoefficientStringUtil.cs

File renamed without changes.

src/Soenneker.Utils.Strings.DiceCoefficient.csproj renamed to src/Soenneker.Utils.Strings.DiceCoefficient/Soenneker.Utils.Strings.DiceCoefficient.csproj

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?><Project Sdk="Microsoft.NET.Sdk">
1+
<?xml version="1.0" encoding="utf-8"?><Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
44
<TargetFramework>net10.0</TargetFramework>
@@ -32,12 +32,15 @@
3232
<LangVersion>latest</LangVersion>
3333
<PackageReadmeFile>README.md</PackageReadmeFile>
3434
<PackageIcon>icon.png</PackageIcon>
35-
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild></PropertyGroup>
35+
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
36+
<PackageReleaseNotes Condition="'$(PACKAGE_RELEASE_NOTES)' != ''">
37+
$(PACKAGE_RELEASE_NOTES)
38+
</PackageReleaseNotes></PropertyGroup>
3639

3740
<ItemGroup>
38-
<None Include="..\README.md" Pack="true" PackagePath="\" />
39-
<None Include="..\LICENSE" Pack="true" PackagePath="\" />
40-
<None Include="..\icon.png" Pack="true" PackagePath="\" />
41+
<None Include="..\..\README.md" Pack="true" PackagePath="\" />
42+
<None Include="..\..\LICENSE" Pack="true" PackagePath="\" />
43+
<None Include="..\..\icon.png" Pack="true" PackagePath="\" />
4144
</ItemGroup>
4245

4346
<ItemGroup>

test/Soenneker.Utils.Strings.DiceCoefficient.Tests/Soenneker.Utils.Strings.DiceCoefficient.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
<PackageReference Include="xUnit.v3" Version="3.2.2" /></ItemGroup>
2727

2828
<ItemGroup>
29-
<ProjectReference Include="..\..\src\Soenneker.Utils.Strings.DiceCoefficient.csproj" />
29+
<ProjectReference Include="..\..\src\Soenneker.Utils.Strings.DiceCoefficient\Soenneker.Utils.Strings.DiceCoefficient.csproj" />
3030
</ItemGroup>
3131

3232
<ItemGroup>

0 commit comments

Comments
 (0)