-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Require at least 1 of Github/Sourceforge. Ref: #10 Signed-off-by: Aaron Armstrong Skomra <[email protected]> Reviewed-by: Ping Cheng <[email protected]> Reviewed-by: Jason Gerecke <[email protected]>
- Loading branch information
Showing
1 changed file
with
207 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,14 @@ | |
|
||
export LC_ALL=C | ||
|
||
#------------------------------------------------------------------------------ | ||
# Function: check_for_jq | ||
#------------------------------------------------------------------------------ | ||
# | ||
check_for_jq() { | ||
command -v jq >/dev/null 2>&1 || { echo >&2 "This script requires jq but it is not installed. Exiting."; exit 1;} | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# Function: check_local_changes | ||
#------------------------------------------------------------------------------ | ||
|
@@ -88,12 +96,161 @@ fi | |
|
||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# Function: release_to_sourceforge | ||
#------------------------------------------------------------------------------ | ||
# | ||
release_to_sourceforge () { | ||
|
||
# Some hostnames are also used as /srv subdirs | ||
host_linuxwacom="shell.sourceforge.net" | ||
|
||
section_path=archive/individual/$section | ||
srv_path="/srv/$host_current/$section_path" | ||
|
||
if [ x"$section" = xxf86-input-wacom ] || | ||
[ x"$section" = xinput-wacom ] || | ||
[ x"$section" = xlibwacom ]; then | ||
# input-wacom files are in a subdirectory for whatever reason | ||
if [ x"$section" = xinput-wacom ]; then | ||
section="xf86-input-wacom/input-wacom" | ||
fi | ||
|
||
hostname=$host_linuxwacom | ||
host_current="sourceforge.net" | ||
section_path="projects/linuxwacom/files/$section" | ||
srv_path="/home/frs/project/linuxwacom/$section" | ||
|
||
echo "creating shell on sourceforge for $SF_USERNAME" | ||
ssh ${SF_USERNAME%@},linuxwacom@$hostname create | ||
#echo "Simply log out once you get to the prompt" | ||
#ssh -t ${SF_USERNAME%@},linuxwacom@$hostname create | ||
#echo "Sleeping for 30 seconds, because this sometimes helps against sourceforge's random authentication denials" | ||
#sleep 30 | ||
fi | ||
|
||
# Use personal web space on the host for unit testing (leave commented out) | ||
# srv_path="~/public_html$srv_path" | ||
|
||
# Check that the server path actually does exist | ||
ssh $SF_USERNAME$hostname ls $srv_path >/dev/null 2>&1 || | ||
if [ $? -ne 0 ]; then | ||
echo "Error: the path \"$srv_path\" on the web server does not exist." | ||
cd $top_src | ||
return 1 | ||
fi | ||
|
||
# Check for already existing tarballs | ||
for tarball in $targz $tarbz2 $tarxz; do | ||
ssh $SF_USERNAME$hostname ls $srv_path/$tarball >/dev/null 2>&1 | ||
if [ $? -eq 0 ]; then | ||
if [ "x$FORCE" = "xyes" ]; then | ||
echo "Warning: overwriting released tarballs due to --force option." | ||
else | ||
echo "Error: tarball $tar_name already exists. Use --force to overwrite." | ||
cd $top_src | ||
return 1 | ||
fi | ||
fi | ||
done | ||
|
||
# Upload to host using the 'scp' remote file copy program | ||
if [ x"$DRY_RUN" = x ]; then | ||
echo "Info: uploading tarballs to web server:" | ||
scp $targz $tarbz2 $tarxz $siggz $sigbz2 $sigxz $SF_USERNAME$hostname:$srv_path | ||
if [ $? -ne 0 ]; then | ||
echo "Error: the tarballs uploading failed." | ||
cd $top_src | ||
return 1 | ||
fi | ||
else | ||
echo "Info: skipping tarballs uploading in dry-run mode." | ||
echo " \"$srv_path\"." | ||
fi | ||
|
||
host_current="sourceforge.net" | ||
section_path="projects/linuxwacom/files/$section" | ||
# DL_URL & PGP_URL will be overwritten by the Github download url if github was | ||
# enabled on the command line | ||
DL_URL="http://$host_current/$section_path/$tarbz2" | ||
PGP_URL="http://$host_current/$section_path/$tarbz2.sig" | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# Function: check_json_message | ||
#------------------------------------------------------------------------------ | ||
# | ||
# if we get json with a "message" from github there was an error | ||
# $1 the JSON to parse | ||
check_json_message() { | ||
|
||
message=`echo $1 | jq ".message"` | ||
if [ "$message" != "null" ] ; then | ||
echo "Github release error: $1" | ||
exit 1 | ||
fi | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# Function: release_to_github | ||
#------------------------------------------------------------------------------ | ||
# | ||
release_to_github() { | ||
# Creating a release on Github automatically creates a tag. | ||
|
||
# dependency 'jq' for reading the json github sends us back | ||
|
||
# note git_username should include the suffix ":KEY" if the user has enabled 2FA | ||
# example skomra:de0e4dc3efbf2d008053027708227b365b7f80bf | ||
|
||
GH_REPO="linuxwacom" | ||
PROJECT="xf86-input-wacom" | ||
release_description="Temporary Empty Release Description" | ||
release_descr=$(jq -n --arg release_description "$release_description" '$release_description') | ||
|
||
# Create a Release | ||
api_json=$(printf '{"tag_name": "%s", | ||
"target_commitish": "master", | ||
"name": "%s", | ||
"body": %s, | ||
"draft": false, | ||
"prerelease": false}' "$tar_name" "$tar_name" "$release_descr") | ||
create_result=`curl -s --data "$api_json" -u $GH_USERNAME https://api.github.com/repos/$GH_REPO/$PROJECT/releases` | ||
GH_RELEASE_ID=`echo $create_result | jq '.id'` | ||
|
||
check_json_message "$create_result" | ||
|
||
# Upload the tar to the release | ||
upload_result=`curl -s -u $GH_USERNAME \ | ||
-H "Content-Type: application/x-bzip" \ | ||
--data-binary @$tarbz2 \ | ||
"https://uploads.github.com/repos/$GH_REPO/$PROJECT/releases/$GH_RELEASE_ID/assets?name=$tarbz2"` | ||
DL_URL=`echo $upload_result | jq -r '.browser_download_url'` | ||
|
||
check_json_message "$upload_result" | ||
|
||
# Upload the sig to the release | ||
sig_result=`curl -s -u $GH_USERNAME \ | ||
-H "Content-Type: application/pgp-signature" \ | ||
--data-binary @$tarbz2.sig \ | ||
"https://uploads.github.com/repos/$GH_REPO/$PROJECT/releases/$GH_RELEASE_ID/assets?name=$tarbz2.sig"` | ||
PGP_URL=`echo $sig_result | jq -r '.browser_download_url'` | ||
|
||
check_json_message "$sig_result" | ||
|
||
echo "Github release created" | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
# Function: generate_announce | ||
#------------------------------------------------------------------------------ | ||
# | ||
generate_announce() | ||
{ | ||
MD5SUM=`which md5sum || which gmd5sum` | ||
SHA1SUM=`which sha1sum || which gsha1sum` | ||
SHA256SUM=`which sha256sum || which gsha256sum` | ||
|
||
cat <<RELEASE | ||
Subject: [ANNOUNCE] $pkg_name $pkg_version | ||
To: $list_to | ||
|
@@ -105,16 +262,14 @@ git tag: $tag_name | |
RELEASE | ||
|
||
for tarball in $tarbz2 $targz $tarxz; do | ||
cat <<RELEASE | ||
http://$host_current/$section_path/$tarball | ||
$DL_URL | ||
MD5: `$MD5SUM $tarball` | ||
SHA1: `$SHA1SUM $tarball` | ||
SHA256: `$SHA256SUM $tarball` | ||
PGP: http://${host_current}/${section_path}/${tarball}.sig | ||
PGP: $PGP_URL | ||
RELEASE | ||
done | ||
} | ||
|
||
#------------------------------------------------------------------------------ | ||
|
@@ -474,76 +629,6 @@ process_module() { | |
fi | ||
fi | ||
|
||
# --------- Now the tarballs are ready to upload ---------- | ||
|
||
# Some hostnames are also used as /srv subdirs | ||
host_linuxwacom="shell.sourceforge.net" | ||
|
||
section_path=archive/individual/$section | ||
srv_path="/srv/$host_current/$section_path" | ||
|
||
if [ x"$section" = xxf86-input-wacom ] || | ||
[ x"$section" = xinput-wacom ] || | ||
[ x"$section" = xlibwacom ]; then | ||
# input-wacom files are in a subdirectory for whatever reason | ||
if [ x"$section" = xinput-wacom ]; then | ||
section="xf86-input-wacom/input-wacom" | ||
fi | ||
|
||
hostname=$host_linuxwacom | ||
host_current="sourceforge.net" | ||
section_path="projects/linuxwacom/files/$section" | ||
srv_path="/home/frs/project/linuxwacom/$section" | ||
list_to="[email protected]" | ||
list_cc="[email protected]" | ||
|
||
echo "creating shell on sourceforge for $USER" | ||
ssh -t ${USER_NAME%@},linuxwacom@$hostname create | ||
#echo "Simply log out once you get to the prompt" | ||
#ssh -t ${USER_NAME%@},linuxwacom@$hostname create | ||
#echo "Sleeping for 30 seconds, because this sometimes helps against sourceforge's random authentication denials" | ||
#sleep 30 | ||
fi | ||
|
||
# Use personal web space on the host for unit testing (leave commented out) | ||
# srv_path="~/public_html$srv_path" | ||
|
||
# Check that the server path actually does exist | ||
ssh $USER_NAME$hostname ls $srv_path >/dev/null 2>&1 || | ||
if [ $? -ne 0 ]; then | ||
echo "Error: the path \"$srv_path\" on the web server does not exist." | ||
cd $top_src | ||
return 1 | ||
fi | ||
|
||
# Check for already existing tarballs | ||
for tarball in $targz $tarbz2 $tarxz; do | ||
ssh $USER_NAME$hostname ls $srv_path/$tarball >/dev/null 2>&1 | ||
if [ $? -eq 0 ]; then | ||
if [ "x$FORCE" = "xyes" ]; then | ||
echo "Warning: overwriting released tarballs due to --force option." | ||
else | ||
echo "Error: tarball $tar_name already exists. Use --force to overwrite." | ||
cd $top_src | ||
return 1 | ||
fi | ||
fi | ||
done | ||
|
||
# Upload to host using the 'scp' remote file copy program | ||
if [ x"$DRY_RUN" = x ]; then | ||
echo "Info: uploading tarballs to web server:" | ||
scp $targz $tarbz2 $tarxz $siggz $sigbz2 $sigxz $USER_NAME$hostname:$srv_path | ||
if [ $? -ne 0 ]; then | ||
echo "Error: the tarballs uploading failed." | ||
cd $top_src | ||
return 1 | ||
fi | ||
else | ||
echo "Info: skipping tarballs uploading in dry-run mode." | ||
echo " \"$srv_path\"." | ||
fi | ||
|
||
# Pushing the top commit tag to the remote repository | ||
if [ x$DRY_RUN = x ]; then | ||
echo "Info: pushing tag \"$tag_name\" to remote \"$remote_name\":" | ||
|
@@ -558,13 +643,20 @@ process_module() { | |
echo "Info: skipped pushing tag \"$tag_name\" to the remote repository in dry-run mode." | ||
fi | ||
|
||
MD5SUM=`which md5sum || which gmd5sum` | ||
SHA1SUM=`which sha1sum || which gsha1sum` | ||
SHA256SUM=`which sha256sum || which gsha256sum` | ||
if [ -n "$SF_USERNAME" ]; then | ||
release_to_sourceforge | ||
fi | ||
|
||
if [ -n "$GH_USERNAME" ]; then | ||
release_to_github | ||
fi | ||
|
||
# --------- Generate the announce e-mail ------------------ | ||
# Failing to generate the announce is not considered a fatal error | ||
|
||
list_to="[email protected]" | ||
list_cc="[email protected]" | ||
|
||
# Git-describe returns only "the most recent tag", it may not be the expected one | ||
# However, we only use it for the commit history which will be the same anyway. | ||
tag_previous=`git describe --abbrev=0 HEAD^ 2>/dev/null` | ||
|
@@ -584,7 +676,26 @@ process_module() { | |
fi | ||
generate_announce > "$tar_name.announce" | ||
echo "Info: [ANNOUNCE] template generated in \"$tar_name.announce\" file." | ||
echo " Please pgp sign and send it." | ||
echo " Please edit the .announce file to add a description of what's interesting and then" | ||
echo " pgp sign and send it." | ||
|
||
# --------- Update the "body" text of the Github release with the .announce file ----------------- | ||
|
||
if [ -n "$GH_RELEASE_ID" ]; then | ||
# Read the announce email and then escape it as a string in order to add it to the JSON | ||
read -r -d '' release_description <"$tar_name.announce" | ||
release_descr=$(jq -n --arg release_description "$release_description" '$release_description') | ||
api_json=$(printf '{"tag_name": "%s", | ||
"target_commitish": "master", | ||
"name": "%s", | ||
"body": %s, | ||
"draft": false, | ||
"prerelease": false}' "$tar_name" "$tar_name" "$release_descr") | ||
create_result=`curl -s -X PATCH --data "$api_json" -u $GH_USERNAME https://api.github.com/repos/$GH_REPO/$PROJECT/releases/$GH_RELEASE_ID` | ||
|
||
check_json_message "$create_result" | ||
echo "Git shortlog posted to the release at Github, please edit the release to add a description of what's interesting." | ||
fi | ||
|
||
# --------- Successful completion -------------------------- | ||
cd $top_src | ||
|
@@ -631,6 +742,9 @@ HELP | |
# Choose which make program to use (could be gmake) | ||
MAKE=${MAKE:="make"} | ||
|
||
# Check if the json parser 'jq' is installed | ||
check_for_jq | ||
|
||
# Choose which grep program to use (on Solaris, must be gnu grep) | ||
if [ "x$GREP" = "x" ] ; then | ||
if [ -x /usr/gnu/bin/grep ] ; then | ||
|
@@ -696,11 +810,18 @@ do | |
--no-quit) | ||
NO_QUIT=yes | ||
;; | ||
# Username of your fdo account if not configured in ssh | ||
--user) | ||
# Github username. Optional. Append colon and Personali | ||
# Access Token to username if 2FA is enabled on the user | ||
# account doing the release | ||
--github) | ||
GH_USERNAME=$2 | ||
shift | ||
;; | ||
# Sourceforge username. Optional. | ||
--sourceforge) | ||
check_option_args $1 $2 | ||
shift | ||
USER_NAME=$1 | ||
SF_USERNAME=$1 | ||
;; | ||
--*) | ||
echo "" | ||
|
@@ -731,6 +852,11 @@ do | |
shift | ||
done | ||
|
||
if [[ x$GH_USERNAME = "x" ]] && [[ x$SF_USERNAME = "x" ]] ; then | ||
echo "At least one of --github or --sourceforge option required"; | ||
exit 1; | ||
fi | ||
|
||
# If no modules specified (blank cmd line) display help | ||
check_modules_specification | ||
|
||
|