-
Notifications
You must be signed in to change notification settings - Fork 15
78 lines (66 loc) · 3.7 KB
/
ci-build.yml
File metadata and controls
78 lines (66 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Builds and tests the code.
# Additionally, for pushes to main and GitHub releases the NuGet packages are published.
# The version number is always read from version-number.txt and the suffix from version-suffix.txt.
# If the workflow has not been triggered by a GitHub release, then a suffix is applied to the version number indicating it's a pre-release.
name: CI Build
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
release:
types: [published]
env:
DOTNET_VERSION: '5.0.x'
OUTPUT_DIR: 'dist'
BUILD_TYPE: 'Release'
NUGET_SOURCE_NAME: 'AzureIntegrationMigration'
CODE_COVERAGE_THRESHOLD: 90
VERSION_NUMBER : 'NOT SET'
VERSION_NUMBER_SUFFIX : ''
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
jobs:
build-and-test:
runs-on: windows-latest
steps:
- name: Checkout repo into workspace
uses: actions/checkout@v2
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# The version number suffix is set to indicate its a pre-release for all builds unless the build is run as result of a github release being created.
- name: Set the version number suffix if the workflow trigger is not a release
if: github.event_name != 'release'
shell: bash
run: |
seconds_at_midnight=$(date --utc -d 'today 00:00:00' +"%s")
seconds_now=$(date --utc +"%s")
seconds_since_midnight=$((seconds_now - seconds_at_midnight))
seconds_since_midnight_padded=`printf %05d $seconds_since_midnight`
echo ::set-env name=VERSION_NUMBER_SUFFIX::-$(cat ./version-suffix.txt).$(date --utc +%Y%m%d$seconds_since_midnight_padded)
# Set the version number.
- name: Set the version number
shell: bash
run: echo ::set-env name=VERSION_NUMBER::$(cat ./version-number.txt)${{ env.VERSION_NUMBER_SUFFIX }}
- name: Restore project dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration ${{ env.BUILD_TYPE }} -p:Version=${{ env.VERSION_NUMBER }}
- name: Run unit tests with coverage
run: dotnet test --filter Category=Unit -p:CollectCoverage=true -p:CoverletOutput=../../${{ env.OUTPUT_DIR }}/tests/coverage/ -p:CoverletOutputFormat=cobertura -p:Threshold=${{ env.CODE_COVERAGE_THRESHOLD }} -p:ExcludeByAttribute=CompilerGeneratedAttribute -p:ExcludeByAttribute=GeneratedCodeAttribute
- name: Pack the code into a NuGet package
run: dotnet pack --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER }} --no-build
# The command line for the NuGet push does not use the api-key. This can only be read from a NuGet config.
# This task creates a NuGet package with the source details and the api-key.
- name: Create NuGet config
if: github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
run: dotnet nuget add source ${{ secrets.NUGET_PACKAGE_REPO_API_SOURCE }} --name ${{ env.NUGET_SOURCE_NAME }} --username ${{ secrets.NUGET_PACKAGE_REPO_API_USER }} --password ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }}
# Publish the packge to GitHub using the source stored in the NuGet config (created in the previous step). The GPR tool is used as its more stable than dotnet nuget push
- name: Publish the package to GitHub package repository
if: github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
run: |
dotnet tool update gpr -g
gpr push .\${{ env.OUTPUT_DIR }}\*.nupkg --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }}