-
Notifications
You must be signed in to change notification settings - Fork 20
191 lines (172 loc) · 12.1 KB
/
ci-build.yml
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Builds and tests the code.
# Additionally, for pushes to main and GitHub releases the NuGet packages and Chocolatey package 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.
# The build can also be triggered on schedule, this results in the chocolatey packages being published.
name: CI Build
on:
push:
branches:
- 'main'
pull_request:
branches:
- 'main'
release:
types: [published]
env:
BUILD_TYPE: 'Release'
DOTNET_VERSION: '5.0.x'
CHOCO_BIZTALK_MIGRATOR_PACKAGE: '..\..\build\chocolatey\biztalkmigrator\biztalkmigrator.nuspec'
CHOCO_CONFIG_DIR: 'build/chocolatey'
CHOCO_PACKAGE_OUTPUT_DIR: 'choco-package'
CHOCO_PACKAGE_REPO_PUBLIC: 'https://push.chocolatey.org/'
CHOCO_PACKAGE_REPO_FOLDER: 'chocolatey-packages'
CHOCO_SRC_DIR: 'choco-src'
# Code coverage is currently not enforced, this will be enabled once there is a sufficient amount of unit tests in the code base by setting the following variable.
CODE_COVERAGE_THRESHOLD: 0
NUGET_SOURCE_NAME: 'AzureIntegrationMigration'
OUTPUT_DIR: 'dist'
ANALYZE_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.Analyze/Microsoft.AzureIntegrationMigration.BizTalk.Analyze.csproj'
CONVERT_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.Convert/Microsoft.AzureIntegrationMigration.BizTalk.Convert.csproj'
DISCOVER_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.Discover/Microsoft.AzureIntegrationMigration.BizTalk.Discover.csproj'
PARSE_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.Parse/Microsoft.AzureIntegrationMigration.BizTalk.Parse.csproj'
REPORT_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.Report/Microsoft.AzureIntegrationMigration.BizTalk.Report.csproj'
PLUGIN_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.StageRunners/Microsoft.AzureIntegrationMigration.BizTalk.StageRunners.csproj'
TYPES_PROJECT_FILE: 'src/Microsoft.AzureIntegrationMigration.BizTalk.Types/Microsoft.AzureIntegrationMigration.BizTalk.Types.csproj'
ANALYZE_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.Analyze'
CONVERT_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.Convert'
DISCOVER_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.Discover'
PARSE_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.Parse'
REPORT_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.Report'
PLUGIN_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.StageRunners'
TYPES_PACKAGE_NAME: 'Microsoft.AzureIntegrationMigration.BizTalk.Types'
SCRIPT_MAX_RETRIES: 4
SCRIPT_RETRY_SLEEP_IN_SECONDS: 10
VERSION_NUMBER_SEM1: 'NOT SET'
VERSION_NUMBER_SEM2: 'NOT SET'
VERSION_NUMBER_SUFFIX_SEM1: ''
VERSION_NUMBER_SUFFIX_SEM2: ''
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
jobs:
build-and-test:
runs-on: windows-latest
steps:
- name: Checkout from default branch
if: github.event_name == 'push' || github.event_name == 'pull_request'
uses: actions/checkout@v2
- name: Checkout from main branch
if: github.event_name == 'release'
uses: actions/checkout@v2
with:
ref: main
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
# Note: 2 version numbers are created, semantic versioning 1 for Chocolatey and semantic versioning 2 for NuGet.
- name: Set the version number suffix
if: github.event_name == 'push' || github.event_name == 'pull_request'
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_SEM1::-$(cat ./version-suffix.txt)-$(date --utc +%Y%m%d$seconds_since_midnight_padded)
echo ::set-env name=VERSION_NUMBER_SUFFIX_SEM2::-$(cat ./version-suffix.txt).$(date --utc +%Y%m%d$seconds_since_midnight_padded)
- name: Set the version numbers
shell: bash
run: |
echo ::set-env name=VERSION_NUMBER_SEM1::$(cat ./version-number.txt)${{ env.VERSION_NUMBER_SUFFIX_SEM1 }}
echo ::set-env name=VERSION_NUMBER_SEM2::$(cat ./version-number.txt)${{ env.VERSION_NUMBER_SUFFIX_SEM2 }}
- name: Update the nuget config with the credentials for the GitHub Package Repository
run: dotnet nuget update source ${{ env.NUGET_SOURCE_NAME }} --username ${{ github.actor }} --password ${{ secrets.GITHUB_TOKEN }}
- name: Restore project dependencies
run: dotnet restore
- name: Build solution
run: dotnet build --configuration ${{ env.BUILD_TYPE }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }}
- name: Run unit tests
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 -p:ThresholdType=line
- name: Pack the plugin library and dependency files into a NuGet package
run: |
dotnet pack ${{ env.ANALYZE_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
dotnet pack ${{ env.CONVERT_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
dotnet pack ${{ env.DISCOVER_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
dotnet pack ${{ env.PARSE_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
dotnet pack ${{ env.REPORT_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
dotnet pack ${{ env.PLUGIN_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
dotnet pack ${{ env.TYPES_PROJECT_FILE }} --configuration ${{ env.BUILD_TYPE }} -o ${{ env.OUTPUT_DIR }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} --no-build
# Publish the package to GitHub package repository using the GPR tool (as this is currently 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 }}
- name: Get the nupkg URLs for each package
if: github.event_name == 'release' || (github.event_name == 'push' && github.ref == 'refs/heads/main')
shell: bash
run: |
packageUrl=$( gpr details "Azure" ${{ env.ANALYZE_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "ANALYZE_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
packageUrl=$( gpr details "Azure" ${{ env.CONVERT_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "CONVERT_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
packageUrl=$( gpr details "Azure" ${{ env.DISCOVER_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "DISCOVER_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
packageUrl=$( gpr details "Azure" ${{ env.PARSE_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "PARSE_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
packageUrl=$( gpr details "Azure" ${{ env.REPORT_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "REPORT_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
packageUrl=$( gpr details "Azure" ${{ env.PLUGIN_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "PLUGIN_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
packageUrl=$( gpr details "Azure" ${{ env.TYPES_PACKAGE_NAME }} ${{ env.VERSION_NUMBER_SEM2 }} --api-key ${{ secrets.NUGET_PACKAGE_REPO_API_SECRET }} | cat | jq '.packageContent' )
echo "TYPES_PACKAGE_URL=$packageUrl" >> "$GITHUB_ENV"
- name: Publish the plugin library and dependency files for Chocolatey
run: dotnet publish ${{ env.PLUGIN_PROJECT_FILE }} -r win-x64 -o ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }} --configuration ${{ env.BUILD_TYPE }} -p:Version=${{ env.VERSION_NUMBER_SEM2 }} -p:TargetFramework=net5.0 --self-contained true
- name: Create the Chocolatey verification file and copy the license file
shell: bash
run: |
cp ./LICENSE ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/LICENSE.txt
cp ./VERIFICATION ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.ANALYZE_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.CONVERT_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.DISCOVER_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.PARSE_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.REPORT_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.PLUGIN_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " - ${{ env.TYPES_PACKAGE_URL }}" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo " " >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
echo "Checksums for the files in the package are:" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
find ${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }} -type f |
while read f
do
filename="$(basename $f) [$f]"
filehash=$(sha256sum $f | awk '{print $1}')
echo "$filename -- $filehash" >> ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_SRC_DIR }}/VERIFICATION.txt
done
- name: Create the Chocolatey package output directory
shell: bash
run: |
mkdir ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_PACKAGE_OUTPUT_DIR }}
find ./${{ env.CHOCO_CONFIG_DIR }} -name "*.nuspec" |
while read f
do
choco pack $f --version=${{ env.VERSION_NUMBER_SEM1 }} --outputdirectory ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_PACKAGE_OUTPUT_DIR }}
done
- name: Push the Chocolatey package to the public repo
if: github.event_name == 'release'
shell: bash
run: |
find ./${{ env.OUTPUT_DIR }}/${{ env.CHOCO_PACKAGE_OUTPUT_DIR }}/ -name "*.nupkg" |
while read f; do
retryCount=0
while true; do
choco push $f -s ${{ env.CHOCO_PACKAGE_REPO_PUBLIC }} -k ${{ secrets.AIM_CHOCO_PUBLIC_REPO_TOKEN }} && break
retryCount=$((retryCount+1))
if (( "$retryCount" <= ${{ env.SCRIPT_MAX_RETRIES }} )); then
echo "Retrying the processing of $f"
sleep ${{ env.SCRIPT_RETRY_SLEEP_IN_SECONDS }}
else
break
fi
done
done