Skip to content

Commit 768ff42

Browse files
committed
build: add ZIP file source distribution
1 parent 5d39d76 commit 768ff42

File tree

2 files changed

+56
-3
lines changed

2 files changed

+56
-3
lines changed

.github/workflows/run_release.yml

+1
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ jobs:
5151
files: |
5252
scubagoggles-*-py3-none-any.whl
5353
scubagoggles-*.tar.gz
54+
scubagoggles-*.zip
5455
generate_release_notes: true
5556
fail_on_unmatched_files: true

scubagoggles/utils/build.sh

+55-3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ shopt -s expand_aliases
3333
gitTag=
3434
outDir="$PWD"
3535
scubaGogglesGit='[email protected]:cisagov/ScubaGoggles.git'
36+
zipSource=true
3637

3738
usage()
3839
{
@@ -45,9 +46,10 @@ usage()
4546
printf ' defaults to %s\n' "$scubaGogglesGit"
4647
printf ' -t <git-tag-or-branch>: checkout tag or branch for build\n'
4748
printf ' defaults to top of main branch\n'
49+
printf ' -x: omit the ZIP source distribution file\n'
4850
}
4951

50-
while getopts ':ho:r:t:' option
52+
while getopts ':ho:r:t:x' option
5153
do
5254
case "$option" in
5355
h)
@@ -64,6 +66,9 @@ do
6466
t)
6567
gitTag=$OPTARG
6668
;;
69+
x)
70+
zipSource=false
71+
;;
6772
?)
6873
usage
6974
exit 1
@@ -78,14 +83,52 @@ shift $((OPTIND -1))
7883
# Used to distinguish output from this script.
7984
buildPfx='{build>>>}'
8085

81-
cleanup() {
86+
cleanup()
87+
{
8288
echo "$buildPfx Performing build cleanup..."
8389
[[ $(type -t deactivate) == function ]] && deactivate
8490
[[ "${DIRSTACK[0]}" == "$scubaGoggles" ]] && popd
8591
rm -rf "$scubaEnv"
8692
rm -rf "$scubaGoggles"
8793
}
8894

95+
generateSourceZip()
96+
{
97+
# Generates a ZIP file version of the source code distribution, which is
98+
# in gzipped tar format (.tar.gz). There are 2 parameters to this function:
99+
#
100+
# generateSourceZip <gz-tar-file> <out-var-name>
101+
#
102+
# where <gz-tar-file> is an existing source distribution (the file must
103+
# end with ".tar.gz" (not ".tgz")), and <out-var-name> is the name of the
104+
# variable where the output file name will be written. The ZIP source
105+
# code file will be created in the same location as the given tar file.
106+
#
107+
# Python's PEP 517 has restricted the source distributions built by
108+
# backends to be gzipped tar files only.
109+
#
110+
# This work is done in a temporary directory, which is removed provided
111+
# that no errors occur during the creation of the ZIP file.
112+
113+
local gztarFile
114+
local sourceTemp
115+
local -n outFile=$2
116+
117+
gztarFile=$1
118+
sourceTemp=$(mktemp -d -t scubagoggles_src.XXXXXXXXXX)
119+
outFile=$(realpath "${gztarFile/tar.gz/zip}")
120+
121+
tar xfz "$gztarFile" -C "$sourceTemp"
122+
123+
pushd "$sourceTemp"
124+
125+
zip -qr "$outFile" .
126+
127+
popd
128+
129+
rm -rf "$sourceTemp"
130+
}
131+
89132
pushd() { builtin pushd "$@" > /dev/null; }
90133

91134
popd() { builtin popd > /dev/null; }
@@ -140,7 +183,16 @@ python -m build
140183
wheelFile=$(realpath dist/scubagoggles-*.whl)
141184
tarFile=$(realpath dist/scubagoggles-*.tar.gz)
142185

143-
for file in "$wheelFile" "$tarFile"
186+
packageFiles=("$wheelFile" "$tarFile")
187+
188+
if [ "$zipSource" == true ]
189+
then
190+
echo "$buildPfx Generating Source ZIP File..."
191+
generateSourceZip "$tarFile" zipFile
192+
packageFiles+=("$zipFile")
193+
fi
194+
195+
for file in "${packageFiles[@]}"
144196
do
145197
echo "$buildPfx Copying $file to $outDir"
146198
cp "$file" "$outDir/$(basename "$file")"

0 commit comments

Comments
 (0)