Skip to content

Commit bb8031c

Browse files
authored
GitHub: Added ps1 scripts to simplify CI/CD (#15030)
1 parent be0ab46 commit bb8031c

File tree

3 files changed

+127
-123
lines changed

3 files changed

+127
-123
lines changed
Lines changed: 23 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
name: Deploy Preview Pipeline
1+
# Copyright (c) 2024 Files Community
2+
# Licensed under the MIT License. See the LICENSE.
3+
4+
name: Files CD (Preview)
25

36
on:
47
workflow_dispatch:
@@ -27,72 +30,31 @@ jobs:
2730
steps:
2831
- name: Checkout the repository
2932
uses: actions/checkout@v4
30-
3133
- name: Setup MSBuild
3234
uses: microsoft/setup-msbuild@v1
33-
3435
- name: Setup NuGet
3536
uses: NuGet/setup-nuget@v1.1.1
36-
3737
- name: Setup .NET 8
3838
uses: actions/setup-dotnet@v3
3939
with:
4040
dotnet-version: '8.0.x'
4141

42-
# TODO: Move the command to PowerShell script instead
43-
- name: Update Package.appxmanifest
42+
- name: Configure the package manifest, logo sets, and secrets
4443
shell: pwsh
4544
run: |
46-
[xml]$xmlDoc = Get-Content "$env:PACKAGE_PROJECT_DIR\Package.appxmanifest"
47-
$xmlDoc.Package.Identity.Name="FilesPreview"
48-
$xmlDoc.Package.Identity.Publisher="$env:SIDELOAD_PUBLISHER_SECRET"
49-
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
50-
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
51-
$xmlDoc.Save("$env:PACKAGE_PROJECT_DIR\Package.appxmanifest")
45+
. './scripts/Configure-AppxManifest.ps1' `
46+
-Branch "$env:CONFIGURATION" `
47+
-PackageProjectDir "$env:PACKAGE_PROJECT_DIR" `
48+
-Publisher "$env:SIDELOAD_PUBLISHER_SECRET" `
49+
-WorkingDir "$env:WORKING_DIR" `
50+
-SecretBingMapsKey "$env:SECRET_BINGMAPS_KEY" `
51+
-SecretAppCenter "$env:SECRET_APPCENTER" `
52+
-SecretGitHubOAuthClientId "$env:SECRET_GITHUB_OAUTH_CLIENT_ID"
5253
env:
5354
SIDELOAD_PUBLISHER_SECRET: ${{ secrets.SIDELOAD_PUBLISHER_SECRET }}
54-
55-
# TODO: Move the command to PowerShell script instead
56-
- name: Use the ${{ env.CONFIGURATION }} logo sets
57-
shell: pwsh
58-
run: |
59-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach -Process `
60-
{ `
61-
(Get-Content $_ -Raw | ForEach -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) | `
62-
Set-Content $_ -NoNewline `
63-
}
64-
65-
- name: Inject the Bing Maps API token
66-
shell: pwsh
67-
run: |
68-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
69-
{ `
70-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "bingmapskey.secret", "$env:BING_MAPS_SECRET" }) | `
71-
Set-Content $_ -NoNewline `
72-
}
73-
env:
74-
BING_MAPS_SECRET: ${{ secrets.BING_MAPS_SECRET }}
75-
76-
- name: Inject the AppCenter token
77-
shell: pwsh
78-
run: |
79-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
80-
{ `
81-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "appcenter.secret", "$env:APP_CENTER_SECRET" }) | `
82-
Set-Content $_ -NoNewline `
83-
}
84-
env:
85-
APP_CENTER_SECRET: ${{ secrets.APP_CENTER_SECRET }}
86-
87-
- name: Inject the GitHub OAuth client ID
88-
run: |
89-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
90-
{ `
91-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "githubclientid.secret", "$env:GH_OAUTH_CLIENT_ID" }) | `
92-
Set-Content $_ -NoNewline `
93-
}
94-
env:
95-
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}
55+
SECRET_BINGMAPS_KEY: ${{ secrets.BING_MAPS_SECRET }}
56+
SECRET_APPCENTER: ${{ secrets.APP_CENTER_SECRET }}
57+
SECRET_GITHUB_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}
9658

9759
- name: Use Windows SDK Preview
9860
shell: cmd
@@ -156,21 +118,20 @@ jobs:
156118
timestamp-rfc3161: http://timestamp.acs.microsoft.com
157119
timestamp-digest: SHA256
158120

159-
- uses: azure/login@v1
121+
- name: Login to Azure
122+
uses: azure/login@v1
160123
with:
161-
creds: ${{ secrets.AZURE_CREDENTIALS }}
124+
creds: ${{ secrets.AZURE_CREDENTIALS }}
162125

163-
- name: Upload to blob storage
126+
- name: Upload to Azure blob storage
164127
uses: azure/powershell@v1
165128
with:
166129
inlineScript: |
167-
az storage blob upload-batch --account-name "filescommunity" --destination "files" --destination-path "preview" --source ${{ env.APPX_PACKAGE_DIR }} --overwrite true
130+
az storage blob upload-batch --account-name "filescommunity" --destination "files" --destination-path "preview" --source ${{ env.APPX_PACKAGE_DIR }} --overwrite true
168131
azPSVersion: "latest"
169132

170-
# Azure logout
171-
- name: logout
172-
run: |
173-
az logout
133+
- name: Logout from Azure
134+
run: 'az logout'
174135

175136
- name: Upload the packages to GitHub Actions
176137
uses: actions/upload-artifact@v3
Lines changed: 22 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
name: Deploy Stable Pipeline
1+
# Copyright (c) 2024 Files Community
2+
# Licensed under the MIT License. See the LICENSE.
3+
4+
name: Files CD (Stable)
25

36
on:
47
workflow_dispatch:
@@ -27,73 +30,32 @@ jobs:
2730
steps:
2831
- name: Checkout the repository
2932
uses: actions/checkout@v4
30-
3133
- name: Setup MSBuild
3234
uses: microsoft/setup-msbuild@v1
33-
3435
- name: Setup NuGet
3536
uses: NuGet/setup-nuget@v1.1.1
36-
3737
- name: Setup .NET 8
3838
uses: actions/setup-dotnet@v3
3939
with:
4040
dotnet-version: '8.0.x'
4141

42-
# TODO: Move the command to PowerShell script instead
43-
- name: Update Package.appxmanifest
42+
- name: Configure the package manifest, logo sets, and secrets
4443
shell: pwsh
4544
run: |
46-
[xml]$xmlDoc = Get-Content "$env:PACKAGE_PROJECT_DIR\Package.appxmanifest"
47-
$xmlDoc.Package.Identity.Name="Files"
48-
$xmlDoc.Package.Identity.Publisher="$env:SIDELOAD_PUBLISHER_SECRET"
49-
$xmlDoc.Package.Properties.DisplayName="Files"
50-
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
51-
$xmlDoc.Save("$env:PACKAGE_PROJECT_DIR\Package.appxmanifest")
45+
. './scripts/Configure-AppxManifest.ps1' `
46+
-Branch "$env:CONFIGURATION" `
47+
-PackageProjectDir "$env:PACKAGE_PROJECT_DIR" `
48+
-Publisher "$env:SIDELOAD_PUBLISHER_SECRET" `
49+
-WorkingDir "$env:WORKING_DIR" `
50+
-SecretBingMapsKey "$env:SECRET_BINGMAPS_KEY" `
51+
-SecretAppCenter "$env:SECRET_APPCENTER" `
52+
-SecretGitHubOAuthClientId "$env:SECRET_GITHUB_OAUTH_CLIENT_ID"
5253
env:
5354
SIDELOAD_PUBLISHER_SECRET: ${{ secrets.SIDELOAD_PUBLISHER_SECRET }}
54-
55-
# TODO: Move the command to PowerShell script instead
56-
- name: Use the ${{ env.CONFIGURATION }} logo sets
57-
shell: pwsh
58-
run: |
59-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach -Process `
60-
{ `
61-
(Get-Content $_ -Raw | ForEach -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) | `
62-
Set-Content $_ -NoNewline `
63-
}
64-
65-
- name: Inject the Bing Maps API token
66-
shell: pwsh
67-
run: |
68-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
69-
{ `
70-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "bingmapskey.secret", "$env:BING_MAPS_SECRET" }) | `
71-
Set-Content $_ -NoNewline `
72-
}
73-
env:
74-
BING_MAPS_SECRET: ${{ secrets.BING_MAPS_SECRET }}
75-
76-
- name: Inject the AppCenter token
77-
shell: pwsh
78-
run: |
79-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
80-
{ `
81-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "appcenter.secret", "$env:APP_CENTER_SECRET" }) | `
82-
Set-Content $_ -NoNewline `
83-
}
84-
env:
85-
APP_CENTER_SECRET: ${{ secrets.APP_CENTER_SECRET }}
86-
87-
- name: Inject the GitHub OAuth client ID
88-
run: |
89-
Get-ChildItem "$env:WORKING_DIR\src" -Include *.cs -recurse | ForEach-Object -Process `
90-
{ `
91-
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "githubclientid.secret", "$env:GH_OAUTH_CLIENT_ID" }) | `
92-
Set-Content $_ -NoNewline `
93-
}
94-
env:
95-
GH_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}
96-
55+
SECRET_BINGMAPS_KEY: ${{ secrets.BING_MAPS_SECRET }}
56+
SECRET_APPCENTER: ${{ secrets.APP_CENTER_SECRET }}
57+
SECRET_GITHUB_OAUTH_CLIENT_ID: ${{ secrets.GH_OAUTH_CLIENT_ID }}
58+
9759
- name: Use Windows SDK Preview
9860
shell: cmd
9961
run: |
@@ -156,21 +118,20 @@ jobs:
156118
timestamp-rfc3161: http://timestamp.acs.microsoft.com
157119
timestamp-digest: SHA256
158120

159-
- uses: azure/login@v1
121+
- name: Login to Azure
122+
uses: azure/login@v1
160123
with:
161124
creds: ${{ secrets.AZURE_CREDENTIALS }}
162125

163-
- name: Upload to blob storage
126+
- name: Upload to Azure blob storage
164127
uses: azure/powershell@v1
165128
with:
166129
inlineScript: |
167130
az storage blob upload-batch --account-name "filescommunity" --destination "files" --destination-path "stable" --source ${{ env.APPX_PACKAGE_DIR }} --overwrite true
168131
azPSVersion: "latest"
169132

170-
# Azure logout
171-
- name: logout
172-
run: |
173-
az logout
133+
- name: Logout from Azure
134+
run: 'az logout'
174135

175136
- name: Upload the packages to GitHub Actions
176137
uses: actions/upload-artifact@v3

scripts/Configure-AppxManifest.ps1

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Copyright (c) 2024 Files Community
2+
# Licensed under the MIT License. See the LICENSE.
3+
4+
param(
5+
[string]$Branch = "",
6+
[string]$PackageProjectDir = "",
7+
[string]$Publisher = "",
8+
[string]$WorkingDir = "",
9+
[string]$SecretBingMapsKey = "",
10+
[string]$SecretAppCenter = "",
11+
[string]$SecretGitHubOAuthClientId = ""
12+
)
13+
14+
[xml]$xmlDoc = Get-Content "$PackageProjectDir\Package.appxmanifest"
15+
$xmlDoc.Package.Identity.Publisher="$Publisher"
16+
17+
if ($Branch -eq "Preview")
18+
{
19+
# Set identities
20+
$xmlDoc.Package.Identity.Name="FilesPreview"
21+
$xmlDoc.Package.Properties.DisplayName="Files - Preview"
22+
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files - Preview"
23+
24+
Get-ChildItem "$WorkingDir\src" -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach -Process
25+
{
26+
(Get-Content $_ -Raw | ForEach -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Preview" }) |
27+
Set-Content $_ -NoNewline
28+
}
29+
}
30+
elseif ($Branch -eq "Stable")
31+
{
32+
# Set identities
33+
$xmlDoc.Package.Identity.Name="Files"
34+
$xmlDoc.Package.Properties.DisplayName="Files"
35+
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
36+
37+
Get-ChildItem "$WorkingDir\src" -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach -Process
38+
{
39+
(Get-Content $_ -Raw | ForEach -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) |
40+
Set-Content $_ -NoNewline
41+
}
42+
}
43+
elseif ($Branch -eq "Store")
44+
{
45+
# Set identities
46+
$xmlDoc.Package.Identity.Name="49306atecsolution.FilesUWP"
47+
$xmlDoc.Package.Properties.DisplayName="Files"
48+
$xmlDoc.Package.Applications.Application.VisualElements.DisplayName="Files"
49+
50+
# Remove an capability that is used for the sideload
51+
$nsmgr = New-Object System.Xml.XmlNamespaceManager($xmlDoc.NameTable)
52+
$nsmgr.AddNamespace("pkg", "http://schemas.microsoft.com/appx/manifest/foundation/windows10")
53+
$nsmgr.AddNamespace("rescap", "http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities")
54+
$pm = $xmlDoc.SelectSingleNode("/pkg:Package/pkg:Capabilities/rescap:Capability[@Name='packageManagement']", $nsmgr)
55+
$xmlDoc.Package.Capabilities.RemoveChild($pm)
56+
57+
Get-ChildItem "$WorkingDir\src" -Include *.csproj, *.appxmanifest, *.wapproj, *.xaml -recurse | ForEach -Process
58+
{
59+
(Get-Content $_ -Raw | ForEach -Process { $_ -replace "Assets\\AppTiles\\Dev", "Assets\AppTiles\Release" }) |
60+
Set-Content $_ -NoNewline
61+
}
62+
}
63+
64+
$xmlDoc.Save("$PackageProjectDir\Package.appxmanifest")
65+
66+
Get-ChildItem "$WorkingDir\src" -Include *.cs -recurse | ForEach-Object -Process
67+
{
68+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "bingmapskey.secret", "$SecretBingMapsKey" }) |
69+
Set-Content $_ -NoNewline
70+
}
71+
72+
Get-ChildItem "$WorkingDir\src" -Include *.cs -recurse | ForEach-Object -Process
73+
{
74+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "appcenter.secret", "$SecretAppCenter" }) |
75+
Set-Content $_ -NoNewline
76+
}
77+
78+
Get-ChildItem "$WorkingDir\src" -Include *.cs -recurse | ForEach-Object -Process
79+
{
80+
(Get-Content $_ -Raw | ForEach-Object -Process { $_ -replace "githubclientid.secret", "$SecretGitHubOAuthClientId" }) |
81+
Set-Content $_ -NoNewline
82+
}

0 commit comments

Comments
 (0)