Skip to content

Commit a157352

Browse files
authored
Merge pull request #1093 from GitGuardian/severine/fix-choco-publication
feat: 1 CI jobs to pack chocolatey package, 1 CI job to push it
2 parents 78bfce1 + cca2799 commit a157352

File tree

11 files changed

+74
-48
lines changed

11 files changed

+74
-48
lines changed

.github/workflows/build_release_assets.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,6 @@ jobs:
261261
TEST_GG_VALID_TOKEN: ${{ secrets.TEST_GG_VALID_TOKEN }}
262262
TEST_GG_VALID_TOKEN_IGNORE_SHA: ${{ secrets.TEST_GG_VALID_TOKEN_IGNORE_SHA }}
263263
TEST_UNKNOWN_SECRET: ${{ secrets.TEST_UNKNOWN_SECRET }}
264-
265264
- name: Upload artifacts
266265
uses: actions/upload-artifact@v4
267266
with:
@@ -272,6 +271,7 @@ jobs:
272271
packages/ggshield-*.zip
273272
packages/ggshield-*.rpm
274273
packages/ggshield_*.deb
274+
packages/ggshield.*.nupkg
275275
276276
# Run some basic tests, the goal is to verify the ggshield binary has all the
277277
# 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
169+
shell: bash
168170
run: |
169-
scripts/push-to-chocolatey/push-to-chocolatey
171+
scripts/chocolatey/push packages/ggshield.*.nupkg
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/build-os-packages/build-os-packages

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ init_system_vars() {
114114
EXE_EXT=".exe"
115115
HUMAN_OS=Windows
116116
TARGET="$arch-pc-windows-msvc"
117+
REQUIREMENTS="$REQUIREMENTS choco"
117118
;;
118119
*)
119120
die "Unknown OS. uname printed '$out'"
@@ -320,11 +321,8 @@ step_create_archive() {
320321
info "Archive created in $pkg_path & $archive_path"
321322
;;
322323
Windows)
323-
archive_path="$PACKAGES_DIR/$ARCHIVE_DIR_NAME.zip"
324-
pushd "$PACKAGES_DIR"
325-
7z a "$archive_path" "$ARCHIVE_DIR_NAME"
326-
popd
327-
info "Archive created in $archive_path"
324+
create_windows_packages
325+
test_chocolatey_package
328326
;;
329327
esac
330328
}

scripts/build-os-packages/windows-functions.bash

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,43 @@ windows_sign() {
2626
--input "$archive_dir/$INSTALL_PREFIX/ggshield.exe"
2727
}
2828

29+
windows_create_archive() {
30+
local archive_path="$PACKAGES_DIR/$ARCHIVE_DIR_NAME.zip"
31+
pushd "$PACKAGES_DIR"
32+
7z a "$archive_path" "$ARCHIVE_DIR_NAME"
33+
popd
34+
info "Archive created in $archive_path"
35+
}
36+
37+
windows_build_chocolatey_package() {
38+
# choco-package will contain everything needed to build the nupkg
39+
# we delete it a the end.
40+
mkdir choco-package
41+
mkdir choco-package/tools
42+
43+
cp -r "$PACKAGES_DIR/$ARCHIVE_DIR_NAME/_internal" choco-package/tools
44+
cp "$PACKAGES_DIR/$ARCHIVE_DIR_NAME/ggshield.exe" choco-package/tools
45+
cp "$ROOT_DIR/scripts/chocolatey/ggshield.nuspec" choco-package
46+
cp "$ROOT_DIR/scripts/chocolatey/VERIFICATION.txt" choco-package/tools
47+
cp "$ROOT_DIR/LICENSE" choco-package/tools/LICENSE.txt
48+
sed -i "s/__VERSION__/$VERSION/" choco-package/ggshield.nuspec
49+
50+
choco pack choco-package/* --version $VERSION --outdir $PACKAGES_DIR
51+
52+
info "Chocolatey package created in $PACKAGES_DIR/ggshield.$VERSION.nupkg"
53+
54+
rm -rf choco-package
55+
56+
}
57+
58+
# cf https://docs.chocolatey.org/en-us/create/create-packages/#testing-your-package
59+
test_chocolatey_package() {
60+
pushd "$PACKAGES_DIR"
61+
choco install ggshield --debug --verbose --source . --noop
62+
popd
63+
}
64+
65+
create_windows_packages() {
66+
windows_create_archive
67+
windows_build_chocolatey_package
68+
}

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/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

0 commit comments

Comments
 (0)