Skip to content

Commit f9afe5a

Browse files
committed
build: Add release-please
1 parent 1cf3ebf commit f9afe5a

File tree

5 files changed

+116
-45
lines changed

5 files changed

+116
-45
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,50 @@
1-
# This workflow will build a .NET project
2-
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3-
4-
name: .NET
1+
name: release-please
52

63
on:
74
push:
8-
branches: [ "main" ]
9-
pull_request:
10-
branches: [ "main" ]
11-
workflow_dispatch:
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: write # required for tags + releases
9+
pull-requests: write # required for release PRs
1210

1311
jobs:
14-
build-test-publish:
12+
release-please:
13+
outputs:
14+
release_created: ${{ steps.release.outputs.release_created }}
15+
tag_name: ${{ steps.release.outputs.tag_name }}
16+
version: ${{ steps.release.outputs.version }}
1517
runs-on: ubuntu-latest
1618
steps:
17-
- uses: actions/checkout@v4
18-
- name: Setup .NET
19-
uses: actions/setup-dotnet@v4
19+
- name: Run release-please
20+
id: release
21+
uses: googleapis/release-please-action@v4
22+
with:
23+
token: ${{ secrets.GITHUB_TOKEN }}
24+
manifest-file: .release-please-manifest.json
25+
config-file: release-please-config.json
26+
27+
publish:
28+
needs:
29+
- release-please
30+
if: needs.release-please.outputs.release_created
31+
runs-on: ubuntu-latest
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v6
2035
with:
21-
dotnet-version: 9.0.x
36+
fetch-depth: 0
2237

2338
- uses: actions/cache@v4
2439
with:
2540
path: ~/.nuget/packages
26-
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
41+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj', 'Directory.Packages.props', 'nuget.config') }}
2742
restore-keys: |
2843
${{ runner.os }}-nuget
2944
45+
- name: Setup .NET
46+
uses: actions/setup-dotnet@v5
47+
3048
- name: Set up JDK 17
3149
uses: actions/setup-java@v3
3250
with:
@@ -38,32 +56,18 @@ jobs:
3856
run: |
3957
dotnet workload install android
4058
41-
- name: Check format
42-
run: |
43-
dotnet tool restore
44-
dotnet csharpier check .
45-
- name: Restore dependencies
46-
run: dotnet restore /p:EnableWindowsTargeting=true
59+
- name: Restore
60+
run: dotnet restore /p:EnableWindowsTargeting=true
4761
- name: Build
48-
run: dotnet build --no-restore --configuration Release /p:EnableWindowsTargeting=true
62+
run: dotnet build --configuration Release --no-restore /p:EnableWindowsTargeting=true
4963
- name: Test
50-
run: dotnet test --no-build --configuration Release
51-
52-
- if: github.event_name == 'push' && github.ref == 'refs/heads/main'
53-
name: Get release version
54-
id: semantic
55-
uses: cycjimmy/semantic-release-action@v4
56-
with:
57-
dry_run: true
58-
env:
59-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64+
run: dotnet test --configuration Release --no-build --no-restore
6065

61-
- if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.semantic.outputs.new_release_published == 'true'
62-
name: Pack and push to nuget.org
66+
- name: Pack and push to nuget.org
6367
run: |
6468
for file_name in ./src/**/*.csproj; do
65-
dotnet pack $file_name --configuration Release --artifacts-path build/noncommercial /p:PackageLicenseFile=LICENSE.md /p:Version=${{ steps.semantic.outputs.new_release_version }}
66-
dotnet pack $file_name --configuration Release --artifacts-path build/commercial /p:PackageLicenseFile=LICENSE-COMMERCIAL.md /p:Version=${{ steps.semantic.outputs.new_release_version }}
69+
dotnet pack $file_name --configuration Release --artifacts-path build/noncommercial /p:PackageLicenseFile=LICENSE.md /p:Version=${{ needs.release-please.outputs.version }}
70+
dotnet pack $file_name --configuration Release --artifacts-path build/commercial /p:PackageLicenseFile=LICENSE-COMMERCIAL.md /p:Version=${{ needs.release-please.outputs.version }}
6771
done
6872
for pkg_name in ./build/noncommercial/package**/*.nupkg; do
6973
dotnet nuget push $pkg_name --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
@@ -75,14 +79,9 @@ jobs:
7579
env:
7680
AZURE_ARTIFACTS_FEED_URL: https://pkgs.dev.azure.com/rosslight-engineering/darp.ble/_packaging/darp.ble.subscription/nuget/v3/index.json
7781

78-
- if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.semantic.outputs.new_release_published == 'true'
79-
name: Semantic Release
80-
id: release
81-
uses: cycjimmy/semantic-release-action@v4
82-
with:
83-
extra_plugins: |
84-
@semantic-release/commit-analyzer
85-
@semantic-release/release-notes-generator
86-
@semantic-release/github
82+
- name: Attach .nupkg to GitHub Release
8783
env:
88-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
85+
run: |
86+
gh release upload "${{ needs.release-please.outputs.tag_name }}" ./build/noncommercial/package**/*.nupkg \
87+
--repo "${{ github.repository }}"

.github/workflows/test.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# This workflow will build a .NET project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
3+
4+
name: Build and test
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
workflow_dispatch:
12+
13+
jobs:
14+
build-test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Setup .NET
19+
uses: actions/setup-dotnet@v4
20+
21+
- uses: actions/cache@v4
22+
with:
23+
path: ~/.nuget/packages
24+
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
25+
restore-keys: |
26+
${{ runner.os }}-nuget
27+
28+
- name: Set up JDK 17
29+
uses: actions/setup-java@v3
30+
with:
31+
java-version: '17'
32+
distribution: 'temurin'
33+
- name: Setup Android SDK
34+
uses: android-actions/setup-android@v3
35+
- name: Install workloads
36+
run: |
37+
dotnet workload install android
38+
39+
- name: Check format
40+
run: |
41+
dotnet tool restore
42+
dotnet csharpier check .
43+
- name: Restore dependencies
44+
run: dotnet restore /p:EnableWindowsTargeting=true
45+
- name: Build
46+
run: dotnet build --no-restore --configuration Release /p:EnableWindowsTargeting=true
47+
- name: Test
48+
run: dotnet test --no-build --configuration Release

.release-please-manifest.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
".": "1.10.0"
3+
}

release-please-config.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
3+
"changelog-path": "CHANGELOG.md",
4+
"packages": {
5+
".": {
6+
"include-v-in-tag": true,
7+
"include-component-in-tag": false,
8+
"package-name": "Darp.Ble",
9+
"release-type": "simple",
10+
"extra-files": [
11+
{
12+
"type": "xml",
13+
"path": "/src/Directory.Build.props",
14+
"xpath": "/Project/PropertyGroup/Version"
15+
}
16+
]
17+
}
18+
}
19+
}

src/Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<RepositoryType>git</RepositoryType>
1111
<PackageReadmeFile>README.md</PackageReadmeFile>
1212
<PackageTags>BLE,communication,near-field,nordic,nrf52840,hci,windows,android</PackageTags>
13+
<!-- Version applied to all the packages. Automatically updated by release-please -->
14+
<Version>1.10.0</Version>
1315
</PropertyGroup>
1416
<ItemGroup>
1517
<None Include="../../README.md" Pack="true" PackagePath="/" />

0 commit comments

Comments
 (0)