Skip to content

Commit

Permalink
build(github): add publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
seangwright committed Jul 8, 2023
1 parent 8b3c1f5 commit 795ba51
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 1 deletion.
34 changes: 34 additions & 0 deletions .github/actions/pack-and-publish/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: 'Pack and Publish'

description: 'Packs and publishes a .NET Library as a build artifact'

inputs:
projectPath:
description: 'Path to the project file'
required: true
preReleaseVersion:
description: 'The pre-release version to use for the NuGet package'
required: true

runs:
using: composite
steps:
- name: Create PreRelease Artifact
run: dotnet pack ${{ inputs.projectPath }} -c Release --no-build --include-symbols -o ./artifacts/prerelease --version-suffix prerelease-${{ inputs.preReleaseVersion }}
shell: pwsh

- name: 'Save prerelease artifact'
uses: actions/upload-artifact@v3
with:
name: prerelease
path: ./artifacts/prerelease/*

- name: Create Release Artifact
run: dotnet pack ${{ inputs.projectPath }} -c Release --no-build --include-symbols -o ./artifacts/release
shell: pwsh

- name: 'Save release artifact'
uses: actions/upload-artifact@v3
with:
name: release
path: ./artifacts/release/*
65 changes: 65 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: "Release: Publish to NuGet"

on:
workflow_dispatch:
inputs:
reason:
description: "The reason for running the workflow"
required: true
default: "Manual run"

jobs:
createArtifacts:
name: Generate NuGet Packages
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
global-json-file: global.json

- name: Install dependencies
run: dotnet restore --locked-mode

- name: Build Solution
run: dotnet build -c Release --no-restore

- name: Test Solution
run: dotnet test --configuration Release --no-build --no-restore

- name: "Pack and Publish"
uses: ./.github/actions/pack-and-publish
with:
projectPath: "./src/templatepack.csproj"
preReleaseVersion: ${{ github.run_number }}-${{ github.run_attempt }}

publishPreRelease:
name: Publish PreRelease NuGet Package
environment: prerelease
needs: createArtifacts
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: prerelease

- name: Publish NuGet Package
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}

publishRelease:
name: Publish Release NuGet Package
environment: release
needs: [createArtifacts, publishPreRelease]
runs-on: ubuntu-latest
steps:
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: release

- name: Publish NuGet Package
run: dotnet nuget push *.nupkg -s https://api.nuget.org/v3/index.json -k ${{ secrets.NUGET_API_KEY }}
2 changes: 1 addition & 1 deletion src/templatepack.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<PackageVersion>1.0</PackageVersion>
<PackageVersion>1.0.0</PackageVersion>
<PackageId>XperienceCommunity.DotnetItemTemplates</PackageId>
<Title>Xperience Community - .NET Item Templates</Title>
<Authors>Sean G. Wright</Authors>
Expand Down

0 comments on commit 795ba51

Please sign in to comment.