Make the project multitargeted #13
Workflow file for this run
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
name: .NET CI/CD Workflow | |
on: | |
pull_request: | |
branches: [main] | |
push: | |
branches: [main] | |
release: | |
types: [published] | |
jobs: | |
prepare_versions: | |
runs-on: ubuntu-latest | |
outputs: | |
ReleaseVersion: ${{ steps.find.outputs.tag }} | |
PreviewAssemblyVersion: ${{ steps.set_version.outputs.preview_assembly_version }} | |
PreviewPackageVersion: ${{ steps.set_version.outputs.preview_package_version }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Find Latest Tag | |
id: find | |
uses: oprypin/[email protected] | |
with: | |
repository: ${{ github.repository }} | |
releases-only: true | |
- name: Set version output | |
id: set_version | |
run: | | |
echo "::set-output name=preview_assembly_version::${{ steps.find.outputs.tag }}.${{ github.run_number }}" | |
echo "::set-output name=preview_package_version::${{ steps.find.outputs.tag }}.${{ github.run_number }}-preview" | |
build_and_test: | |
needs: prepare_versions | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: ['7.0.x', '8.0.x'] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Restore dependencies | |
run: dotnet restore | |
- name: Build (Conditional Versioning) | |
run: | | |
if [ "${{ github.event_name }}" = "pull_request" ] || [ "${{ github.event_name }}" = "push" ]; then | |
VERSION=${{ needs.prepare_versions.outputs.PreviewAssemblyVersion }} | |
elif [ "${{ github.event_name }}" = "release" ]; then | |
VERSION=${{ needs.prepare_versions.outputs.ReleaseVersion }} | |
fi | |
dotnet build --configuration Release --no-restore /p:Version=$VERSION | |
- name: Test | |
run: dotnet test --configuration Release --no-build | |
- name: Upload Artifacts | |
uses: actions/upload-artifact@v2 | |
with: | |
name: built-artifacts | |
path: | | |
**/bin/ | |
**/obj/ | |
build_pack_publish_preview: | |
needs: [prepare_versions, build_and_test] | |
if: github.event_name == 'push' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: ['7.0.x', '8.0.x'] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Download Artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: built-artifacts | |
- name: Pack | |
run: dotnet pack --configuration Release --no-build --output nupkgs /p:Version=${{ needs.prepare_versions.outputs.PreviewPackageVersion }} | |
- name: Publish NuGet | |
run: dotnet nuget push "nupkgs/*.nupkg" -k ${{ secrets.NugetKey }} -s https://api.nuget.org/v3/index.json --skip-duplicate | |
build_pack_publish_release: | |
needs: [prepare_versions, build_and_test] | |
if: github.event_name == 'release' | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
dotnet-version: ['7.0.x', '8.0.x'] | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v1 | |
with: | |
dotnet-version: ${{ matrix.dotnet-version }} | |
- name: Download Artifacts | |
uses: actions/download-artifact@v2 | |
with: | |
name: built-artifacts | |
- name: Pack | |
run: dotnet pack --configuration Release --no-build --output nupkgs /p:Version=${{ needs.prepare_versions.outputs.ReleaseVersion }} | |
- name: Publish NuGet | |
run: dotnet nuget push "nupkgs/*.nupkg" -k ${{ secrets.NugetKey }} -s https://api.nuget.org/v3/index.json --skip-duplicate | |
- name: Upload Release Assets | |
uses: dwenegar/upload-release-assets@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
release_id: ${{ needs.prepare_versions.outputs.ReleaseVersion }} | |
path: nupkgs |