Merge pull request #807 from ibbyu/main #339
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: CI | |
# This workflow builds and tests the code | |
# Because of failed permissions all steps which are pushing code to github releases or nuget are removed. | |
# For creating draft release launch workflow -Create Draft Release- manually. | |
on: | |
pull_request: | |
branches: | |
- 'release/**' | |
- main | |
push: | |
workflow_dispatch: | |
jobs: | |
build: | |
runs-on: windows-latest | |
env: | |
DOTNET_NOLOGO: true | |
DOTNET_CLI_TELEMETRY_OPTOUT: true | |
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Avoid pre-populating the NuGet package cache | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # all | |
- name: Setup .NET 8.0 | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: 8.0.x | |
- name: Install GitVersion | |
uses: gittools/actions/gitversion/setup@v0 | |
with: | |
versionSpec: '5.x' | |
- name: Run GitVersion | |
id: gitversion | |
uses: gittools/actions/gitversion/execute@v0 | |
- name: Display SemVer | |
run: | | |
echo "SemVer: $env:GitVersion_SemVer" | |
- name: Restore | |
run: dotnet restore DbUp.sln | |
working-directory: src | |
- name: Build | |
run: dotnet build -c Release --no-restore /p:Version=$env:GitVersion_SemVer DbUp.sln | |
working-directory: src | |
- name: Test | |
run: dotnet test --no-build -c Release --logger trx --logger "console;verbosity=detailed" --results-directory ../artifacts/TestResults DbUp.sln | |
working-directory: src | |
- name: Pack | |
run: dotnet pack --no-build -c Release -o ../artifacts /p:Version=$env:GitVersion_SemVer DbUp.sln | |
working-directory: src | |
- name: Push NuGet packages to GitHub Packages ⬆️ | |
if: ${{ format('{0}', env.GITHUB_TOKEN) != '' && startsWith(github.repository, 'DbUp/') && github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]' }} | |
working-directory: artifacts | |
run: dotnet nuget push *.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/DbUp/index.json" | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
# https://github.com/dorny/test-reporter#recommended-setup-for-public-repositories | |
- name: Upload Test Results | |
uses: actions/upload-artifact@v3 # upload test results | |
if: success() || failure() # run this step even if previous step failed | |
with: | |
name: test-results | |
path: artifacts/TestResults/*.trx | |
- name: Create GitHub Release | |
if: ${{ (github.ref_name == 'main' || startsWith(github.ref_name, 'release/')) && format('{0}', env.GITHUB_TOKEN) != '' }} | |
shell: pwsh | |
working-directory: artifacts | |
# Can't just use wildcard in this command due to https://github.com/cli/cli/issues/5099 so use Get-Item | |
run: gh release create --draft ${{ github.ref_name == 'main' && '' || '--prerelease' }} --target ${{ github.ref_name }} --title $env:GitVersion_SemVer $env:GitVersion_SemVer (Get-Item dbup-core.*.nupkg) | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |