Skip to content

Commit 03075cd

Browse files
committed
test workflow
1 parent 7612b2e commit 03075cd

8 files changed

Lines changed: 336 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Chocolatey update dry run
2+
3+
on:
4+
push:
5+
branches:
6+
- chocolatey-update
7+
8+
jobs:
9+
chocolatey-dry-run:
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v6
14+
with:
15+
submodules: recursive
16+
17+
- name: Resolve latest release tag
18+
shell: pwsh
19+
env:
20+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
21+
run: |
22+
$tag = gh release list --limit 20 --exclude-drafts --json tagName,isPrerelease --jq '.[] | select(.isPrerelease==false) | .tagName' | Select-Object -First 1
23+
if (-not $tag) { throw "No non-prerelease tags found." }
24+
"RELEASE_TAG=$tag" | Out-File -FilePath $env:GITHUB_ENV -Append
25+
$version = $tag.TrimStart('v').Split('-')[0]
26+
"VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
27+
28+
- name: Download MSI asset
29+
shell: pwsh
30+
env:
31+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32+
run: |
33+
$msiName = "Defguard_${env:VERSION}_x64_en-US.msi"
34+
gh release download "$env:RELEASE_TAG" --pattern $msiName --dir "$pwd"
35+
36+
- name: Calculate MSI checksum
37+
shell: pwsh
38+
run: |
39+
$msiName = "Defguard_${env:VERSION}_x64_en-US.msi"
40+
$hash = (Get-FileHash -Algorithm SHA256 -Path $msiName).Hash.ToLower()
41+
"MSI_SHA256=$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
42+
43+
- name: Update Chocolatey package files
44+
shell: pwsh
45+
working-directory: chocolatey/defguard
46+
run: |
47+
$msiUrl = "https://github.com/DefGuard/client/releases/download/v$env:VERSION/Defguard_$env:VERSION_x64_en-US.msi"
48+
$nuspecPath = "defguard.nuspec"
49+
$installPath = "tools\chocolateyinstall.ps1"
50+
51+
(Get-Content -Raw $nuspecPath) `
52+
-replace '<version>[^<]+</version>', "<version>$env:VERSION</version>" `
53+
-replace '<packageSourceUrl>[^<]+</packageSourceUrl>', "<packageSourceUrl>$msiUrl</packageSourceUrl>" |
54+
Set-Content -NoNewline -Encoding UTF8 $nuspecPath
55+
56+
(Get-Content -Raw $installPath) `
57+
-replace "^\$url\s*=\s*'.*'$", "`$url = '$msiUrl'" `
58+
-replace "checksum\s*=\s*'[^']+'", "checksum = '$env:MSI_SHA256'" |
59+
Set-Content -NoNewline -Encoding UTF8 $installPath
60+
61+
- name: Debug updated files
62+
shell: pwsh
63+
working-directory: chocolatey/defguard
64+
run: |
65+
Write-Output "=== defguard.nuspec ==="
66+
Get-Content defguard.nuspec
67+
Write-Output "=== tools\chocolateyinstall.ps1 ==="
68+
Get-Content tools\chocolateyinstall.ps1
69+
70+
- name: Refresh local nupkg
71+
shell: pwsh
72+
working-directory: chocolatey/defguard
73+
run: |
74+
$old = Get-ChildItem -Filter "defguard.*.nupkg" | Where-Object { $_.Name -ne "defguard.$env:VERSION.nupkg" }
75+
if ($old) { $old | Remove-Item -Force }
76+
77+
- name: Pack Chocolatey package
78+
shell: pwsh
79+
working-directory: chocolatey/defguard
80+
run: choco pack
81+
82+
- name: Dry run complete
83+
shell: pwsh
84+
run: Write-Output "Dry run finished successfully. No push executed."
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# name: Update Chocolatey package
2+
3+
# on:
4+
# release:
5+
# types: [published]
6+
7+
# jobs:
8+
# update-chocolatey:
9+
# if: github.event.release.prerelease == false
10+
# runs-on: windows-latest
11+
# steps:
12+
# - name: Checkout
13+
# uses: actions/checkout@v6
14+
15+
# - name: Set release version
16+
# shell: pwsh
17+
# run: |
18+
# $version = "${{ github.event.release.tag_name }}".TrimStart('v').Split('-')[0]
19+
# "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append
20+
21+
# - name: Download MSI asset
22+
# shell: pwsh
23+
# env:
24+
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25+
# run: |
26+
# $msiName = "Defguard_${env:VERSION}_x64_en-US.msi"
27+
# gh release download "${{ github.event.release.tag_name }}" --pattern $msiName --dir "$pwd"
28+
29+
# - name: Calculate MSI checksum
30+
# shell: pwsh
31+
# run: |
32+
# $msiName = "Defguard_${env:VERSION}_x64_en-US.msi"
33+
# $hash = (Get-FileHash -Algorithm SHA256 -Path $msiName).Hash.ToLower()
34+
# "MSI_SHA256=$hash" | Out-File -FilePath $env:GITHUB_ENV -Append
35+
36+
# - name: Update Chocolatey package files
37+
# shell: pwsh
38+
# working-directory: chocolatey/defguard
39+
# run: |
40+
# $msiUrl = "https://github.com/DefGuard/client/releases/download/v$env:VERSION/Defguard_$env:VERSION_x64_en-US.msi"
41+
# $nuspecPath = "defguard.nuspec"
42+
# $installPath = "tools\chocolateyinstall.ps1"
43+
44+
# (Get-Content -Raw $nuspecPath) `
45+
# -replace '<version>[^<]+</version>', "<version>$env:VERSION</version>" `
46+
# -replace '<packageSourceUrl>[^<]+</packageSourceUrl>', "<packageSourceUrl>$msiUrl</packageSourceUrl>" |
47+
# Set-Content -NoNewline -Encoding UTF8 $nuspecPath
48+
49+
# (Get-Content -Raw $installPath) `
50+
# -replace "^\$url\s*=\s*'.*'$", "`$url = '$msiUrl'" `
51+
# -replace "checksum\s*=\s*'[^']+'", "checksum = '$env:MSI_SHA256'" |
52+
# Set-Content -NoNewline -Encoding UTF8 $installPath
53+
54+
# - name: Refresh local nupkg
55+
# shell: pwsh
56+
# working-directory: chocolatey/defguard
57+
# run: |
58+
# $old = Get-ChildItem -Filter "defguard.*.nupkg" | Where-Object { $_.Name -ne "defguard.$env:VERSION.nupkg" }
59+
# if ($old) { $old | Remove-Item -Force }
60+
61+
# - name: Pack Chocolatey package
62+
# shell: pwsh
63+
# working-directory: chocolatey/defguard
64+
# run: choco pack
65+
66+
# - name: Push Chocolatey package
67+
# shell: pwsh
68+
# working-directory: chocolatey/defguard
69+
# env:
70+
# CHOCO_API_KEY: ${{ secrets.CHOCO_API_KEY }}
71+
# run: |
72+
# $nupkg = "defguard.$env:VERSION.nupkg"
73+
# choco push $nupkg --source "https://push.chocolatey.org/" -k="$env:CHOCO_API_KEY"

chocolatey/defguard/README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Defguard Chocolatey package
2+
3+
This directory contains the Chocolatey package source for Defguard.
4+
The GitHub Actions workflow updates version, MSI URL, and checksum after a release is published.
5+
6+
## Workflow behavior
7+
8+
- Trigger: GitHub release `published` (non-prerelease).
9+
- Source MSI: Release asset named `Defguard_<version>_x64_en-US.msi`.
10+
- Updated files:
11+
- `defguard.nuspec` (`<version>`, `<packageSourceUrl>`)
12+
- `tools/chocolateyinstall.ps1` (`$url`, `checksum`)
13+
- Package build: `choco pack`.
14+
- Package push: `choco push` to `https://push.chocolatey.org/`.
15+
16+
## Required secret
17+
18+
- `CHOCO_API_KEY` in GitHub repo secrets.
19+
20+
## Local testing (Windows)
21+
22+
From this directory:
23+
24+
```
25+
choco pack
26+
choco install defguard --source .
27+
```
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Read this before creating packages: https://docs.chocolatey.org/en-us/create/create-packages -->
3+
<!-- It is especially important to read the above link to understand additional requirements when publishing packages to the community feed aka dot org (https://community.chocolatey.org/packages). -->
4+
5+
<!-- Test your packages in a test environment: https://github.com/chocolatey/chocolatey-test-environment -->
6+
7+
<!--
8+
This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Reference. Chocolatey uses a special version of NuGet.Core that allows us to do more than was initially possible. As such there are certain things to be aware of:
9+
10+
* the package xmlns schema url may cause issues with nuget.exe
11+
* Any of the following elements can ONLY be used by choco tools - projectSourceUrl, docsUrl, mailingListUrl, bugTrackerUrl, packageSourceUrl, provides, conflicts, replaces
12+
* nuget.exe can still install packages with those elements but they are ignored. Any authoring tools or commands will error on those elements
13+
-->
14+
15+
<!-- You can embed software files directly into packages, as long as you are not bound by distribution rights. -->
16+
<!-- * If you are an organization making private packages, you probably have no issues here -->
17+
<!-- * If you are releasing to the community feed, you need to consider distribution rights. -->
18+
<!-- Do not remove this test for UTF-8: if “Ω” doesn’t appear as greek uppercase omega letter enclosed in quotation marks, you should use an editor that supports UTF-8, not this one. -->
19+
<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
20+
<metadata>
21+
<!-- == PACKAGE SPECIFIC SECTION == -->
22+
<!-- This section is about this package, although id and version have ties back to the software -->
23+
<!-- id is lowercase and if you want a good separator for words, use '-', not '.'. Dots are only acceptable as suffixes for certain types of packages, e.g. .install, .portable, .extension, .template -->
24+
<!-- If the software is cross-platform, attempt to use the same id as the debian/rpm package(s) if possible. -->
25+
<id>defguard</id>
26+
<!-- version should MATCH as closely as possible with the underlying software -->
27+
<!-- Is the version a prerelease of a version? https://docs.nuget.org/create/versioning#creating-prerelease-packages -->
28+
<!-- Note that unstable versions like 0.0.1 can be considered a released version, but it's possible that one can release a 0.0.1-beta before you release a 0.0.1 version. If the version number is final, that is considered a released version and not a prerelease. -->
29+
<version>1.6.5</version>
30+
<packageSourceUrl>https://github.com/DefGuard/client/releases/download/v1.6.5/Defguard_1.6.5_x64_en-US.msi</packageSourceUrl>
31+
<!-- owners is a poor name for maintainers of the package. It sticks around by this name for compatibility reasons. It basically means you. -->
32+
<!--<owners>Defguard</owners>-->
33+
<!-- ============================== -->
34+
35+
<!-- == SOFTWARE SPECIFIC SECTION == -->
36+
<!-- This section is about the software itself -->
37+
<title>Defguard</title>
38+
<authors>Defguard</authors>
39+
<!-- projectUrl is required for the community feed -->
40+
<projectUrl>https://defguard.net</projectUrl>
41+
<!-- There are a number of CDN Services that can be used for hosting the Icon for a package. More information can be found here: https://docs.chocolatey.org/en-us/create/create-packages#package-icon-guidelines -->
42+
<!-- Here is an example using Githack -->
43+
<iconUrl>http://rawcdn.githack.com/defguard/client/main/src/shared/images/png/logo_256-256.png</iconUrl>
44+
<copyright>2026</copyright>
45+
<!-- If there is a license Url available, it is required for the community feed -->
46+
<licenseUrl>https://github.com/DefGuard/client/blob/main/LICENSE.md</licenseUrl>
47+
<requireLicenseAcceptance>true</requireLicenseAcceptance>
48+
<projectSourceUrl>https://github.com/DefGuard/client</projectSourceUrl>
49+
<docsUrl>https://docs.defguard.net/</docsUrl>
50+
<!--<mailingListUrl></mailingListUrl>-->
51+
<bugTrackerUrl>https://github.com/DefGuard/client/issues</bugTrackerUrl>
52+
<tags>defguard vpn wireguard sso mfa</tags>
53+
<summary>Desktop client for Defguard - Wireguard VPN with MFA</summary>
54+
<description>Desktop client provides an easy way to access VPN locations of multiple Defguard instances via user-friendly UI.</description>
55+
<releaseNotes>https://github.com/DefGuard/client/releases</releaseNotes>
56+
<!-- =============================== -->
57+
58+
<!-- Specifying dependencies and version ranges? https://docs.nuget.org/create/versioning#specifying-version-ranges-in-.nuspec-files -->
59+
<!--<dependencies>
60+
<dependency id="" version="__MINIMUM_VERSION__" />
61+
<dependency id="" version="[__EXACT_VERSION__]" />
62+
<dependency id="" version="[_MIN_VERSION_INCLUSIVE, MAX_VERSION_INCLUSIVE]" />
63+
<dependency id="" version="[_MIN_VERSION_INCLUSIVE, MAX_VERSION_EXCLUSIVE)" />
64+
<dependency id="" />
65+
<dependency id="chocolatey-core.extension" version="1.1.0" />
66+
</dependencies>-->
67+
<!-- chocolatey-core.extension - https://community.chocolatey.org/packages/chocolatey-core.extension -->
68+
69+
<!--<provides>NOT YET IMPLEMENTED</provides>-->
70+
<!--<conflicts>NOT YET IMPLEMENTED</conflicts>-->
71+
<!--<replaces>NOT YET IMPLEMENTED</replaces>-->
72+
</metadata>
73+
<files>
74+
<!-- this section controls what actually gets packaged into the Chocolatey package -->
75+
<file src="tools\**" target="tools" />
76+
</files>
77+
</package>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+

2+
Note: Include this file if including binaries you have the right to distribute.
3+
Otherwise delete. this file.
4+
5+
===DELETE ABOVE THIS LINE AND THIS LINE===
6+
7+
From: <insert applicable license url here>
8+
9+
LICENSE
10+
11+
<Insert License Here>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# This runs before upgrade or uninstall.
2+
# Use this file to do things like stop services prior to upgrade or uninstall.
3+
# NOTE: It is an anti-pattern to call chocolateyUninstall.ps1 from here. If you
4+
# need to uninstall an MSI prior to upgrade, put the functionality in this
5+
# file without calling the uninstall script. Make it idempotent in the
6+
# uninstall script so that it doesn't fail when it is already uninstalled.
7+
# NOTE: For upgrades - like the uninstall script, this script always runs from
8+
# the currently installed version, not from the new upgraded package version.
9+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
$ErrorActionPreference = 'Stop'
2+
$toolsDir = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
3+
$url = 'https://github.com/DefGuard/client/releases/download/v1.6.5/Defguard_1.6.5_x64_en-US.msi'
4+
5+
6+
$packageArgs = @{
7+
packageName = $env:ChocolateyPackageName
8+
unzipLocation = $toolsDir
9+
fileType = 'msi'
10+
url = $url
11+
12+
softwareName = 'defguard*'
13+
14+
checksum = 'be99afe71ab88e0add4905721471d0d40935c33ae7cdb47084ba53a91d675cc7'
15+
checksumType = 'sha256'
16+
17+
18+
silentArgs = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`""
19+
validExitCodes= @(0, 3010, 1641)
20+
}
21+
22+
Install-ChocolateyPackage @packageArgs
23+
Write-Warning "IMPORTANT: Reboot or Re-login Required: On initial install the user is added to the defguard group.A reboot or logging out and back in is required for group membership changes to take effect. This is not required on subsequent updates."
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
$ErrorActionPreference = 'Stop'
2+
$packageArgs = @{
3+
packageName = $env:ChocolateyPackageName
4+
softwareName = 'defguard*'
5+
fileType = 'msi'
6+
silentArgs = "/qn /norestart"
7+
validExitCodes= @(0, 3010, 1605, 1614, 1641)
8+
}
9+
10+
[array]$key = Get-UninstallRegistryKey -SoftwareName $packageArgs['softwareName']
11+
12+
if ($key.Count -eq 1) {
13+
$key | % {
14+
$packageArgs['file'] = "$($_.UninstallString)"
15+
16+
if ($packageArgs['fileType'] -eq 'MSI') {
17+
$packageArgs['silentArgs'] = "$($_.PSChildName) $($packageArgs['silentArgs'])"
18+
19+
$packageArgs['file'] = ''
20+
} else {
21+
}
22+
23+
Uninstall-ChocolateyPackage @packageArgs
24+
}
25+
} elseif ($key.Count -eq 0) {
26+
Write-Warning "$packageName has already been uninstalled by other means."
27+
} elseif ($key.Count -gt 1) {
28+
Write-Warning "$($key.Count) matches found!"
29+
Write-Warning "To prevent accidental data loss, no programs will be uninstalled."
30+
Write-Warning "Please alert package maintainer the following keys were matched:"
31+
$key | % {Write-Warning "- $($_.DisplayName)"}
32+
}

0 commit comments

Comments
 (0)