Skip to content

Commit 19bb086

Browse files
Cihan CakirCihan Cakir
Cihan Cakir
authored and
Cihan Cakir
committed
initial create
0 parents  commit 19bb086

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2011
-0
lines changed

.github/workflows/publish.yml

+110
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: publish
4+
on:
5+
workflow_dispatch: # Allow running the workflow manually from the GitHub UI
6+
push:
7+
branches:
8+
- 'main' # Run the workflow when pushing to the main branch
9+
pull_request:
10+
branches:
11+
- '*' # Run the workflow for all pull requests
12+
release:
13+
types:
14+
- published # Run the workflow when a new GitHub release is published
15+
16+
env:
17+
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: 1
18+
DOTNET_NOLOGO: true
19+
NuGetDirectory: ${{ github.workspace}}/nuget
20+
21+
defaults:
22+
run:
23+
shell: pwsh
24+
25+
jobs:
26+
create_nuget:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
with:
31+
fetch-depth: 0 # Get all history to allow automatic versioning using MinVer
32+
33+
# Install the .NET SDK indicated in the global.json file
34+
- name: Setup .NET
35+
uses: actions/setup-dotnet@v3
36+
37+
- name: 'Get Version'
38+
id: version
39+
uses: battila7/get-version-action@v2
40+
41+
# Create the NuGet package in the folder from the environment variable NuGetDirectory
42+
- run: dotnet pack --configuration Release --include-symbols -p:PackageVersion=${{ steps.version.outputs.version-without-v }} --output ${{ env.NuGetDirectory }}
43+
44+
# Publish the NuGet package as an artifact, so they can be used in the following jobs
45+
- uses: actions/upload-artifact@v3
46+
with:
47+
name: nuget
48+
if-no-files-found: error
49+
retention-days: 7
50+
path: ${{ env.NuGetDirectory }}/*.nupkg
51+
52+
validate_nuget:
53+
runs-on: ubuntu-latest
54+
needs: [ create_nuget ]
55+
steps:
56+
# Install the .NET SDK indicated in the global.json file
57+
- name: Setup .NET
58+
uses: actions/setup-dotnet@v3
59+
60+
# Download the NuGet package created in the previous job
61+
- uses: actions/download-artifact@v3
62+
with:
63+
name: nuget
64+
path: ${{ env.NuGetDirectory }}
65+
66+
- name: Install nuget validator
67+
run: dotnet tool update Meziantou.Framework.NuGetPackageValidation.Tool --global
68+
69+
# Validate metadata and content of the NuGet package
70+
# https://www.nuget.org/packages/Meziantou.Framework.NuGetPackageValidation.Tool#readme-body-tab
71+
# If some rules are not applicable, you can disable them
72+
# using the --excluded-rules or --excluded-rule-ids option
73+
- name: Validate package
74+
run: meziantou.validate-nuget-package (Get-ChildItem "${{ env.NuGetDirectory }}/*.nupkg")
75+
76+
run_test:
77+
runs-on: ubuntu-latest
78+
steps:
79+
- uses: actions/checkout@v3
80+
- name: Setup .NET
81+
uses: actions/setup-dotnet@v3
82+
- name: Run tests
83+
run: dotnet test --configuration Release
84+
85+
deploy:
86+
# Publish only when creating a GitHub Release
87+
# https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository
88+
# You can update this logic if you want to manage releases differently
89+
if: github.event_name == 'release'
90+
runs-on: ubuntu-latest
91+
needs: [ validate_nuget, run_test ]
92+
steps:
93+
# Download the NuGet package created in the previous job
94+
- uses: actions/download-artifact@v3
95+
with:
96+
name: nuget
97+
path: ${{ env.NuGetDirectory }}
98+
99+
# Install the .NET SDK indicated in the global.json file
100+
- name: Setup .NET Core
101+
uses: actions/setup-dotnet@v3
102+
103+
# Publish all NuGet packages to NuGet.org
104+
# Use --skip-duplicate to prevent errors if a package with the same version already exists.
105+
# If you retry a failed workflow, already published packages will be skipped without error.
106+
- name: Publish NuGet package
107+
run: |
108+
foreach($file in (Get-ChildItem "${{ env.NuGetDirectory }}" -Recurse -Include *.nupkg)) {
109+
dotnet nuget push $file --api-key "${{ secrets.NUGET_APIKEY }}" --source https://api.nuget.org/v3/index.json --skip-duplicate
110+
}

0 commit comments

Comments
 (0)