Skip to content

Commit 1c8c486

Browse files
committed
feat: 1 CI jobs to pack chocolatey package, 1 CI job to push it
1 parent 78bfce1 commit 1c8c486

File tree

10 files changed

+75
-43
lines changed

10 files changed

+75
-43
lines changed

.github/workflows/build_release_assets.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,19 @@ jobs:
240240
# automatically do it on Windows
241241
pdm run bash -c "scripts/build-os-packages/build-os-packages $args"
242242
243+
- name: Build Chocolatey package & test it
244+
# About test part, cf https://docs.chocolatey.org/en-us/create/create-packages/#testing-your-package
245+
if: startsWith(matrix.os, 'windows-')
246+
shell: bash
247+
run: |
248+
windows_zip=$(find packages -maxdepth 1 -type f -name "*.zip" | grep "windows" | head -n 1)
249+
scripts/chocolatey/pack $windows_zip packages
250+
cd packages
251+
choco install ggshield --debug --verbose --source . --noop
252+
env:
253+
# otherwise grep -P in pack chocolatey/pack script fails on Windows
254+
LC_ALL: en_US.utf8
255+
243256
- name: Override base Docker image used for functional tests on Windows
244257
if: matrix.os == 'windows-2022'
245258
# This is required because GitHub Windows runner is not configured to
@@ -261,7 +274,6 @@ jobs:
261274
TEST_GG_VALID_TOKEN: ${{ secrets.TEST_GG_VALID_TOKEN }}
262275
TEST_GG_VALID_TOKEN_IGNORE_SHA: ${{ secrets.TEST_GG_VALID_TOKEN_IGNORE_SHA }}
263276
TEST_UNKNOWN_SECRET: ${{ secrets.TEST_UNKNOWN_SECRET }}
264-
265277
- name: Upload artifacts
266278
uses: actions/upload-artifact@v4
267279
with:
@@ -272,6 +284,7 @@ jobs:
272284
packages/ggshield-*.zip
273285
packages/ggshield-*.rpm
274286
packages/ggshield_*.deb
287+
packages/ggshield.*.nupkg
275288
276289
# Run some basic tests, the goal is to verify the ggshield binary has all the
277290
# libraries it needs to run

.github/workflows/tag.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ jobs:
8282
packages/ggshield_*.deb \
8383
packages/ggshield-*.rpm \
8484
packages/ggshield-*.zip \
85+
packages/ggshield.*.nupkg \
8586
packages/ggshield-*.gz
8687
8788
update_vscode_extension:
@@ -151,19 +152,22 @@ jobs:
151152
push_to_chocolatey:
152153
needs: build_release_assets
153154
name: Push to Chocolatey
154-
runs-on: chocolatey/choco
155+
runs-on: windows-latest
155156
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
156157
steps:
157158
- name: Checkout
158159
uses: actions/checkout@v4
159160

160-
- name: Download packages
161+
- name: Download nupkg
162+
id: download-nupkg
161163
uses: actions/download-artifact@v4
162164
with:
163-
pattern: os-packages-windows-2022
165+
pattern: ggshield.*.nupkg
164166
path: packages
165-
merge-multiple: true
166167

167168
- name: Push to Chocolatey
168169
run: |
169-
scripts/push-to-chocolatey/push-to-chocolatey
170+
nupkg_path=$(find ${{ steps.download-nupkg.outputs.download-path }} -maxdepth 1 -type f -name "*.nupkg" | head -n 1)
171+
scripts/chocolatey/push $nupkg_path
172+
env:
173+
CHOCOLATEY_API_KEY: ${{ secrets.CHOCOLATEY_API_KEY }}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### Added
2+
3+
- Added ggshield nukpg package (for installation with Chocolatey on Windows) to release assets.

scripts/push-to-chocolatey/README.md renamed to scripts/chocolatey/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Push to Chocolatey
1+
# Chocolatey
22

33
This folder contains everything necessary to build and publish the chocolatey package.
44

File renamed without changes.

scripts/chocolatey/pack

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# parse command line arguments
5+
zip_name=$1
6+
output_dir=$2
7+
8+
# unzip to folder
9+
if ! command -v unzip > /dev/null ; then
10+
apt update
11+
apt install unzip
12+
fi
13+
mkdir win_package
14+
unzip $zip_name -d win_package
15+
16+
version=$(echo "$zip_name" | grep -oP '(?<=ggshield-)[0-9.]+')
17+
18+
# choco-package will contain everything needed to build the nupkg
19+
mkdir choco-package
20+
mkdir choco-package/tools
21+
22+
mv win_package/*/_internal choco-package/tools
23+
mv win_package/*/ggshield.exe choco-package/tools
24+
cp scripts/chocolatey/ggshield.nuspec choco-package
25+
cp scripts/chocolatey/VERIFICATION.txt choco-package/tools
26+
cp LICENSE choco-package/tools/LICENSE.txt
27+
sed -i "s/__VERSION__/$version/" choco-package/ggshield.nuspec
28+
29+
choco pack choco-package/* --version $version --outdir $output_dir
30+
31+
rm -rf win_package choco-package

scripts/chocolatey/push

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
die() {
5+
echo $* >&2
6+
exit 1
7+
}
8+
9+
if [ -z "${CHOCOLATEY_API_KEY:-}" ] ; then
10+
die '$CHOCOLATEY_API_KEY is not set'
11+
fi
12+
13+
# parse command line arguments
14+
choco_nupkg=$1
15+
16+
# push to chocolatey
17+
choco push $choco_nupkg --source https://push.chocolatey.org/ --api-key $CHOCOLATEY_API_KEY

scripts/push-to-chocolatey/push-to-chocolatey

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)