Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build/Release: Add ZIP Source File Distribution #574

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='git@github.com: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