-
-
Notifications
You must be signed in to change notification settings - Fork 13
88 lines (77 loc) · 2.92 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Slugify Actions
permissions:
packages: write
env:
PATH_TO_CSPROJ: 'src/Slugify.Core/Slugify.Core.csproj'
on:
push:
branches:
- main
pull_request:
workflow_dispatch:
inputs:
environment:
description: 'Environment'
type: environment
required: true
jobs:
build:
runs-on: ubuntu-latest
name: Build
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal --logger GitHubActions
- name: Pack #If we're not in production, add a version suffix to the package. This indicates pre-release
if: inputs.environment != 'Production'
run: dotnet pack --configuration release --output ${{ github.workspace}}/artifact/ /p:VersionSuffix=prerelease.${{ github.run_number}}
- name: Pack
if: inputs.environment == 'Production'
run: dotnet pack --configuration release --output ${{ github.workspace}}/artifact/
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: uploads
path: ${{ github.workspace}}/artifact/
if-no-files-found: error
- name: Push to GitHub Package Registry
if: ${{ github.ref == 'refs/heads/main' }}
run: dotnet nuget push ${{ github.workspace}}/artifact/*.nupkg --source https://nuget.pkg.github.com/ctolkien/index.json --api-key ${{secrets.GITHUB_TOKEN}} --skip-duplicate
deploy:
runs-on: ubuntu-latest
needs: build
name: Deploy
environment: ${{ inputs.environment }}
if: (inputs.environment == 'Production') || (inputs.environment == 'PreRelease')
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: uploads
path: ${{ github.workspace}}/artifact/
- name: Push to NuGet Package Registry
run: dotnet nuget push ${{ github.workspace}}/artifact/*.nupkg --api-key ${{ secrets.NUGETTOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Extract version
shell: pwsh
run: |
$version = ([xml](Get-Content ${{ env.PATH_TO_CSPROJ }})).Project.PropertyGroup.VersionPrefix[0].Trim()
Add-Content -Path $env:GITHUB_ENV -Value "VERSION=$version"
Add-Content -Path $env:GITHUB_ENV -Value "VERSIONWITHSUFFIX=$version-${{ github.run_number }}"
- name: Create GitHub Release
if: inputs.environment == 'PreRelease'
run: gh release create "${{ env.VERSIONWITHSUFFIX }}" --generate-notes --prerelease
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Create GitHub Release
if: inputs.environment == 'Production'
run: gh release create "${{ env.VERSION }}" --generate-notes
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}