diff --git a/.github/actions/pack-and-publish/action.yml b/.github/actions/pack-and-publish/action.yml new file mode 100644 index 0000000..49fab20 --- /dev/null +++ b/.github/actions/pack-and-publish/action.yml @@ -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/* \ No newline at end of file diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..7bf1e50 --- /dev/null +++ b/.github/workflows/publish.yml @@ -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 }} diff --git a/src/templatepack.csproj b/src/templatepack.csproj index 08ecf1a..b30f3e6 100644 --- a/src/templatepack.csproj +++ b/src/templatepack.csproj @@ -2,7 +2,7 @@ Template - 1.0 + 1.0.0 XperienceCommunity.DotnetItemTemplates Xperience Community - .NET Item Templates Sean G. Wright