Added github token required secret #3
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 | ||
on: | ||
workflow_call: | ||
secrets: | ||
GITHUB_TOKEN: | ||
required: true | ||
permissions: | ||
packages: write | ||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
env: | ||
DOTNET_NOLOGO: true | ||
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true # Avoid pre-populating the NuGet package cache | ||
ASSENTNONINTERACTIVE: true | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 # all | ||
- name: Setup .NET 8.0 | ||
uses: actions/setup-dotnet@v1 | ||
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: $GitVersion_SemVer" | ||
- name: Add DbUp NuGet Source | ||
run: dotnet nuget add source --name DbUp --username DbUp --password ${{ secrets.GITHUB_TOKEN }} --store-password-in-clear-text https://nuget.pkg.github.com/DbUp/index.json | ||
- name: Restore | ||
run: dotnet restore | ||
working-directory: src | ||
- name: Build | ||
run: dotnet build -c Release --no-restore /p:Version=$GitVersion_SemVer | ||
working-directory: src | ||
- name: Test | ||
run: dotnet test --no-build -c Release --logger trx --logger "console;verbosity=detailed" --results-directory ../artifacts | ||
working-directory: src | ||
- name: Pack | ||
run: dotnet pack --no-build -c Release -o ../artifacts /p:Version=$GitVersion_SemVer | ||
working-directory: src | ||
- name: Push NuGet packages to GitHub Packages ⬆️ | ||
#if: ${{ format('{0}', secrets.GITHUB_TOKEN) != '' && startsWith(github.repository, 'DbUp/') }} | ||
working-directory: artifacts | ||
run: dotnet nuget push *.nupkg --api-key ${{ secrets.GITHUB_TOKEN }} --source "https://nuget.pkg.github.com/DbUp/index.json" | ||
# 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/*.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 $GitVersion_SemVer $GitVersion_SemVer (Get-Item dbup-core.*.nupkg) | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |