Skip to content

Commit f62446f

Browse files
authored
Create dedicated package to reference in ASP.NET Core projects (#21)
1 parent 696a4d3 commit f62446f

12 files changed

Lines changed: 170 additions & 63 deletions

.github/workflows/cd-production.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ jobs:
2525
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY_NEOLUTION }}
2626

2727
- name: Determine version for NuGet package
28-
run: echo NUGET_VERSION=${GITHUB_REF#refs/tags/v} >> $GITHUB_ENV
28+
run: echo NUGET_VERSION=${GITHUB_REF#refs/tags/} >> $GITHUB_ENV
2929

3030
- name: Build and pack
3131
run: |
3232
dotnet restore
33-
dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} -p:Version=$NUGET_VERSION
34-
dotnet pack --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore --no-build -p:PackageVersion=$NUGET_VERSION
33+
dotnet build --configuration ${{ env.BUILD_CONFIGURATION }} --no-restore -p:Version=$NUGET_VERSION
34+
dotnet pack --configuration ${{ env.BUILD_CONFIGURATION }} --no-build --no-restore -p:PackageVersion=$NUGET_VERSION
3535
3636
- name: Push NuGet package
37-
run: echo "dotnet nuget push -k $NUGET_AUTH_TOKEN **/bin/Release/*.nupkg"
37+
run: dotnet nuget push -k $NUGET_AUTH_TOKEN **/bin/Release/*.nupkg
3838
env:
3939
NUGET_AUTH_TOKEN: ${{ secrets.NUGET_API_KEY_NEOLUTION }}

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,11 @@ jobs:
4242

4343
- uses: actions/setup-dotnet@v4
4444
with:
45-
dotnet-version: 6.x
45+
dotnet-version: 8.x
4646

4747
- run: dotnet build -c Release
4848

49-
- run: dotnet pack -c Release --no-build --no-restore -o ./artifacts
50-
51-
- run: mv ./artifacts/*.nupkg ./artifacts/Neolution.Extensions.Configuration.GoogleSecrets.${{ github.run_id }}-${{ github.run_attempt }}.nupkg
49+
- run: dotnet pack -c Release --no-build --no-restore -o ./artifacts -p:PackageVersion=$(date -d "${GITHUB_RUN_TIMESTAMP}" "+%Y.%-m.%-d")-ci.${{ github.run_attempt }}${{ github.run_id }}
5250

5351
- name: Upload artifact
5452
uses: actions/upload-artifact@v4

.github/workflows/create-release.yml

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,29 @@ name: Create Release
33
on:
44
workflow_dispatch:
55
inputs:
6-
version_type:
6+
versioning_phase:
77
type: choice
8-
description: Semantic Version Type
8+
description: Versioning Phase
9+
default: stable
910
options:
10-
- automatic
11+
- alpha
12+
- beta
13+
- rc
14+
- stable
15+
16+
bump_version_number:
17+
type: choice
18+
description: Bump Version Number
19+
default: consecutive
20+
options:
21+
- consecutive
1122
- patch
1223
- minor
1324
- major
1425

15-
pre_release:
16-
type: choice
17-
description: Stage
18-
options:
19-
- stable
20-
- rc
21-
- beta
22-
- alpha
26+
is_dry_run:
27+
type: boolean
28+
description: Dry Run
2329

2430
jobs:
2531
release-it:
@@ -43,27 +49,30 @@ jobs:
4349
git config user.name "GitHub Release Bot"
4450
git config user.email release-bot@neolution.ch
4551
46-
- name: install @release-it/keep-a-changelog
47-
run: yarn add release-it @release-it/keep-a-changelog @neolution-ch/release-it-dotnet-plugin
52+
- name: install release-it with plugins
53+
run: npm install -g release-it @release-it/keep-a-changelog
4854

4955
- name: run release-it
5056
run: |
5157
params=()
5258
53-
if [[ ${{ github.event.inputs.version_type }} != "automatic" ]]; then
54-
params+=(${{ github.event.inputs.version_type }})
59+
if [[ ${{ github.event.inputs.bump_version_number }} != "consecutive" ]]; then
60+
params+=(${{ github.event.inputs.bump_version_number }})
5561
fi
5662
57-
if [[ ${{ github.event.inputs.pre_release }} != "stable" ]]; then
58-
params+=(--preRelease=${{ github.event.inputs.pre_release }})
63+
if [[ ${{ github.event.inputs.versioning_phase }} != "stable" ]]; then
64+
params+=(--preRelease=${{ github.event.inputs.versioning_phase }})
5965
params+=(--plugins.@release-it/keep-a-changelog.keepUnreleased)
6066
params+=(--no-plugins.@release-it/keep-a-changelog.strictLatest)
6167
fi
6268
69+
if [[ ${{ github.event.inputs.is_dry_run }} == "true" ]]; then
70+
params+=(--dry-run)
71+
fi
72+
6373
params+=(--ci)
64-
params+=(--plugins.@neolution-ch/release-it-dotnet-plugin.nugetApiKey=${{ secrets.NUGET_API_KEY_NEOLUTION }})
6574
6675
echo "command: release-it ${params[@]}"
67-
yarn release-it "${params[@]}"
76+
release-it "${params[@]}"
6877
env:
6978
GITHUB_TOKEN: ${{ steps.generate-token.outputs.token }}

.release-it.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
"addVersionUrl": true,
1616
"addUnreleased": true,
1717
"strictLatest": false
18-
},
19-
"@neolution-ch/release-it-dotnet-plugin": {
20-
"csprojFile": "./GoogleSecrets/GoogleSecrets.csproj",
21-
"buildConfiguration": "Release",
22-
"nugetApiKey": "overridden in GitHub workflow"
2318
}
2419
},
2520
"hooks": {

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ and adheres to a project-specific [Versioning](/README.md).
77

88
## [Unreleased]
99

10-
### Dependabot
10+
### Added
11+
12+
- Convention to load Google Secrets project name from environment variable `GOOGLE_SECRETS_PROJECT` if not specified in the options.
13+
- New package `Neolution.Extensions.Configuration.GoogleSecrets.AspNetCore` to reference in ASP.NET Core projects.
14+
15+
### Changed
1116

1217
- Update GitHub Actions to use the latest versions of the actions
1318

GoogleSecrets.sln

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

GoogleSecrets/GoogleSecretsExtensions.cs renamed to GoogleSecrets/ConfigurationBuilderExtensions.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,32 @@
66
/// <summary>
77
/// The Google Secrets Extensions
88
/// </summary>
9-
public static class GoogleSecretsExtensions
9+
public static class ConfigurationBuilderExtensions
1010
{
1111
/// <summary>
12-
/// Adds the google secrets.
12+
/// Adds the Google secrets to the <see cref="ConfigurationBuilder"/>.
13+
/// If the GOOGLE_SECRETS_PROJECT environment variable is set, it will be used as the project name.
14+
/// </summary>
15+
/// <param name="configuration">The configuration.</param>
16+
/// <returns>The IConfigurationBuilder</returns>
17+
/// <exception cref="System.ArgumentNullException">options</exception>
18+
public static IConfigurationBuilder AddGoogleSecrets(this IConfigurationBuilder configuration)
19+
{
20+
// Configure app configuration to add Google Secrets if environment variable is set
21+
var googleSecretProject = Environment.GetEnvironmentVariable(EnvironmentVariableNames.GoogleSecretsProject);
22+
if (!string.IsNullOrWhiteSpace(googleSecretProject))
23+
{
24+
return AddGoogleSecrets(configuration, options =>
25+
{
26+
options.ProjectName = googleSecretProject;
27+
});
28+
}
29+
30+
return AddGoogleSecrets(configuration, _ => { });
31+
}
32+
33+
/// <summary>
34+
/// Adds the Google secrets to the <see cref="ConfigurationBuilder"/>.
1335
/// </summary>
1436
/// <param name="configuration">The configuration.</param>
1537
/// <param name="options">The options.</param>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace Neolution.Extensions.Configuration.GoogleSecrets
2+
{
3+
/// <summary>
4+
/// Contains the names of environment variables used for Google Secrets configuration.
5+
/// </summary>
6+
public static class EnvironmentVariableNames
7+
{
8+
/// <summary>
9+
/// The name of the environment variable where the google secrets project id is stored.
10+
/// </summary>
11+
public const string GoogleSecretsProject = "GOOGLE_SECRETS_PROJECT";
12+
}
13+
}

GoogleSecrets/GoogleSecrets.csproj renamed to GoogleSecrets/Neolution.Extensions.Configuration.GoogleSecrets.csproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919

2020
<ItemGroup>
2121
<PackageReference Include="Google.Cloud.SecretManager.V1" Version="2.1.0" />
22-
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.0" />
23-
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.0" />
24-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="3.1.0" />
22+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
23+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
24+
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
25+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.1" />
2526
</ItemGroup>
2627

2728
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<ImplicitUsings>enable</ImplicitUsings>
6+
<Nullable>enable</Nullable>
7+
<IsPackable>true</IsPackable>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
12+
</ItemGroup>
13+
14+
<ItemGroup>
15+
<ProjectReference Include="..\GoogleSecrets\Neolution.Extensions.Configuration.GoogleSecrets.csproj" />
16+
</ItemGroup>
17+
18+
</Project>

0 commit comments

Comments
 (0)