1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
#!/usr/bin/env bash
set -eu
usage()
{
cat - <<- END
${0} -k <Debian signing key> [-n] [--push]
Create source package for latest stable or beta release and upload to Debian,
and update (and optionally push) changelog file.
-k <key> The PGP key used to sign the source package
-n Simulate upload
--push Push changelog changes to GitHub
--beta Deploy beta release. Default: latest stable release.
--stable Deploy latest stable release.
--debian-revision <revision>
The debian revision to use. Default: 1
--help Display usage help
Requires an entry in ~/.dput.cf:
[mentors]
fqdn = mentors.debian.net
incoming = /upload
method = https
allow_unsigned_uploads = 0
progress_indicator = 2
allowed_distributions = .*
END
}
## START STANDARD BUILD SCRIPT INCLUDE
# adjust relative paths as necessary
THIS_SCRIPT="$(readlink -f "${BASH_SOURCE[0]}")"
. "${THIS_SCRIPT%/*}/../../resources/build/build-utils.sh"
## END STANDARD BUILD SCRIPT INCLUDE
. "$KEYMAN_ROOT/resources/shellHelperFunctions.sh"
NOOP=
PUSH=
DEBKEYID=
REVISION=1
IS_BETA=false
while (( $# )); do
case $1 in
-k) shift
if [[ ! $# -eq 0 ]]; then
DEBKEYID=$1
else
builder_die "Error: The -k argument is missing a value. Exiting."
fi;;
-n) NOOP=: ;;
--help) usage ; exit 0 ;;
--push) PUSH=1 ;;
--beta) IS_BETA=true ;;
--stable) IS_BETA=false ;;
--debian-revision)
shift
if [[ ! $# -eq 0 ]]; then
REVISION=$1
else
builder_die "Error: The --debian-revision argument is missing a value. Exiting."
fi;;
*) builder_die "Error: Unexpected argument \"$1\". Exiting." ;;
esac
shift || builder_die "Error: The last argument is missing a value. Exiting."
done
if [[ -z ${DEBKEYID} ]]; then
usage
exit 2
fi
if ! git diff --quiet; then
builder_die "You have changed files in your git working directory. Exiting."
fi
function get_latest_stable_branch_name() {
# Get the list of stable branches and take the one with the highest number.
# Extract `origin/stable-16.0` from ` origin/stable-16.0`
local branches stable_branch
branches=$(git branch -r | grep origin/stable-)
stable_branch=$(echo "${branches}" | sort | tail -1)
if [[ -z ${stable_branch} ]]; then
builder_die "Can't find stable-* branch" > /dev/stderr
exit 2
fi
echo "${stable_branch##* }"
}
# Push the changelog changes to GitHub and create a PR. Returns the PR#
# in the environment variable PR_NUMBER.
function push_to_github_and_create_pr() {
local BRANCH=$1 # `chore/linux/changelog` or `chore/linux/cherry-pick/changelog`
local BASE=$2 # stable branch, `beta` or `master`
local PR_TITLE=$3 # `Update debian changelog`
local PR_BODY=$4 # `@keymanapp-test-bot skip`
if [[ -n "${PUSH}" ]]; then
# Push to origin. We force push to reset the branch the commit we just made.
# There shouldn't be any other commits on ${BRANCH} except the one we want to replace
# (if any).
${NOOP} git push --force origin "${BRANCH}"
PR_NUMBER=$(gh pr list --draft --search "${PR_TITLE}" --base "${BASE}" --json number --jq '.[].number')
if [[ -n ${PR_NUMBER} ]]; then
builder_echo "PR #${PR_NUMBER} already exists"
else
local PR_URL
PR_URL=$(gh pr create --draft --base "${BASE}" --title "${PR_TITLE}" --body "${PR_BODY}")
PR_NUMBER="${PR_URL##*/}"
fi
else
PR_NUMBER=""
fi
}
function cleanup_worktree() {
if [[ -d "${WORKTREE_DIR}/linux/debianpackage" ]]; then
cp -r "${WORKTREE_DIR}/linux/debianpackage" "${KEYMAN_ROOT}/linux"
fi
cd "${PREV_DIR}"
if [[ -n "${WORKTREE_DIR}" ]] && [[ -d "${WORKTREE_DIR}" ]]; then
builder_echo "Removing temporary worktree"
git worktree remove -f "${WORKTREE_DIR}"
git branch -D "${WORKTREE_BRANCH}"
fi
local TEMP_DIR
TEMP_DIR=$(dirname "${WORKTREE_DIR}")
rm -rf "${TEMP_DIR}"
}
builder_heading "Fetching latest changes"
git fetch -p origin
if ${IS_BETA}; then
ORIGIN_DEPLOY_BRANCH=origin/beta
else
# shellcheck disable=2311
ORIGIN_DEPLOY_BRANCH=$(get_latest_stable_branch_name)
fi
DEPLOY_BRANCH="${ORIGIN_DEPLOY_BRANCH#origin/}"
BRANCH_BASENAME="tmp-packaging-${DEPLOY_BRANCH}"
WORKTREE_BRANCH="maint/linux/${BRANCH_BASENAME}"
PREV_DIR="${PWD}"
# cleanup any residues of previous runs
WORKTREE_DIR="$(git worktree list --porcelain | awk -v name="${BRANCH_BASENAME}" \
'$1 == "worktree" && $2 ~ name { print $2 }')"
if [[ -n "${WORKTREE_DIR}" ]] && [[ -d "${WORKTREE_DIR}" ]]; then
git worktree remove -f "${WORKTREE_DIR}"
fi
if git branch | grep -q "${WORKTREE_BRANCH}"; then
git branch -D "${WORKTREE_BRANCH}"
fi
# Create a temporary worktree so that we start with a clean copy of the
# target branch (stable/beta). Checkout stable/beta branch so that
# scripts/debian.sh picks up correct version
WORKTREE_DIR="$(mktemp -d)/${BRANCH_BASENAME}"
builder_heading "Creating temporary worktree at ${WORKTREE_DIR}"
git worktree add -f -b "${WORKTREE_BRANCH}" "${WORKTREE_DIR}" "${DEPLOY_BRANCH}"
cd "${WORKTREE_DIR}"
trap cleanup_worktree EXIT
git pull origin "${DEPLOY_BRANCH}"
builder_heading "Building source package"
cd "${WORKTREE_DIR}/linux"
DIST=unstable DEBREVISION=${REVISION} scripts/debian.sh
cd debianpackage/
builder_heading "Signing source package"
debsign -k"${DEBKEYID}" --re-sign ./*.changes
builder_heading "Uploading packages to mentors.debian.net"
${NOOP} dput mentors ./*.changes
cd ..
builder_heading "Updating changelog"
# base changelog branch on remote stable/beta branch
git checkout -B chore/linux/changelog "${ORIGIN_DEPLOY_BRANCH}"
cp debianpackage/keyman-*/debian/changelog debian/
git add debian/changelog
COMMIT_MESSAGE="chore(linux): Update debian changelog"
git commit -m "${COMMIT_MESSAGE}"
push_to_github_and_create_pr chore/linux/changelog "${DEPLOY_BRANCH#origin/}" "${COMMIT_MESSAGE} 🏠" "Build-bot: skip
Test-bot: skip"
# Create cherry-pick on master branch
git checkout -B chore/linux/cherry-pick/changelog origin/master
git cherry-pick -x chore/linux/changelog
push_to_github_and_create_pr chore/linux/cherry-pick/changelog master "${COMMIT_MESSAGE} 🍒" \
"Cherry-pick-of: #${PR_NUMBER}
Build-bot: skip
Test-bot: skip"
builder_heading "Finishing"
cleanup_worktree
|