forked from pipeline-foundation/Notepads
-
Notifications
You must be signed in to change notification settings - Fork 0
266 lines (240 loc) · 10.2 KB
/
main.yml
File metadata and controls
266 lines (240 loc) · 10.2 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
name: Notepads CI/CD Pipeline
on: [push, pull_request, workflow_dispatch]
jobs:
ci:
runs-on: windows-latest
strategy:
matrix:
configuration: [ Debug, Release ]
outputs:
new_version: ${{ steps.get_assembly_version.outputs.version_num }}
new_version_tag: ${{ steps.get_assembly_version.outputs.version_tag }}
latest_tag: ${{ steps.get_latest_tag.outputs.tag }}
is_github_release: ${{ steps.step_conditionals_handler.outputs.is_github_release }}
env:
Solution_Name: src\Notepads.sln
steps:
- name: Steps' conditionals handler
id: step_conditionals_handler
shell: powershell
run: |
$IS_GITHUB_RELEASE = $false
$IS_NOT_PR = $true
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') -and ($env:BUILD_CONFIGURATION -ceq 'Release') ) {
$IS_GITHUB_RELEASE = $true
}
if ( $env:GITHUB_EVENT_NAME -ceq 'pull_request' ) {
$IS_NOT_PR = $false
}
echo "::set-output name=is_github_release::$(echo $IS_GITHUB_RELEASE)"
echo "::set-output name=is_not_PR::$(echo $IS_NOT_PR)"
env:
$GITHUB_EVENT_NAME: ${{ github.event_name }}
$GITHUB_REF: ${{ github.ref }}
$BUILD_CONFIGURATION: ${{ matrix.configuration }}
- name: Check step_conditionals_handler output
run: |
echo "${{ steps.step_conditionals_handler.outputs.is_github_release }}"
echo "${{ steps.step_conditionals_handler.outputs.is_not_PR }}"
- if: ( false )
name: Set up JDK 11
id: Setup_JDK
uses: actions/setup-java@v1
with:
java-version: 1.11
- name: Install .NET Core
id: install_dotnet_dependencies
uses: actions/setup-dotnet@v1
- name: Setup MSBuild
id: setup_msbuild
uses: microsoft/setup-msbuild@v1
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
with:
fetch-depth: 50
token: ${{ secrets.GITHUB_TOKEN }}
- if: ( steps.step_conditionals_handler.outputs.is_github_release )
name: Get assembly version from appxmanifest
id: get_assembly_version
shell: powershell
run: |
cd src/Notepads/
$xml = [xml](Get-Content Package.appxmanifest)
$ASSEMBLY_VERSION_NUMBER = $xml.Package.Identity | Select -ExpandProperty Version
echo "::set-output name=version_num::$(echo $ASSEMBLY_VERSION_NUMBER)"
echo "::set-output name=version_tag::$(echo v"$ASSEMBLY_VERSION_NUMBER")"
- if: ( steps.step_conditionals_handler.outputs.is_github_release )
name: Get latest tag
id: get_latest_tag
shell: powershell
run: |
$LATEST_TAG = git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags "https://github.com/$env:GIT_URL.git" '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3
echo "::set-output name=tag::$(echo $LATEST_TAG)"
env:
GIT_URL: ${{ github.repository }}
- if: ( steps.step_conditionals_handler.outputs.is_github_release ) && steps.get_assembly_version.outputs.version_tag != steps.get_latest_tag.outputs.tag
name: Add new tag to repo
id: add_new_tag_to_repo
shell: powershell
run: |
git config --global user.name $env:GIT_USER_NAME
git config --global user.email $env:GIT_USER_EMAIL
git tag -a -m "New version" $env:NEW_VERSION_TAG
git push --follow-tags
env:
GIT_USER_NAME: ${{ secrets.GIT_USER_NAME }}
GIT_USER_EMAIL: ${{ secrets.GIT_USER_EMAIL }}
NEW_VERSION_TAG: ${{ steps.get_assembly_version.outputs.version_tag }}
- if: ( steps.step_conditionals_handler.outputs.is_not_PR )
name: Cache SonarCloud packages
id: cache_sonar_packages
uses: actions/cache@v2
with:
path: ~\sonar\cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- if: ( steps.step_conditionals_handler.outputs.is_not_PR )
name: Cache SonarCloud scanner
id: cache_sonar_scanner
uses: actions/cache@v2
with:
path: .\.sonar\scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- if: ( steps.step_conditionals_handler.outputs.is_not_PR ) && steps.cache_sonar_scanner.outputs.cache-hit != 'true'
name: Install SonarCloud scanner
id: install_sonar_scanner
shell: powershell
run: |
New-Item -Path .\.sonar\scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path .\.sonar\scanner
- if: ( steps.step_conditionals_handler.outputs.is_not_PR )
name: Lowercase string generator
id: lowercase_string_gen
shell: powershell
run: |
$LOWERCASE_OWNER = "${{ github.repository_owner }}".ToLower()
echo "::set-output name=owner_name::$LOWERCASE_OWNER"
- if: ( steps.step_conditionals_handler.outputs.is_not_PR )
name: Initialize SonarCloud scanner
id: init_sonar_scanner
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner begin `
/k:"${{ github.repository_owner }}_${{ github.event.repository.name }}" `
/o:"${{ steps.lowercase_string_gen.outputs.owner_name }}" `
/d:sonar.login="$env:SONAR_TOKEN" `
/d:sonar.host.url="https://sonarcloud.io"
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- if: ( steps.step_conditionals_handler.outputs.is_github_release )
name: Create PFX certificate for AppxBundle
id: create_pfx_cert
shell: powershell
run: |
$BASE64_STR = $env:BASE64_STR
$TARGET_FILE = "$env:DEFAULT_DIR\cert.pfx"
$FROM_BASE64_STR = [Convert]::FromBase64String($BASE64_STR)
[IO.File]::WriteAllBytes($TARGET_FILE, $FROM_BASE64_STR)
env:
BASE64_STR: ${{ secrets.PFX_TO_BASE64 }}
DEFAULT_DIR: ${{ github.workspace }}
- name: Restore the application
id: restore_application
shell: powershell
run: |
msbuild $env:Solution_Name `
/t:Restore `
/p:Configuration=$env:Configuration
env:
Configuration: ${{ matrix.configuration }}
- name: Determine if signing should be applied to AppxBundle
id: determine_signing
shell: powershell
run: |
[bool]$PARAM = $false
if ( $env:IS_GITHUB_RELEASE ) {
$PARAM = $true
}
echo "::set-output name=parameter::$(echo $PARAM)"
env:
$IS_GITHUB_RELEASE: ${{ steps.step_conditionals_handler.outputs.is_github_release }}
- name: Build and generate bundles
id: build_app
shell: powershell
run: |
msbuild $env:Solution_Name `
/p:Platform=$env:Platform `
/p:Configuration=$env:Configuration `
/p:UapAppxPackageBuildMode=$env:Uap_Appx_Package_Build_Mode `
/p:AppxBundle=$env:Appx_Bundle `
/p:AppxPackageSigningEnabled=$env:Appx_Package_Signing_Enabled `
/p:AppxBundlePlatforms=$env:Appx_Bundle_Platforms `
/p:AppxPackageDir=$env:Artifacts_Dir `
/p:PackageCertificateKeyFile=$env:PackageCertificateKeyFile `
/p:PackageCertificatePassword=$env:PackageCertificatePassword
env:
Platform: x64
Configuration: ${{ matrix.configuration }}
Uap_Appx_Package_Build_Mode: StoreUpload
Appx_Bundle: Always
Appx_Package_Signing_Enabled: ${{ steps.determine_signing.outputs.parameter }}
Appx_Bundle_Platforms: x86|x64
Artifacts_Dir: ${{ github.workspace }}\Artifacts
PackageCertificateKeyFile: ${{ github.workspace }}\cert.pfx
PackageCertificatePassword: ${{ secrets.PACKAGE_CERTIFICATE_PWD }}
- if: ( steps.step_conditionals_handler.outputs.is_not_PR )
name: Send SonarCloud results
id: send_sonar_results
shell: powershell
run: |
.\.sonar\scanner\dotnet-sonarscanner end `
/d:sonar.login="${{ secrets.SONAR_TOKEN }}"
env:
GITHUB_TOKEN: ${{ secrets.SONAR_GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- if: ( steps.step_conditionals_handler.outputs.is_github_release )
name: Upload build artifacts
id: upload_artifacts
uses: actions/upload-artifact@v1
with:
name: Build artifacts
path: Artifacts/
cd:
# "This job will execute when the workflow is triggered on a 'push event', the target branch is 'master' and the commit is intended to be a release."
if: ( needs.ci.outputs.is_github_release ) && needs.ci.outputs.new_version_tag != needs.ci.outputs.latest_tag
needs: ci
runs-on: windows-latest
env:
NEW_VERSION: ${{ needs.ci.outputs.new_version }}
NEW_TAG: ${{ needs.ci.outputs.new_version_tag }}
steps:
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v2
- name: Download and extract MSIX package
id: dl_package_artifact
uses: actions/download-artifact@v2
with:
name: Build artifacts
path: Artifacts/
- name: Create and publish release
id: create_release
uses: actions/create-release@v1
with:
tag_name: ${{ env.NEW_TAG }}
release_name: Notepads ${{ env.NEW_TAG }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload msixbundle as release asset
id: upload_notepads_zip
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: Artifacts/Notepads_${{ env.NEW_VERSION }}_Test/Notepads_${{ env.NEW_VERSION }}_x86_x64.msixbundle
asset_name: Notepads_${{ env.NEW_VERSION }}_x86_x64.msixbundle
asset_content_type: application/zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# Built with ❤ by [Pipeline Foundation](https://pipeline.foundation)