-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 9cfe4b4
Showing
9 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
name: 'build-test' | ||
|
||
on: | ||
pull_request: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Deploy to NuGet | ||
uses: ./ | ||
with: | ||
deploy-nuget-project: 'test' | ||
version: '1.0.0' | ||
nuget-api-key: 'GARBAGE' | ||
image-version: '8.0' | ||
build-only: true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
**/bin/** | ||
**/obj/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2024 GitHub, Inc. and contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Deploy to NuGet | ||
|
||
This reusable action builds a .NET project and deploys the resulting package to NuGet. It supports configuration for custom project paths and versioning, and securely handles the NuGet API key as a secret. | ||
|
||
## Usage | ||
|
||
Simply use this action in your workflow by specifying the project file path, version, and your NuGet API key. | ||
|
||
### Inputs | ||
|
||
- `deploy-nuget-project`: **Required**. The path to the `.csproj` file of the .NET project that you want to build and deploy. | ||
- `version`: **Required**. The version to assign to the NuGet package. Typically, this is dynamically generated from tags or other versioning strategies. | ||
- `nuget-api-key`: **Required**. The NuGet API key used to push the package to NuGet.org. This should be stored securely as a GitHub Secret. | ||
- `dotnet-version`: **Optional**. The .NET SDK version to use. Defaults to `8.0`. | ||
|
||
### Example | ||
|
||
```yaml | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Deploy to NuGet | ||
uses: alsi-lawr/deploy-nuget@v1 | ||
with: | ||
deploy-nuget-project: 'src/MyProject' # Specify the correct path to your project file directory | ||
version: 1.0.${{ github.run_number }} # Example using the run number | ||
nuget-api-key: ${{ secrets.NUGET_API_KEY }} # NuGet API key stored as a secret | ||
dotnet-version: '8.0' | ||
``` | ||
### Security | ||
- **NuGet API Key:** The `nuget-api-key` input should always be stored as a secret to avoid exposing sensitive information. You can add this secret in your GitHub repository settings under `Settings` > `Secrets and variables` > `Actions`. | ||
|
||
### Additional Notes | ||
|
||
- This action leverages Docker to run inside a .NET SDK container, ensuring a consistent build environment. | ||
- The action automatically restores NuGet packages, adds `Microsoft.SourceLink.GitHub`, and builds the project with various settings optimized for CI/CD environments. | ||
|
||
## Contributing | ||
|
||
Contributions are welcome! Please refer to the [contributing guidelines](./docs/CONTRIBUTING.md) for more information. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
name: 'Deploy to NuGet' | ||
|
||
description: 'Reusable action to build and deploy a .NET project to NuGet the @v tag of the action is the dotnet sdk version.' | ||
|
||
inputs: | ||
deploy-nuget-project: | ||
description: 'The path to the .NET project to deploy' | ||
required: true | ||
version: | ||
description: 'The version to assign to the NuGet package' | ||
required: true | ||
nuget-api-key: | ||
description: 'Your NuGet API key' | ||
required: true | ||
secret: true | ||
dotnet-version: | ||
description: 'The .NET SDK version to use' | ||
default: '8.0' | ||
options: | ||
- '8.0' | ||
- '7.0' | ||
- '6.0' | ||
build-only: | ||
description: 'Only build the project, do not deploy' | ||
default: false | ||
options: | ||
- true | ||
- false | ||
|
||
runs: | ||
using: 'composite' | ||
steps: | ||
- name: Deploy to NuGet in Docker | ||
run: | | ||
docker run --rm \ | ||
-v ${{ github.workspace }}:/workspace \ | ||
-e NUGET_API_KEY=${{ inputs.nuget-api-key }} \ | ||
-e GITHUB_REF_NAME=${{ github.ref_name }} \ | ||
-e GITHUB_SHA=${{ github.sha }} \ | ||
-w /workspace \ | ||
mcr.microsoft.com/dotnet/sdk:${{ inputs.dotnet-version }} \ | ||
bash -c "./src/deploy.sh ${{ inputs.deploy-nuget-project }} ${{ inputs.version }} ${{ inputs.build-only }}" | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# How to Contribute | ||
|
||
1. **Modify the Action**: Make changes to the `action.yml` or related scripts (if any exist). | ||
|
||
2. **Test Your Changes**: Ensure your changes work by testing in a separate repository or locally using `act`. | ||
|
||
3. **Submit Your Changes**: Once you're confident your changes work as expected, submit a pull request with a brief description of the improvements or fixes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/bin/bash | ||
|
||
PROJECT_PATH=$1 | ||
PACKAGE_VERSION=$2 | ||
BUILD_ONLY=$3 | ||
echo "Deploying package in $PROJECT_PATH with version $PACKAGE_VERSION" | ||
echo "Dotnet version used: " | ||
dotnet --version | ||
|
||
dotnet restore -s "https://api.nuget.org/v3/index.json" $PROJECT_PATH | ||
dotnet add $PROJECT_PATH package Microsoft.SourceLink.GitHub | ||
dotnet build $PROJECT_PATH -c Release \ | ||
/p:ContinuousIntegrationBuild=true \ | ||
/p:EmbedUntrackedSources=true \ | ||
/p:PublishRepositoryUrl=true \ | ||
/p:GenerateDocumentationFile=true \ | ||
/p:IncludeSymbols=true \ | ||
/p:SymbolPackageFormat=snupkg \ | ||
/p:NoWarn=CS1591 \ | ||
/p:RepositoryBranch=$GITHUB_REF_NAME \ | ||
/p:RepositoryCommit=$GITHUB_SHA \ | ||
/p:GeneratePackageOnBuild=true \ | ||
/p:Version=$PACKAGE_VERSION \ | ||
/p:BaseOutputPath=bin/ \ | ||
--no-incremental | ||
|
||
if [ "$BUILD_ONLY" = "true" ]; then | ||
exit 0 | ||
fi | ||
|
||
dotnet nuget push "$PROJECT_PATH/bin/Release/*.nupkg"\ | ||
--source https://api.nuget.org/v3/index.json\ | ||
--api-key $NUGET_API_KEY | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Test.Package; | ||
|
||
public class Class1 | ||
{ | ||
public Class1() | ||
{ | ||
Console.WriteLine("Hello World!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |