2019-11-16 14:46:52 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#set -x
|
|
|
|
# Use this variable to indicate a list of branches that docker hub is watching
|
2021-03-06 22:53:46 +00:00
|
|
|
branches_list=(
|
|
|
|
'java8'
|
|
|
|
'java8-multiarch'
|
2021-05-22 03:34:45 +00:00
|
|
|
'java8-openj9'
|
2021-05-21 22:32:38 +00:00
|
|
|
'java11'
|
2021-05-22 03:40:29 +00:00
|
|
|
'java11-openj9'
|
2021-10-20 02:36:31 +00:00
|
|
|
'java17'
|
2022-01-23 16:57:31 +00:00
|
|
|
'java17-openj9'
|
2021-03-06 22:53:46 +00:00
|
|
|
)
|
2019-11-16 14:46:52 +00:00
|
|
|
|
|
|
|
function TrapExit {
|
2020-03-27 01:53:10 +00:00
|
|
|
echo "Checking out back in master"
|
2019-11-16 14:46:52 +00:00
|
|
|
git checkout master
|
|
|
|
}
|
|
|
|
|
2019-11-16 15:30:06 +00:00
|
|
|
batchMode=false
|
|
|
|
|
2021-06-24 03:29:24 +00:00
|
|
|
while getopts "hbt:s" arg
|
2019-11-16 15:30:06 +00:00
|
|
|
do
|
|
|
|
case $arg in
|
|
|
|
b)
|
|
|
|
batchMode=true
|
|
|
|
;;
|
2020-06-19 16:31:41 +00:00
|
|
|
t)
|
|
|
|
tag=${OPTARG}
|
|
|
|
;;
|
2020-06-20 20:42:45 +00:00
|
|
|
s)
|
|
|
|
tagArgs="-s -m 'Signed during docker-versions-create"
|
|
|
|
;;
|
2020-06-19 16:31:41 +00:00
|
|
|
h)
|
|
|
|
echo "
|
|
|
|
Usage $0 [options]
|
|
|
|
|
|
|
|
Options:
|
|
|
|
-b enable batch mode, which avoids interactive prompts and causes script to fail immediately
|
|
|
|
when any merge fails
|
|
|
|
-t TAG tag and push the current revision on master with the given tag
|
|
|
|
and apply respective tags to each branch
|
2020-06-20 20:42:45 +00:00
|
|
|
-s enable signed tags
|
2020-06-19 16:31:41 +00:00
|
|
|
-h display this help and exit
|
|
|
|
"
|
|
|
|
exit
|
|
|
|
;;
|
2019-11-16 15:30:06 +00:00
|
|
|
*)
|
2020-03-27 01:53:10 +00:00
|
|
|
echo "Unsupported arg $arg"
|
2019-11-16 15:30:06 +00:00
|
|
|
exit 2
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2020-03-27 01:53:10 +00:00
|
|
|
${batchMode} && echo "Using batch mode"
|
2019-11-16 15:30:06 +00:00
|
|
|
|
2019-11-16 14:46:52 +00:00
|
|
|
trap TrapExit EXIT SIGTERM
|
|
|
|
|
2020-03-27 01:53:10 +00:00
|
|
|
test -d ./.git || { echo ".git folder was not found. Please start this script from root directory of the project!";
|
2019-11-16 14:46:52 +00:00
|
|
|
exit 1; }
|
|
|
|
|
|
|
|
# Making sure we are in master
|
|
|
|
git checkout master
|
2020-03-27 01:53:10 +00:00
|
|
|
git pull --all || { echo "Can't pull the repo!"; \
|
2019-11-16 14:46:52 +00:00
|
|
|
exit 1; }
|
2020-06-19 16:31:41 +00:00
|
|
|
if [[ $tag ]]; then
|
|
|
|
git tag $tag
|
|
|
|
git push origin $tag
|
|
|
|
fi
|
2019-11-16 14:46:52 +00:00
|
|
|
|
|
|
|
git_branches=$(git branch -a)
|
|
|
|
|
|
|
|
for branch in "${branches_list[@]}"; do
|
|
|
|
if [[ "$git_branches" != *"$branch"* ]]; then
|
2020-03-27 01:53:10 +00:00
|
|
|
echo "Can't update $branch because I can't find it in the list of branches."
|
2019-11-16 14:46:52 +00:00
|
|
|
exit 1
|
|
|
|
else
|
2020-03-27 01:53:10 +00:00
|
|
|
echo "Branch $branch found. Working with it."
|
|
|
|
git checkout "$branch" || { echo "Can't checkout into the branch. Don't know the cause."; \
|
2019-11-16 14:46:52 +00:00
|
|
|
exit 1; }
|
|
|
|
proceed='False'
|
|
|
|
while [[ "$proceed" == "False" ]]; do
|
2020-02-01 14:52:00 +00:00
|
|
|
# Ensure local branch is aligned with remote since docker-versions-create may have been run elsewhere
|
|
|
|
git pull
|
|
|
|
|
2019-11-16 15:04:03 +00:00
|
|
|
if git merge -m 'Auto-merging via docker-versions-create' master; then
|
2019-11-16 14:46:52 +00:00
|
|
|
proceed="True"
|
2020-03-27 01:53:10 +00:00
|
|
|
echo "Branch $branch updated to current master successfully"
|
2019-11-16 14:46:52 +00:00
|
|
|
# pushing changes to remote for this branch
|
|
|
|
git commit -m "Auto merge branch with master" -a
|
|
|
|
# push may fail if remote doesn't have this branch yet. In this case - sending branch
|
2020-03-27 01:53:10 +00:00
|
|
|
git push || git push -u origin "$branch" || { echo "Can't push changes to the origin."; exit 1; }
|
2020-06-19 16:31:41 +00:00
|
|
|
if [[ $tag ]]; then
|
|
|
|
git tag "$tag-$branch"
|
|
|
|
git push origin "$tag-$branch"
|
|
|
|
fi
|
2019-11-16 15:30:06 +00:00
|
|
|
elif ${batchMode}; then
|
|
|
|
status=$?
|
2020-03-27 01:53:10 +00:00
|
|
|
echo "Git merge failed in batch mode"
|
2019-11-16 15:30:06 +00:00
|
|
|
exit ${status}
|
|
|
|
# and trap exit gets us back to master
|
2019-11-16 14:46:52 +00:00
|
|
|
else
|
|
|
|
cat<<EOL
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
Master merge in the branch $branch encountered an error!
|
|
|
|
You may try to fix the error and merge again. (Commit changes)
|
|
|
|
Or skip this branch merge completely.
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
EOL
|
|
|
|
printf "Should we try again? (y):"
|
2019-11-16 15:29:48 +00:00
|
|
|
read -r answer
|
2019-11-16 14:46:52 +00:00
|
|
|
if [[ "$answer" == '' ]] || [[ "$answer" == 'y' ]] || [[ "$answer" == 'Y' ]]; then
|
|
|
|
# If you use non-local editor or files are changed in repo
|
|
|
|
cat <<EOL
|
|
|
|
|
|
|
|
The following commands may encounter an error!
|
|
|
|
This is completely fine if the changes were made locally and remote branch doesn't know about them.
|
|
|
|
|
|
|
|
EOL
|
|
|
|
# Updating branch from remote before trying again
|
|
|
|
git checkout master
|
|
|
|
git fetch --all
|
|
|
|
git pull -a
|
|
|
|
git checkout "$branch"
|
|
|
|
continue
|
|
|
|
else
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
done
|
2021-12-11 22:51:01 +00:00
|
|
|
|
|
|
|
if [[ $tag ]]; then
|
|
|
|
if [ -f "$HOME/.github.env" ]; then
|
|
|
|
source "$HOME/.github.env"
|
|
|
|
if [[ $GITHUB_TOKEN ]]
|
|
|
|
then
|
|
|
|
auth=(-u ":$GITHUB_TOKEN")
|
|
|
|
base=https://api.github.com
|
|
|
|
: "${owner:=itzg}"
|
|
|
|
: "${repo:=docker-minecraft-server}"
|
|
|
|
read -r -d '' releaseBody << EOF
|
|
|
|
{
|
|
|
|
"tag_name": "$tag",
|
|
|
|
"name": "$tag",
|
|
|
|
"generate_release_notes": true
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
if ! curl "${auth[@]}" -H "Accept: application/vnd.github.v3+json" \
|
|
|
|
"${base}/repos/${owner}/${repo}/releases" -d "$releaseBody"; then
|
|
|
|
echo "ERROR failed to create github release $tag"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|