Skip to content

Commit

Permalink
feat: add configurable auto update url
Browse files Browse the repository at this point in the history
This will allow the plugin to be built from any repo without code changes, and allows us to have the auto-update file in our release artifacts instead of the repo
  • Loading branch information
desmaraisp committed Dec 9, 2024
1 parent 7f7217c commit 5f77840
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 39 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/create_pre-release-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ jobs:

- name: publish
run: |
msbuild -t:restore,build -m -p:"Configuration=Release;Platform=Any Cpu" .\src\KPSyncForDrive.csproj `
-p:'CompileTimeConfig_ClientId=${{vars.GCPCLIENTID}}' -p:'CompileTimeConfig_GoogleDrivePickerAppId=${{vars.GDRIVEAPPID}}' `
-p:'CompileTimeConfig_DriveFilePickerPublicApiKey=${{vars.GDRIVEFILEPICKERAPIKEY}}' `
-p:'CompileTimeConfig_PublicClientSecret=${{vars.PublicClientSecret }}'
msbuild -t:restore,build -m -p:"Configuration=Release;Platform=Any Cpu" GoogleDriveSync.sln
# The publish needs to be run separately, since the PLGX build task seems to not run on first build
msbuild -t:publish -m -p:"Configuration=Release;Platform=Any Cpu" .\src\KPSyncForDrive.csproj `
Expand Down
34 changes: 20 additions & 14 deletions .github/workflows/publish-on-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,37 @@ jobs:
- uses: microsoft/setup-msbuild@v2

- name: publish
env:
VersionNumber: ${{github.event.release.name}}
run: |
msbuild -t:restore,build -m -p:"Configuration=Release;Platform=Any Cpu" .\src\KPSyncForDrive.csproj `
-p:'CompileTimeConfig_ClientId=${{vars.GCPCLIENTID}}' -p:'CompileTimeConfig_GoogleDrivePickerAppId=${{vars.GDRIVEAPPID}}' `
-p:'CompileTimeConfig_DriveFilePickerPublicApiKey=${{vars.GDRIVEFILEPICKERAPIKEY}}' `
-p:'CompileTimeConfig_PublicClientSecret=${{vars.PublicClientSecret }}' `
-p:'Version=${{github.event.release.name}}'
msbuild -t:restore,build -m -p:"Configuration=Release;Platform=Any Cpu" GoogleDriveSync.sln
# The publish needs to be run separately, since the PLGX build task seems to not run on first build
msbuild -t:publish -m -p:"Configuration=Release;Platform=Any Cpu" .\src\KPSyncForDrive.csproj `
-p:'CompileTimeConfig_ClientId=${{vars.GCPCLIENTID}}' -p:'CompileTimeConfig_GoogleDrivePickerAppId=${{vars.GDRIVEAPPID}}' `
-p:'CompileTimeConfig_ClientId=${{vars.GCPCLIENTID}}' `
-p:'CompileTimeConfig_GoogleDrivePickerAppId=${{vars.GDRIVEAPPID}}' `
-p:'CompileTimeConfig_DriveFilePickerPublicApiKey=${{vars.GDRIVEFILEPICKERAPIKEY}}' `
-p:'CompileTimeConfig_PublicClientSecret=${{vars.PublicClientSecret }}' `
-p:'Version=${{github.event.release.name}}'
-p:Version=$Env:VersionNumber `
-p:'CompileTimeConfig_UpdateUrlPubKey=${{vars.UpdateUrlPubKey}}' `
-p:'CompileTimeConfig_UpdateUrl=https://github.com/${{github.repository}}/releases/latest/download/kpsync_final.txt'
- name: Create dist directory
run: mkdir ./dist

- name: Generate AutoUpdate file
run: |
"${{secrets.SIGNING_PRIVATEKEY_XML}}" | Set-Content .\lib\src\GenVerInfo\privateKey.xml -Force
msbuild -t:restore,build,publish -p:Configuration=Release .\lib\src\GenVerInfo\GenVerInfo.csproj
msbuild -t:publish -p:Configuration=Release .\lib\src\GenVerInfo\GenVerInfo.csproj
& ".\lib\src\GenVerInfo\bin\Release\net48\GenVerInfo.exe" "./src/bin/Any Cpu/Release/net48/publish/KPSyncForDrive.dll" ./dist/kpsync_final.txt
- name: zip results
shell: pwsh
env:
VersionNumber: ${{github.event.release.name}}
run: |
move-item "./src/bin/Any Cpu/Release/net48/*.plgx" -Destination ./dist/KPSyncForDrive-${{github.event.release.name}}.plgx
Compress-Archive -Path "./src/bin/Any Cpu/Release/net48/publish/*" -DestinationPath ./dist/KPSyncForDrive-${{github.event.release.name}}.zip -CompressionLevel Optimal -Force
move-item "./src/bin/Any Cpu/Release/net48/*.plgx" -Destination ./dist/KPSyncForDrive-$Env:VersionNumber.plgx
Compress-Archive -Path "./src/bin/Any Cpu/Release/net48/publish/*" -DestinationPath ./dist/KPSyncForDrive-$Env:VersionNumber.zip -CompressionLevel Optimal -Force
[System.IO.FileSystemInfo[]]$files = Get-ChildItem ./dist/
Write-Host "$($files.Count) files found in dist directory:"
$files
Expand All @@ -57,22 +60,25 @@ jobs:
subject-path: './dist/*'

- uses: actions/github-script@v6
env:
ReleaseName: ${{github.event.release.name}}
with:
script: |
const { ReleaseName } = process.env
const fs = require('fs').promises;
await github.rest.repos.uploadReleaseAsset({
name: 'KPSyncForDrive-${{github.event.release.name}}.plgx',
name: `KPSyncForDrive-${ReleaseName}.plgx`,
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ github.event.release.id }},
data: await fs.readFile('./dist/KPSyncForDrive-${{github.event.release.name}}.plgx')
data: await fs.readFile(`./dist/KPSyncForDrive-${ReleaseName}.plgx`)
});
await github.rest.repos.uploadReleaseAsset({
name: 'KPSyncForDrive-${{github.event.release.name}}.zip',
name: `KPSyncForDrive-${ReleaseName}.zip`,
owner: context.repo.owner,
repo: context.repo.repo,
release_id: ${{ github.event.release.id }},
data: await fs.readFile('./dist/KPSyncForDrive-${{github.event.release.name}}.zip')
data: await fs.readFile(`./dist/KPSyncForDrive-${ReleaseName}.zip`)
});
await github.rest.repos.uploadReleaseAsset({
name: 'kpsync_final.txt',
Expand Down
11 changes: 0 additions & 11 deletions src/GdsDefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
**/

using KeePassLib.Security;
using System;
using System.Reflection;

namespace KPSyncForDrive
Expand Down Expand Up @@ -81,15 +80,6 @@ public static ProtectedString PsEmptyEx
}
}

public static string UpdateUrl
{
get
{
return UrlUpdateFormat;
}
}

public const string GitHubProjectName = "google-drive-sync";
public const string ConfigUUID = "GoogleSync.AccountUUID";

public const string ConfigTrue = "TRUE";
Expand All @@ -102,7 +92,6 @@ public static string UpdateUrl
public const string UrlHelp = UrlHome;
public const string UrlGoogleDev = "https://console.developers.google.com/start";
public const string UrlGoogleDrive = "https://drive.google.com";
public const string UrlUpdateFormat = "https://raw.githubusercontent.com/walterpg/"+ GitHubProjectName + "/master/kpsync_final.txt";
public const string UrlSignInHelp = "https://developers.google.com/identity/sign-in/web/troubleshooting";
public const string UrlSharedFileHelp = UrlHome + "/notices/sharedsec";
public const string UrlPersonalAppCreds = UrlHome + "/usage/oauth";
Expand Down
7 changes: 5 additions & 2 deletions src/GoogleDriveSyncExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public override string UpdateUrl
{
get
{
return GdsDefs.UpdateUrl;
return _serviceProvider.GetRequiredService<ICompileTimeConfigAccessor<PluginStaticConfiguration>>().GetConfig().UpdateUrl;
}
}

Expand Down Expand Up @@ -146,7 +146,10 @@ public override bool Initialize(IPluginHost host)
_serviceProvider = serviceCollection.BuildServiceProvider();


UpdateCheckEx.SetFileSigKey(UpdateUrl, Images.PubKey);
UpdateCheckEx.SetFileSigKey(
UpdateUrl,
_serviceProvider.GetRequiredService<ICompileTimeConfigAccessor<PluginStaticConfiguration>>()
.GetConfig().UpdateUrlPubKey);
m_host = host;

PluginConfig appDefaults = PluginConfig.InitDefault(host);
Expand Down
3 changes: 0 additions & 3 deletions src/Images.resx
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@
<data name="outline_settings_black_48dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>images\outline_settings_black_48dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="PubKey" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>images\pubkey.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8</value>
</data>
<data name="round_cloud_download_black_18dp" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>images\round_cloud_download_black_18dp.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
Expand Down
5 changes: 0 additions & 5 deletions src/Images/PubKey.xml

This file was deleted.

3 changes: 3 additions & 0 deletions src/KPSyncForDrive.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
<CompileTimeConfig_DriveFilePickerPublicApiKey>DevPublicApiKey</CompileTimeConfig_DriveFilePickerPublicApiKey>
<CompileTimeConfig_GoogleDrivePickerAppId>DevAppId</CompileTimeConfig_GoogleDrivePickerAppId>
<CompileTimeConfig_PublicClientSecret>DevClientSecret</CompileTimeConfig_PublicClientSecret>
<CompileTimeConfig_UpdateUrl>https://github.com/YourFork/google-drive-sync/releases/latest/download/kpsync_final.txt</CompileTimeConfig_UpdateUrl>
</PropertyGroup>

<ItemGroup>
<CompilerVisibleProperty Include="CompileTimeConfig_ClientId" />
<CompilerVisibleProperty Include="CompileTimeConfig_GoogleDrivePickerAppId" />
<CompilerVisibleProperty Include="CompileTimeConfig_DriveFilePickerPublicApiKey" />
<CompilerVisibleProperty Include="CompileTimeConfig_PublicClientSecret" />
<CompilerVisibleProperty Include="CompileTimeConfig_UpdateUrl" />
<CompilerVisibleProperty Include="CompileTimeConfig_UpdateUrlPubKey" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 2 additions & 0 deletions src/OptionsAccessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public class PluginStaticConfiguration
public string PublicClientSecret { get; set; }
public string DriveFilePickerPublicApiKey { get; set; }
public string GoogleDrivePickerAppId { get; set; }
public string UpdateUrl { get; set; }
public string UpdateUrlPubKey { get; set; }
}
}

0 comments on commit 5f77840

Please sign in to comment.