CIBuild_push_main_101.1 #101
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 Build | |
run-name: CIBuild_${{ github.event_name }}_${{ github.ref_name }}_${{ github.run_number }}.${{ github.run_attempt }} | |
env: | |
PKG_MAJOR_VERSION: '1.1' | |
PROJECT_NAME: 'DNX.Extensions' | |
DOTNET_VERSION: 8.0.x | |
NUGET_VERSION: 5.x | |
BUILD_CONFIG: Release | |
BUILD_PLATFORM: Any CPU | |
PACK_PARAMETERS: '' | |
NUGET_OUTPUT_FOLDER: nupkgs | |
BRANCH_RELEASE_CANDIDATE: rc/** | |
on: | |
push: | |
branches: | |
- main | |
- rc/** | |
- feature/** | |
- task/** | |
- spike/** | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
jobs: | |
########################################################## | |
## Pipeline Configuration and Setup | |
setup: | |
name: Setup Pipeline | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get Current Build Date | |
id: build_date | |
run: echo "build_date=$(date +'%y%j')" >> $GITHUB_ENV | |
- name: Set Package Suffix | |
id: package_suffix | |
run: | | |
branch="${{ github.ref }}" | |
package_suffix='' | |
if [ "$branch" != "refs/heads/main" ] | |
then | |
package_suffix='-beta' | |
fi | |
echo "package_suffix=${package_suffix}" >> $GITHUB_ENV | |
- name: Determine package publishing | |
id: should_publish | |
run: | | |
should_publish=false | |
if [ "${{ github.event_name }}" == "pull_request" ] | |
then | |
should_publish=true | |
elif [ "${{ github.ref }}" == "refs/heads/main" ] | |
then | |
should_publish=true | |
elif [[ "${{ github.ref }}" == ${{ env.BRANCH_RELEASE_CANDIDATE }}* ]] | |
then | |
should_publish=true | |
fi | |
echo "should_publish=${should_publish}" >> $GITHUB_ENV | |
- name: Set Product Version | |
id: product_version | |
run: echo "product_version=${{ env.PKG_MAJOR_VERSION }}" >> $GITHUB_ENV | |
- name: Set Assembly Version | |
id: assembly_version | |
run: echo "assembly_version=${{ env.PKG_MAJOR_VERSION }}.${{ env.build_date }}.${{ github.run_number }}${{ github.run_attempt }}" >> $GITHUB_ENV | |
- name: Set Package Version | |
id: package_version | |
run: echo "package_version=${{ env.assembly_version }}${{ env.package_suffix }}" >> $GITHUB_ENV | |
outputs: | |
assembly_version: ${{ env.assembly_version }} | |
product_version: ${{ env.product_version }} | |
package_version: ${{ env.package_version }} | |
should_publish: ${{ env.should_publish }} | |
########################################################## | |
## Build DotNet projects | |
build: | |
name: Build .NET | |
needs: setup | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install .NET SDK | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: ${{ env.DOTNET_VERSION }} | |
- name: Restore NuGet packages | |
run: dotnet restore | |
- name: Build | |
run: dotnet build --no-restore --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"Version=${{ needs.setup.outputs.product_version }}" /p:"AssemblyVersion=${{ needs.setup.outputs.assembly_version }}" | |
- name: Test | |
run: dotnet test --no-restore --no-build --configuration ${{ env.BUILD_CONFIG }} --verbosity normal --collect:"XPlat Code Coverage" | |
- name: Code Coverage Report | |
uses: irongut/[email protected] | |
with: | |
filename: "**/coverage.cobertura.xml" | |
badge: true | |
fail_below_min: true | |
format: markdown | |
hide_branch_rate: false | |
hide_complexity: false | |
indicators: true | |
output: both | |
thresholds: '60 80' | |
- name: Pull Request - Add Coverage Comment | |
uses: marocchino/sticky-pull-request-comment@v2 | |
if: github.event_name == 'pull_request' | |
with: | |
recreate: true | |
path: code-coverage-results.md | |
- name: Pack | |
run: dotnet pack --configuration ${{ env.BUILD_CONFIG }} /p:"Platform=${{ env.BUILD_PLATFORM }}" /p:"PackageVersion=${{ needs.setup.outputs.package_version }}" --no-restore --output "${{ env.NUGET_OUTPUT_FOLDER }}" | |
- name: Upload Build Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: build_output | |
path: "**/${{ env.PROJECT_NAME }}/bin/${{ env.BUILD_CONFIG }}/**" | |
if-no-files-found: error | |
- name: Upload NuGet Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: nuget_output | |
path: "${{ env.NUGET_OUTPUT_FOLDER }}/**" | |
if-no-files-found: error | |
########################################################## | |
## Generate a Release and Tag in git | |
release: | |
name: Create GitHub Release | |
if: github.ref == 'refs/heads/main' && success() | |
needs: | |
- setup | |
- build | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Build Changelog | |
id: build_changelog | |
uses: mikepenz/[email protected] | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Create Release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: v${{ needs.setup.outputs.assembly_version }} | |
name: Release ${{ needs.setup.outputs.assembly_version }} | |
body: ${{ steps.build_changelog.outputs.changelog }} | |
artifacts: '**/*.nupkg' | |
- name: Tag git | |
uses: pkgdeps/[email protected] | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
github_repo: ${{ github.repository }} | |
git_commit_sha: ${{ github.sha }} | |
git_tag_prefix: "v" | |
version: ${{ needs.setup.outputs.assembly_version }} | |
########################################################## | |
## Publish to NuGet | |
publish: | |
name: Publish to NuGet | |
if: needs.setup.outputs.should_publish == 'true' | |
needs: | |
- setup | |
- build | |
- release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Install NuGet | |
uses: NuGet/[email protected] | |
with: | |
nuget-api-key: ${{ secrets.NUGET_API_KEY }} | |
nuget-version: ${{ env.NUGET_VERSION }} | |
- name: Download NuGet Output | |
id: download_nuget | |
uses: actions/download-artifact@v4 | |
with: | |
name: nuget_output | |
path: ${{ env.NUGET_OUTPUT_FOLDER }} | |
- name: Publish | |
run: nuget push "**/*.nupkg" -Source 'https://api.nuget.org/v3/index.json' |