Skip to content

Commit

Permalink
build: add ZIP file source distribution
Browse files Browse the repository at this point in the history
  • Loading branch information
rlxdev committed Jan 22, 2025
1 parent 655168b commit 9d43d54
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/run_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ jobs:
files: |
scubagoggles-*-py3-none-any.whl
scubagoggles-*.tar.gz
scubagoggles-*.zip
generate_release_notes: true
fail_on_unmatched_files: true
58 changes: 55 additions & 3 deletions scubagoggles/utils/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ shopt -s expand_aliases
gitTag=
outDir="$PWD"
scubaGogglesGit='[email protected]:cisagov/ScubaGoggles.git'
zipSource=true

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

while getopts ':ho:r:t:' option
while getopts ':ho:r:t:x' option
do
case "$option" in
h)
Expand All @@ -64,6 +66,9 @@ do
t)
gitTag=$OPTARG
;;
x)
zipSource=false
;;
?)
usage
exit 1
Expand All @@ -78,14 +83,52 @@ shift $((OPTIND -1))
# Used to distinguish output from this script.
buildPfx='{build>>>}'

cleanup() {
cleanup()
{
echo "$buildPfx Performing build cleanup..."
[[ $(type -t deactivate) == function ]] && deactivate
[[ "${DIRSTACK[0]}" == "$scubaGoggles" ]] && popd
rm -rf "$scubaEnv"
rm -rf "$scubaGoggles"
}

generateSourceZip()
{
# Generates a ZIP file version of the source code distribution, which is
# in gzipped tar format (.tar.gz). There are 2 parameters to this function:
#
# generateSourceZip <gz-tar-file> <out-var-name>
#
# where <gz-tar-file> is an existing source distribution (the file must
# end with ".tar.gz" (not ".tgz")), and <out-var-name> is the name of the
# variable where the output file name will be written. The ZIP source
# code file will be created in the same location as the given tar file.
#
# Python's PEP 517 has restricted the source distributions built by
# backends to be gzipped tar files only.
#
# This work is done in a temporary directory, which is removed provided
# that no errors occur during the creation of the ZIP file.

local gztarFile
local sourceTemp
local -n outFile=$2

gztarFile=$1
sourceTemp=$(mktemp -d -t scubagoggles_src.XXXXXXXXXX)
outFile=$(realpath "${gztarFile/tar.gz/zip}")

tar xfz "$gztarFile" -C "$sourceTemp"

pushd "$sourceTemp"

zip -qr "$outFile" .

popd

rm -rf "$sourceTemp"
}

pushd() { builtin pushd "$@" > /dev/null; }

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

for file in "$wheelFile" "$tarFile"
packageFiles=("$wheelFile" "$tarFile")

if [ "$zipSource" == true ]
then
echo "$buildPfx Generating Source ZIP File..."
generateSourceZip "$tarFile" zipFile
packageFiles+=("$zipFile")
fi

for file in "${packageFiles[@]}"
do
echo "$buildPfx Copying $file to $outDir"
cp "$file" "$outDir/$(basename "$file")"
Expand Down

0 comments on commit 9d43d54

Please sign in to comment.