Skip to content

Commit

Permalink
Fine tune build script to handle releases where release tags for gnuc…
Browse files Browse the repository at this point in the history
…ash and gnucash-docs differ

For example there can be a gnucash 3.8b tag with a gnucash-docs 3.8 tag.
The way to invoke the script for this is
build-package.sh -r3.8 -c3.8b -d3.8
or even
build-package.sh -r3.8 -c3.8b

The value of -r serves as both
- the default for -c and -d
- the sourceforge directory name containing the tarballs.

So the main constraint for release tarballs now is that the tarballs must live
in the same sourceforge directory.

Notes:
* if the release tag is the same for gnucash, gnucash-docs and the directory
(the ideal case), the command can be simplified even more:
build-package.sh -r3.7
* for development (nightly) builds the directory restriction doesn't apply. For
such builds you are free to use -c, -d and -r as you see fit. -r only serves
as default for -c and -d in that scenario.
  • Loading branch information
gjanssens committed Dec 30, 2019
1 parent 5dce910 commit 1af2580
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 26 deletions.
26 changes: 17 additions & 9 deletions build_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,17 @@ revision=maint
. "$fp_git_dir"/functions.sh

# Parse command line options
while getopts "hr:" o; do
while getopts "hr:c:d:" o; do
case "${o}" in
r)
revision=${OPTARG}
;;
c)
code_revision=${OPTARG}
;;
d)
docs_revision=${OPTARG}
;;
h)
usage
;;
Expand All @@ -51,6 +57,8 @@ while getopts "hr:" o; do
done

is_release="undecided"
code_revision=${code_revision:-${revision}}
docs_revision=${docs_revision:-${revision}}

# Set up logging
local_log_dir="$base_dir/logs"
Expand All @@ -72,7 +80,7 @@ trap cleanup ERR
# Check for new commits in code
package=${code_package}
repodir=${code_repodir}
prepare_repo
prepare_repo ${code_revision}
get_versions

code_curr_rev=${gc_commit}
Expand All @@ -81,22 +89,22 @@ code_full_version=${gc_full_version}
# Check for new commits in docs
package=${docs_package}
repodir=${docs_repodir}
prepare_repo
prepare_repo ${docs_revision}
get_versions

docs_curr_rev=${gc_commit}
docs_full_version=${gc_full_version}

# Simplify flatpak package version if code and docs are on the same full_version
# In practice this only happens when a tag is checked out, so as the code
# is currently written this means it only happens for release builds
if [[ "$code_full_version" == "$docs_full_version" ]]
# Compose the default branch name to use in the flatpak repo
fp_branch="$revision-C$code_full_version-D$docs_full_version"

# Release builds start from tarballs and need checksums for the manifest
if [[ "${is_release}" == "yes" ]]
then
fp_branch="$code_full_version"
build_type=tar
fp_branch="$revision"
get_checksums
else
fp_branch="$revision-C$code_full_version-D$docs_full_version"
build_type=git
fi

Expand Down
70 changes: 57 additions & 13 deletions functions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,48 @@ function cleanup()
function usage()
{
{
echo "Usage: $0 [-r <revision>] [-u <remote>]"
echo "Usage: $0 [-c <revision>] [-d <revision>] [-r <revision>]"
echo " $0 -h"
echo
echo "-h display this help message"
echo
echo "-c revision gnucash git revision to build. Can be a branch or a tag."
echo " Default: whatever is set with -r or 'maint' if -' was not specified"
echo "-d revision gnucash-docs git revision to build. Can be a branch or a tag."
echo " Default: whatever is set with -r or 'maint' if -' was not specified"
echo "-r revision git revision to build. Can be a branch or a tag."
echo " Note this branch or tag should exist in both the gnucash"
echo " and the gnucash-docs repository used for this build."
echo " Can be used in multiple ways: if -c or -d options are omitted"
echo " the value of -r is used as default instead."
echo " If both -c and -d refer to a release tag, the value of -r will be used"
echo " additionally as name of the directory that holds the release tarballs"
echo " on sourceforge. This allows to handle situations where this directory name"
echo " is different from the release tarball versions."
echo " Default: 'maint'"
echo
echo "Examples:"
echo
echo " $0 -r master"
echo
echo " Create a development flatpak for the current master branches of gnucash and gnucash-docs"
echo
echo " $0 -r 3.7"
echo
echo " Create a release flatpak for the gnucash 3.7. This will look for tarballs on sourceforge"
echo " for gnucash 3.7 and gnucash-docs 3.7 in directory 3.7"
echo
echo " $0 -r 3.8 -c3.8b"
echo
echo " Create a release flatpak with tarballs taken from sourceforge"
echo " for gnucash 3.8 and gnucash-docs 3.8b in directory 3.8"
echo
echo "Note:"
echo " If you want to create a release flatpak, you will always want to set at least -r."
echo " That tells the scripts in which sourceforge directory to look for tarballs."
echo " If the tarballs have slightly different version numbers (due to release process internals)"
echo " you can add -c or -d to specify those."
echo " For development builds (that is, from git) you are free to mix and match"
echo " the 3 options as you see fit. In this case -r only serves as a default value"
echo " for the other two."
} 1>&2
exit 1
}
Expand Down Expand Up @@ -72,22 +105,33 @@ function upload_build_log()
fi
}

# Updates repo to repo_rev
# Then checks whether repo_rev is a tag
# If not a tag, reset repo to repo_rev
# Caller should pass repo_rev as first parameter
function prepare_repo()
{
repo_rev=$1
pushd "${repodir}"
echo "Update repository $repodir"
git fetch
git checkout $revision
if git tag | grep -q "^$revision\$"
git checkout $repo_rev
if git tag | grep -q "^$repo_rev\$"
then
echo "Detected a tag (release) build"
is_release="yes"
remote_branch_dir="releases"
if [[ "${is_release}" == "no" ]]
then
echo "However a previously checked repository is not set up for release builds. Falling back to development build."
remote_branch_dir=$repo_rev
else
is_release="yes"
remote_branch_dir="releases"
fi
else
echo "No tag detected, assuming development build"
is_release="no"
remote_branch_dir=$revision
git reset --hard origin/$revision
remote_branch_dir=$repo_rev
git reset --hard origin/$repo_rev
fi
popd
}
Expand All @@ -112,8 +156,8 @@ function get_versions()
function get_checksums()
{
wget "http://downloads.sourceforge.net/gnucash/gnucash (stable)/${revision}/README.txt" -O "${base_dir}"/README.txt
code_checksum=$(awk "/gnucash-${revision}.tar.bz2/ { print \$1;}" "${base_dir}"/README.txt)
docs_checksum=$(awk "/gnucash-docs-${revision}.tar.gz/ { print \$1;}" "${base_dir}"/README.txt)
code_checksum=$(awk "/gnucash-${code_revision}.tar.bz2/ { print \$1;}" "${base_dir}"/README.txt)
docs_checksum=$(awk "/gnucash-docs-${docs_revision}.tar.gz/ { print \$1;}" "${base_dir}"/README.txt)
}

function prepare_gpg()
Expand Down Expand Up @@ -144,7 +188,7 @@ function create_manifest()
echo "Writing org.gnucash.GnuCash.json manifest file"

# Export environment variables used in the templates in order for envsubst to find them
export code_repodir docs_repodir code_checksum docs_checksum revision
export code_repodir docs_repodir code_checksum docs_checksum revision code_revision docs_revision

# In the functions below build_type selects the proper templates to initiate
# a git or a tar build. build_type is determined earlier in build_package.sh
Expand All @@ -157,7 +201,7 @@ function create_manifest()
# Note the variable names passed to envsubst:
# this limits the set of variables envsubst will effectively substitute
# We do this to prevent colisions with flatpak variables in the manifest
gnucash_targets=$(envsubst '$code_repodir $docs_repodir $revision $code_checksum $docs_checksum' \
gnucash_targets=$(envsubst '$code_repodir $docs_repodir $code_revision $docs_revision $revision $code_checksum $docs_checksum' \
< "$fp_git_dir"/templates/gnucash-targets-${build_type}.json.tpl)
fi
export extra_deps gnucash_targets
Expand Down
4 changes: 2 additions & 2 deletions templates/gnucash-targets-git.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
{
"type": "git",
"path": "${code_repodir}",
"branch": "${revision}"
"branch": "${code_revision}"
}
]
},
Expand All @@ -29,7 +29,7 @@
{
"type": "git",
"path": "${docs_repodir}",
"branch": "${revision}"
"branch": "${docs_revision}"
}
]
}
4 changes: 2 additions & 2 deletions templates/gnucash-targets-tar.json.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"sources": [
{
"type": "archive",
"url": "http://downloads.sourceforge.net/gnucash/gnucash (stable)/${revision}/gnucash-${revision}.tar.bz2",
"url": "http://downloads.sourceforge.net/gnucash/gnucash (stable)/${revision}/gnucash-${code_revision}.tar.bz2",
"sha256": "${code_checksum}"
}
]
Expand All @@ -28,7 +28,7 @@
"sources": [
{
"type": "archive",
"url": "http://downloads.sourceforge.net/gnucash/gnucash-docs/gnucash-docs-${revision}.tar.gz",
"url": "http://downloads.sourceforge.net/gnucash/gnucash (stable)/${revision}/gnucash-docs-${docs_revision}.tar.gz",
"sha256": "${docs_checksum}"
}
]
Expand Down

0 comments on commit 1af2580

Please sign in to comment.