build-and-release #32
This file contains hidden or 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
# This workflow tests, builds and releases the project on github and nuget.org | |
name: build-and-release | |
on: [workflow_dispatch] | |
env: | |
# Specifies dotnet SDK Version | |
DOTNET_VERSION: '8.0.x' | |
jobs: | |
ci: | |
name: build-and-release-job | |
runs-on: ubuntu-latest | |
# Need write permission for creating release-notes file | |
permissions: | |
contents: write | |
steps: | |
# Checks out the source code at the latest commit | |
- uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
# Create new version from commits and write to enviornment variables (env.Tag_Name + env.Release_Name + env.Nuget_Version) | |
- name: Create Version | |
run: bash ".github/workflows/create-next-version.sh" | |
# Installs the .NET SDK on the build machine | |
- name: Setup .NET | |
uses: actions/setup-dotnet@v3 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
# Installs any NuGet packages required. | |
- name: Install dependencies | |
run: dotnet restore | |
# Builds the project | |
- name: Build | |
run: dotnet build --configuration Release --no-restore | |
# Create Release Log | |
# Need to fetch, otherwise doesn't know last commits | |
- name: Git Fetch | |
shell: bash | |
run: git fetch --depth=500 | |
- name: Create release-notes | |
run: bash ".github/workflows/create-release-notes.sh" "${{ github.repository }}" ${{ env.Tag_Name }} "${{ github.workspace }}\release-notes.md" | |
- name: Show release-notes | |
run: cat "${{ github.workspace }}\release-notes.md" | |
# Create Release | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
tag_name: "${{ env.Tag_Name }}" | |
name: "${{ env.Release_Name }}" | |
body_path: "${{ github.workspace }}\\release-notes.md" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
# Create nuget-package | |
- name: Pack | |
run: dotnet pack --configuration Release --no-restore /p:Version=${{ env.Nuget_Version }} | |
# Push nuget-package to nuget.org | |
- name: Push | |
run: dotnet nuget push Markdown2Pdf/bin/Release/Markdown2Pdf.${{ env.Nuget_Version }}.nupkg -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate |