Update cd.yml #53
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: cd | |
on: | |
workflow_dispatch: | |
inputs: | |
Publish: | |
description: 'Publish option' | |
required: true | |
default: 'None' | |
type: choice | |
options: | |
- None | |
- NuGet | |
- NuGetTest | |
push: | |
branches: | |
- "**" | |
paths: | |
- ".github/workflows/cd.yml" | |
tags: | |
- "v*" | |
jobs: | |
release: | |
runs-on: windows-latest | |
env: | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages # NuGet CLI environment variables | |
NUGET_PACKAGE_SOURCE: https://api.nuget.org/v3/index.json # need ${{ secrets.NUGET_TOKEN }} or ${{ secrets.NUGETALL_TOKEN }} (Expires in a day) | |
NUGETTEST_PACKAGE_SOURCE: https://apiint.nugettest.org/v3/index.json # need ${{ secrets.NUGETTEST_TOKEN }} (Expires in a day) | |
steps: | |
- uses: actions/checkout@v3 | |
with: | |
submodules: true | |
fetch-depth: 0 | |
- uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: | | |
7.0.x | |
8.0.x | |
cache: true | |
cache-dependency-path: '**/packages.lock.json' | |
- run: dotnet restore --locked-mode | |
- id: meta | |
shell: bash | |
run: | | |
is_release=${{ startsWith(github.ref, 'refs/tags/v') }} | |
is_cd_modified=${{ contains(github.event.head_commit.modified, '.github/workflows/cd.yml') }} | |
tag=$(git describe --tags --match "v*" ${{ github.ref }} || true) | |
if ! $($is_release) ; then | |
prefix=${tag%-*-*} | |
suffix=${tag#$prefix-} | |
tag="$prefix-ci.$suffix" | |
fi | |
echo tag=$tag | tee -a $GITHUB_OUTPUT | |
echo version=${tag#v} | tee -a $GITHUB_OUTPUT | |
echo is_release=$is_release | tee -a $GITHUB_OUTPUT | |
echo is_cd_modified=$is_cd_modified | tee -a $GITHUB_OUTPUT | |
- name: Build | |
run: | | |
dotnet build --configuration Release --no-restore -p:Version=${{ steps.meta.outputs.version }} -p:RepositoryBranch=$(git rev-parse --abbrev-ref HEAD) -p:RepositoryCommit=$(git rev-parse HEAD) | |
mv ./src/**/bin/Release/*nupkg ./ | |
- name: Publish the package to nugettest.org | |
if: ${{ steps.meta.outputs.is_cd_modified == 'true' || github.event.inputs.Publish == 'NuGetTest' }} | |
run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGETTEST_PACKAGE_SOURCE }} --source ${{ env.NUGET_PACKAGE_SOURCE }} | |
- name: Publish the package to nuget.org | |
if: ${{ steps.meta.outputs.is_release == 'true' || github.event.inputs.Publish == 'NuGet' }} | |
run: dotnet nuget push *.nupkg --api-key ${{ secrets.NUGETALL_TOKEN }} --source ${{ env.NUGET_PACKAGE_SOURCE }} | |
- uses: softprops/action-gh-release@v1 | |
if: ${{ steps.meta.outputs.is_release == 'true' }} | |
with: | |
tag_name: ${{ steps.meta.outputs.tag }} |