]*>/[url="\1"]/g' -e 's/<\/a>/\[\/url]/g' \
-e 's/
]*>/[img]\1[\/img]/g' \
-e 's/<\(\/\)\?blockquote>/[\1quote]\n/g' \
-e 's//[code]\n/g' -e 's/<\/code><\/pre>/[\/code]\n/g' \
-e 's//[font="monospace"]/g' -e 's/<\/code>/[\/font]/g' \
-e 's/<\/p>/\n/g' \
-e 's/<[^>]\+>//g' \
-e 's/"/"/g' \
-e 's/&/&/g' \
-e 's/<//g' \
-e "s/'/'/g" \
| line_ending_filter > "$wowi_changelog"
# extra conversion for discount markdown
# -e 's/&\(ld\|rd\)quo;/"/g' \
# -e "s/&\(ls\|rs\)quo;/'/g" \
# -e 's/–/--/g' \
# -e 's/…/.../g' \
# -e 's/^[ \t]*//g' \
fi
fi
if [ ! -f "$topdir/$changelog" -a ! -f "$topdir/CHANGELOG.txt" -a ! -f "$topdir/CHANGELOG.md" ]; then
if [ -n "$manual_changelog" ]; then
echo "Warning! Could not find a manual changelog at $topdir/$changelog"
manual_changelog=
changelog="CHANGELOG.md"
changelog_markup="markdown"
fi
echo "Generating changelog of commits into $changelog"
if [ "$repository_type" = "git" ]; then
changelog_url=
changelog_version=
changelog_url_wowi=
changelog_version_wowi=
_changelog_range=
if [ -z "$previous_version" -a -z "$tag" ]; then
# no range, show all commits up to ours
changelog_url="[Full Changelog](${githost_url}/commits/$project_hash)"
changelog_version="[$project_version](${githost_url}/tree/$project_hash)"
changelog_url_wowi="[url=${githost_url}/commits/$project_hash]Full Changelog[/url]"
changelog_version_wowi="[url=${githost_url}/tree/$project_hash]$project_version[/url]"
_changelog_range="$project_hash"
elif [ -z "$previous_version" -a -n "$tag" ]; then
# first tag, show all commits upto it
changelog_url="[Full Changelog](${githost_url}/commits/$tag)"
changelog_version="[$project_version](${githost_url}/tree/$tag)"
changelog_url_wowi="[url=${githost_url}/commits/$tag]Full Changelog[/url]"
changelog_version_wowi="[url=${githost_url}/tree/$tag]$project_version[/url]"
_changelog_range="$tag"
elif [ -n "$previous_version" -a -z "$tag" ]; then
# compare between last tag and our commit
changelog_url="[Full Changelog](${githost_url}/compare/$previous_version...$project_hash)"
changelog_version="[$project_version](${githost_url}/tree/$project_hash)"
changelog_url_wowi="[url=${githost_url}/compare/$previous_version...$project_hash]Full Changelog[/url]"
changelog_version_wowi="[url=${githost_url}/tree/$project_hash]$project_version[/url]"
_changelog_range="$previous_version..$project_hash"
elif [ -n "$previous_version" -a -n "$tag" ]; then
# compare between last tag and our tag
changelog_url="[Full Changelog](${githost_url}/compare/$previous_version...$tag)"
changelog_version="[$project_version](${githost_url}/tree/$tag)"
changelog_url_wowi="[url=${githost_url}/compare/$previous_version...$tag]Full Changelog[/url]"
changelog_version_wowi="[url=${githost_url}/tree/$tag]$project_version[/url]"
_changelog_range="$previous_version..$tag"
fi
# lazy way out
if [ -z "$githost_url" ]; then
changelog_url=
changelog_version=$project_version
changelog_url_wowi=
changelog_version_wowi="[color=orange]$project_version[/color]"
fi
changelog_date=$( TZ= printf "%(%Y-%m-%d)T" "$project_timestamp" )
cat <<- EOF | line_ending_filter > "$pkgdir/$changelog"
# $project
## $changelog_version ($changelog_date)
$changelog_url
EOF
git -C "$topdir" log $_changelog_range --pretty=format:"###%B" \
| sed -e 's/^/ /g' -e 's/^ *$//g' -e 's/^ ###/- /g' -e 's/$/ /' \
-e 's/\([a-zA-Z0-9]\)_\([a-zA-Z0-9]\)/\1\\_\2/g' \
-e 's/\[ci skip\]//g' -e 's/\[skip ci\]//g' \
-e '/git-svn-id:/d' -e '/^\s*This reverts commit [0-9a-f]\{40\}\.\s*$/d' \
-e '/^\s*$/d' \
| line_ending_filter >> "$pkgdir/$changelog"
# WoWI uses BBCode, generate something usable to post to the site
# the file is deleted on successful upload
if [ -n "$addonid" -a -n "$tag" -a -n "$wowi_gen_changelog" ]; then
changelog_previous_wowi=
if [ -n "$githost_url" -a -n "$githost_token" ]; then
changelog_previous_wowi="[url=${githost_url}/releases]Previous releases[/url]"
fi
wowi_changelog="$releasedir/WOWI-$project_version-CHANGELOG.txt"
cat <<- EOF | line_ending_filter > "$wowi_changelog"
[size=5]$project[/size]
[size=4]$changelog_version_wowi ($changelog_date)[/size]
$changelog_url_wowi $changelog_previous_wowi
[list]
EOF
git -C "$topdir" log $_changelog_range --pretty=format:"###%B" \
| sed -e 's/^/ /g' -e 's/^ *$//g' -e 's/^ ###/[*]/g' \
-e 's/\[ci skip\]//g' -e 's/\[skip ci\]//g' \
-e '/git-svn-id:/d' -e '/^\s*This reverts commit [0-9a-f]\{40\}\.\s*$/d' \
-e '/^\s*$/d' \
| line_ending_filter >> "$wowi_changelog"
echo "[/list]" | line_ending_filter >> "$wowi_changelog"
fi
elif [ "$repository_type" = "svn" ]; then
_changelog_range=
if [ -n "$previous_version" ]; then
_changelog_range="-r$project_revision:$previous_revision"
fi
changelog_date=$( TZ= printf "%(%Y-%m-%d)T" "$project_timestamp" )
cat <<- EOF | line_ending_filter > "$pkgdir/$changelog"
# $project
## $project_version ($changelog_date)
EOF
svn log "$topdir" $_changelog_range --xml \
| awk '//,/<\/msg>/' \
| sed -e 's//###/g' -e 's/<\/msg>//g' \
-e 's/^/ /g' -e 's/^ *$//g' -e 's/^ ###/- /g' -e 's/$/ /' \
-e 's/\([a-zA-Z0-9]\)_\([a-zA-Z0-9]\)/\1\\_\2/g' \
-e 's/\[ci skip\]//g' -e 's/\[skip ci\]//g' \
-e '/^\s*$/d' \
| line_ending_filter >> "$pkgdir/$changelog"
# WoWI uses BBCode, generate something usable to post to the site
# the file is deleted on successful upload
if [ -n "$addonid" -a -n "$tag" -a -n "$wowi_gen_changelog" ]; then
wowi_changelog="$releasedir/WOWI-$project_version-CHANGELOG.txt"
cat <<- EOF | line_ending_filter > "$wowi_changelog"
[size=5]$project[/size]
[size=4][color=orange]$project_version[/color] ($changelog_date)[/size]
[list]
EOF
svn log "$topdir" $_changelog_range --xml \
| awk '//,/<\/msg>/' \
| sed -e 's//###/g' -e 's/<\/msg>//g' \
-e 's/^/ /g' -e 's/^ *$//g' -e 's/^ ###/[*]/g' \
-e 's/\[ci skip\]//g' -e 's/\[skip ci\]//g' \
-e '/^\s*$/d' \
| line_ending_filter >> "$wowi_changelog"
echo "[/list]" | line_ending_filter >> "$wowi_changelog"
fi
elif [ "$repository_type" = "hg" ]; then
_changelog_range=.
if [ -n "$previous_revision" ]; then
_changelog_range="::$project_revision - ::$previous_revision - filelog(.hgtags)"
fi
changelog_date=$( TZ= printf "%(%Y-%m-%d)T" "$project_timestamp" )
cat <<- EOF | line_ending_filter > "$pkgdir/$changelog"
# $project
## $project_version ($changelog_date)
EOF
hg --cwd "$topdir" log -r "$_changelog_range" --template '- {fill(desc|strip, 76, "", " ")}\n' | line_ending_filter >> "$pkgdir/$changelog"
# WoWI uses BBCode, generate something usable to post to the site
# the file is deleted on successful upload
if [ -n "$addonid" -a -n "$tag" -a -n "$wowi_gen_changelog" ]; then
wowi_changelog="$releasedir/WOWI-$project_version-CHANGELOG.txt"
cat <<- EOF | line_ending_filter > "$wowi_changelog"
[size=5]$project[/size]
[size=4][color=orange]$project_version[/color] ($changelog_date)[/size]
[list]
EOF
hg --cwd "$topdir" log $_changelog_range --template '[*]{desc|strip|escape}\n' | line_ending_filter >> "$wowi_changelog"
echo "[/list]" | line_ending_filter >> "$wowi_changelog"
fi
fi
echo
cat "$pkgdir/$changelog"
echo
fi
###
### Process .pkgmeta to perform move-folders actions.
###
if [ -f "$pkgmeta_file" ]; then
yaml_eof=
while [ -z "$yaml_eof" ]; do
IFS='' read -r yaml_line || yaml_eof=true
# Strip any trailing CR character.
yaml_line=${yaml_line%$carriage_return}
case $yaml_line in
[!\ ]*:*)
# Split $yaml_line into a $yaml_key, $yaml_value pair.
yaml_keyvalue "$yaml_line"
# Set the $pkgmeta_phase for stateful processing.
pkgmeta_phase=$yaml_key
;;
" "*)
yaml_line=${yaml_line#"${yaml_line%%[! ]*}"} # trim leading whitespace
case $yaml_line in
"- "*)
;;
*:*)
# Split $yaml_line into a $yaml_key, $yaml_value pair.
yaml_keyvalue "$yaml_line"
case $pkgmeta_phase in
move-folders)
srcdir="$releasedir/$yaml_key"
destdir="$releasedir/$yaml_value"
if [[ -d "$destdir" && -z "$overwrite" && "$srcdir" != "$destdir/"* ]]; then
rm -fr "$destdir"
fi
if [ -d "$srcdir" ]; then
if [ ! -d "$destdir" ]; then
mkdir -p "$destdir"
fi
echo "Moving $yaml_key to $yaml_value"
mv -f "$srcdir"/* "$destdir" && rm -fr "$srcdir"
contents="$contents $yaml_value"
# Copy the license into $destdir if one doesn't already exist.
if [ -n "$license" -a -f "$pkgdir/$license" -a ! -f "$destdir/$license" ]; then
cp -f "$pkgdir/$license" "$destdir/$license"
fi
# Check to see if the base source directory is empty
_mf_basedir=${srcdir%$(basename "$yaml_key")}
if [ ! "$(ls -A $_mf_basedir )" ]; then
echo "Removing empty directory ${_mf_basedir#$releasedir/}"
rm -fr "$_mf_basedir"
fi
fi
# update external dir
nolib_exclude=${nolib_exclude//$srcdir/$destdir}
;;
esac
;;
esac
;;
esac
done < "$pkgmeta_file"
if [ -n "$srcdir" ]; then
echo
fi
fi
###
### Create the final zipfile for the addon.
###
archive_package_name="${package//[^A-Za-z0-9._-]/_}"
archive_version="$project_version"
archive_name="$archive_package_name-$project_version${classic:+-classic}.zip"
archive="$releasedir/$archive_name"
nolib_archive_version="$project_version-nolib"
nolib_archive_name="$archive_package_name-$nolib_archive_version${classic:+-classic}.zip"
nolib_archive="$releasedir/$nolib_archive_name"
if [ -z "$skip_zipfile" ]; then
if [ -n "$nolib" ]; then
archive_version="$nolib_archive_version"
archive_name="$nolib_archive_name"
archive="$nolib_archive"
nolib_archive=
fi
echo "Creating archive: $archive_name"
if [ -f "$archive" ]; then
rm -f "$archive"
fi
( cd "$releasedir" && zip -X -r "$archive" $contents )
if [ ! -f "$archive" ]; then
exit 1
fi
echo
# Create nolib version of the zipfile
if [ -n "$enable_nolib_creation" -a -z "$nolib" -a -n "$nolib_exclude" ]; then
echo "Creating no-lib archive: $nolib_archive_name"
# run the nolib_filter
find "$pkgdir" -type f \( -name "*.xml" -o -name "*.toc" \) -print | while read file; do
case $file in
*.toc) _filter="toc_filter2 no-lib-strip" ;;
*.xml) _filter="xml_filter no-lib-strip" ;;
esac
$_filter < "$file" > "$file.tmp" && mv "$file.tmp" "$file"
done
# make the exclude paths relative to the release directory
nolib_exclude=${nolib_exclude//$releasedir\//}
if [ -f "$nolib_archive" ]; then
rm -f "$nolib_archive"
fi
# set noglob so each nolib_exclude path gets quoted instead of expanded
( set -f; cd "$releasedir" && zip -X -r -q "$nolib_archive" $contents -x $nolib_exclude )
if [ ! -f "$nolib_archive" ]; then
exit_code=1
fi
echo
fi
fi
###
### Deploy the zipfile.
###
if [ -z "$skip_upload" ]; then
if [ ! -f "$archive" ]; then
echo "Skipping upload because archive file is missing."
skip_cf_upload=true
skip_wi_upload=true
skip_gh_upload=true
skip_gl_upload=true
exit_code=1
fi
upload_curseforge=$( [[ -z "$skip_cf_upload" && -n "$slug" && -n "$cf_token" && -n "$project_site" ]] && echo true )
upload_wowinterface=$( [[ -z "$skip_wi_upload" && -n "$tag" && -n "$addonid" && -n "$wowi_token" ]] && echo true )
upload_github=$( [[ -z "$skip_gh_upload" && -n "$tag" && -n "$github_slug" && -n "$github_token" ]] && echo true )
upload_gitlab=$( [[ -z "$skip_gl_upload" && -n "$tag" && -n "$gitlab_slug" && -n "$gitlab_token" ]] && echo true )
if [ -n "$upload_curseforge" -o -n "$upload_wowinterface" -o -n "$upload_github" -o -n "$upload_gitlab" ] && ! which jq &>/dev/null; then
echo "Skipping upload because \"jq\" was not found."
echo
upload_curseforge=
upload_wowinterface=
upload_github=
upload_gitlab=
exit_code=1
fi
# Upload to CurseForge.
if [ -n "$upload_curseforge" ]; then
_cf_versions=$( curl -s -H "x-api-token: $cf_token" $project_site/api/game/versions )
if [ -n "$_cf_versions" ]; then
if [ -n "$game_version" ]; then
game_version_id=$(
_v=
IFS=',' read -a V <<< "$game_version"
for i in "${V[@]}"; do
_v="$_v,\"$i\""
done
_v="[${_v#,}]"
# jq -c '["8.0.1","7.3.5"] as $v | map(select(.name as $x | $v | index($x)) | .id)'
echo "$_cf_versions" | jq -c --argjson v $_v 'map(select(.name as $x | $v | index($x)) | .id) | select(length > 0)' 2>/dev/null
)
if [ -n "$game_version_id" ]; then
# and now the reverse, since an invalid version will just be dropped (jq newlines are crlf on windows /wrists)
game_version=$(
_v=
V=($( echo $_cf_versions | jq -r --argjson v $game_version_id '.[] | select(.id as $x | $v | index($x)) | .name' 2>/dev/null ))
for i in "${V[@]}"; do
_v="$_v,${i%%[[:cntrl:]]}"
done
echo "${_v#,}"
)
fi
fi
if [ -z "$game_version_id" ]; then
# 517 = retail, 67408 = classic
game_version_id=$( echo $_cf_versions | jq -c 'map(select(.gameVersionTypeID == 517)) | max_by(.id) | [.id]' 2>/dev/null )
game_version=$( echo $_cf_versions | jq -r 'map(select(.gameVersionTypeID == 517)) | max_by(.id) | .name' 2>/dev/null )
fi
fi
if [ -n "$game_version_id" ]; then
_cf_payload=$( cat <<-EOF
{
"displayName": "$project_version",
"gameVersions": $game_version_id,
"releaseType": "$release_type",
"changelog": $( cat "$pkgdir/$changelog" | jq --slurp --raw-input '.' ),
"changelogType": "markdown"
}
EOF
)
_cf_payload_relations=
for i in "${!relations[@]}"; do
_cf_payload_relations="$_cf_payload_relations{\"slug\":\"$i\",\"type\":\"${relations[$i]}\"},"
done
if [[ -n $_cf_payload_relations ]]; then
_cf_payload_relations="{\"relations\":{\"projects\":[${_cf_payload_relations%,}]}}"
_cf_payload=$( echo "$_cf_payload $_cf_payload_relations" | jq -s -c '.[0] * .[1]' )
fi
echo "Uploading $archive_name ($game_version $release_type) to $project_site/projects/$slug"
resultfile="$releasedir/cf_result.json"
result=$( curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "x-api-token: $cf_token" \
-F "metadata=$_cf_payload" \
-F "file=@$archive" \
"$project_site/api/projects/$slug/upload-file" ) &&
{
case $result in
200) echo "Success!" ;;
302)
echo "Error! ($result)"
# don't need to ouput the redirect page
exit_code=1
;;
404)
echo "Error! No project for \"$slug\" found."
exit_code=1
;;
*)
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
exit_code=1
;;
esac
} || {
exit_code=1
}
echo
rm -f "$resultfile" 2>/dev/null
else
echo "Error fetching game version info from $project_site/api/game/versions"
echo
echo "Skipping upload to CurseForge."
echo
exit_code=1
fi
fi
# Upload tags to WoWInterface.
if [ -n "$upload_wowinterface" ]; then
_wowi_versions=$( curl -s -H "x-api-token: $wowi_token" https://api.wowinterface.com/addons/compatible.json )
if [ -n "$_wowi_versions" ]; then
game_version=$( echo $_wowi_versions | jq -r '.[] | select(.interface == "'$toc_version'" and .default == true) | .id' 2>/dev/null )
if [ -z "$game_version" ]; then
game_version=$( echo $_wowi_versions | jq -r 'map(select(.interface == "'$toc_version'"))[0] | .id // empty' 2>/dev/null )
fi
if [ -z "$game_version" ]; then
game_version=$( echo $_wowi_versions | jq -r '.[] | select(.default == true) | .id' 2>/dev/null )
fi
fi
if [ -n "$game_version" ]; then
_wowi_changelog=
if [ -f "$wowi_changelog" ]; then
_wowi_changelog="<$wowi_changelog"
elif [ -n "$manual_changelog" ]; then
_wowi_changelog="<$pkgdir/$changelog"
fi
_wowi_archive="Yes"
if [ -z "$wowi_archive" ]; then
_wowi_archive="No"
fi
echo "Uploading $archive_name ($game_version) to https://www.wowinterface.com/downloads/info$addonid"
resultfile="$releasedir/wi_result.json"
result=$( curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "x-api-token: $wowi_token" \
-F "id=$addonid" \
-F "version=$archive_version" \
-F "compatible=$game_version" \
-F "changelog=$_wowi_changelog" \
-F "archive=$_wowi_archive" \
-F "updatefile=@$archive" \
"https://api.wowinterface.com/addons/update" ) &&
{
case $result in
202)
echo "Success!"
rm -f "$wowi_changelog" 2>/dev/null
;;
401)
echo "Error! No addon for id \"$addonid\" found or you do not have permission to upload files."
exit_code=1
;;
403)
echo "Error! Incorrect api key or you do not have permission to upload files."
exit_code=1
;;
*)
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
exit_code=1
;;
esac
} || {
exit_code=1
}
echo
rm -f "$resultfile" 2>/dev/null
else
echo "Error fetching game version info from https://api.wowinterface.com/addons/compatible.json"
echo
echo "Skipping upload to WoWInterface."
echo
upload_wowinterface=
exit_code=1
fi
fi
if [[ -n "$upload_github" || -n "$upload_gitlab" ]]; then
# Create changelog
project_site_name="CurseForge"
if [ "$project_site" == "https://www.wowace.com" ]; then
project_site_name="WowAce";
fi
changelog_githost="$pkgdir/$changelog"
_changelog_githost="$releasedir/CHANGELOG_GITHOST.md"
if [ -f "$changelog_githost" ]; then
cp "$changelog_githost" "$_changelog_githost"
changelog_githost="$_changelog_githost"
if [[ -n "$slug" || -n "$addonid" ]]; then
echo -en "\n\nGet it from " >> "$changelog_githost"
if [ -n "$slug" ]; then
echo -n "[$project_site_name]($project_site/projects/$slug)" >> "$changelog_githost"
fi
if [[ -n "$slug" && -n "$addonid" ]]; then
echo -n " or " >> "$changelog_githost"
fi
if [ -n "$addonid" ]; then
echo -n "[WoWInterface](https://www.wowinterface.com/downloads/info$addonid.html)" >> "$changelog_githost"
fi
echo >> "$changelog_githost"
fi
fi
# Create a GitHub Release for tags and upload the zipfile as an asset.
if [ -n "$upload_github" ]; then
upload_github_asset() {
_ghf_release_id=$1
_ghf_file_name=$2
_ghf_file_path=$3
_ghf_resultfile="$releasedir/gh_asset_result.json"
# check if an asset exists and delete it (editing a release)
asset_id=$( curl -sS "https://api.github.com/repos/$github_slug/releases/$_ghf_release_id/assets" | jq '.[] | select(.name? == "'$_ghf_file_name'") | .id' )
if [ -n "$asset_id" ]; then
curl -s -H "Authorization: token $github_token" -X DELETE "https://api.github.com/repos/$github_slug/releases/assets/$asset_id" &>/dev/null
fi
echo -n "Uploading $_ghf_file_name... "
result=$( curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$_ghf_resultfile" \
-H "Authorization: token $github_token" \
-H "Content-Type: application/zip" \
--data-binary "@$_ghf_file_path" \
"https://uploads.github.com/repos/$github_slug/releases/$_ghf_release_id/assets?name=$_ghf_file_name" ) &&
{
if [ "$result" = "201" ]; then
echo "Success!"
else
echo "Error ($result)"
if [ -s "$_ghf_resultfile" ]; then
echo "$(<"$_ghf_resultfile")"
fi
exit_code=1
fi
} || {
exit_code=1
}
rm -f "$_ghf_resultfile" 2>/dev/null
}
# check if a release exists and delete it unless it's a classic build
# TODO: Need to work out how to handle classic only addons, currently the assumption is the retail version is built first, followed by classic
release_id=$( curl -sS "https://api.github.com/repos/$github_slug/releases/tags/$tag" | jq '.id // empty' )
if [ -n "$release_id" ] && [ -z "$classic" ]; then
curl -s -H "Authorization: token $github_token" -X DELETE "https://api.github.com/repos/$github_slug/releases/$release_id" &>/dev/null
release_id=
sleep 1
fi
_gh_payload=$( cat <<-EOF
{
"tag_name": "$tag",
"name": "$tag",
"body": $( cat "$changelog_githost" | jq --slurp --raw-input '.' ),
"draft": false,
"prerelease": $( [[ "$release_type" != "release" ]] && echo true || echo false )
}
EOF
)
resultfile="$releasedir/gh_result.json"
if [ -n "$release_id" ]; then
echo "Updating GitHub release: https://github.com/$github_slug/releases/tag/$tag"
# result=$( curl -sS --retry 3 --retry-delay 10 \
# -w "%{http_code}" -o "$resultfile" \
# -H "Authorization: token $github_token" \
# -X PATCH \
# -d "$_gh_payload" \
# "https://api.github.com/repos/$github_slug/releases/$release_id" ) &&
# {
# if [ "$result" = "201" ]; then
upload_github_asset "$release_id" "$archive_name" "$archive"
if [ -f "$nolib_archive" ]; then
upload_github_asset "$release_id" "$nolib_archive_name" "$nolib_archive"
fi
# else
# echo "Error! ($result)"
# if [ -s "$resultfile" ]; then
# echo "$(<"$resultfile")"
# fi
# exit_code=1
# fi
# } || {
# exit_code=1
# }
else
echo "Creating GitHub release: https://github.com/$github_slug/releases/tag/$tag"
result=$( curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "Authorization: token $github_token" \
-d "$_gh_payload" \
"https://api.github.com/repos/$github_slug/releases" ) &&
{
if [ "$result" = "201" ]; then
release_id=$( cat "$resultfile" | jq '.id' )
upload_github_asset "$release_id" "$archive_name" "$archive"
if [ -f "$nolib_archive" ]; then
upload_github_asset "$release_id" "$nolib_archive_name" "$nolib_archive"
fi
else
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
exit_code=1
fi
} || {
exit_code=1
}
fi
rm -f "$resultfile" 2>/dev/null
echo
fi
# Create a GitLab Release for tags and upload the zipfile as an asset.
if [ -n "$upload_gitlab" ]; then
urlencode() {
local length="${#1}"
for (( i = 0; i < length; i++ )); do
local c="${1:i:1}"
case $c in
[a-zA-Z0-9.~_-]) printf "$c" ;;
*) printf '%%%02X' "'$c" ;;
esac
done
}
gitlab_id=$( curl -sS --retry 3 --retry-delay 10 -H "PRIVATE-TOKEN: $gitlab_token" "https://gitlab.vuhdo.io/api/v4/projects?$gitlab_slug" | jq '.[0].id' )
gitlab_assets=
upload_gitlab_asset() {
_glf_file_name=$1
_glf_file_path=$2
_glf_resultfile="$releasedir/gl_asset_result.json"
_glf_exit_code=0
echo -n "Uploading $_glf_file_name to GitLab... "
result=$( curl -sS --retry 3 --retry-delay 10 --request POST \
-w "%{http_code}" -o "$_glf_resultfile" \
-H "PRIVATE-TOKEN: $gitlab_token" \
-F "file=@$_glf_file_path" \
"https://gitlab.vuhdo.io/api/v4/projects/$gitlab_id/uploads" )
if [ $? -eq 0 ]; then
if [ "$result" -eq "201" ]; then
echo "Success!"
_glf_file_url=$( cat "$_glf_resultfile" | jq '.url' )
gitlab_assets="${gitlab_assets:+,}{\"name\":\"$_glf_file_name\",\"url\":\"https://gitlab.vuhdo.io/$gitlab_slug${_glf_file_url:1:-1}\"}"
else
echo "Error ($result)"
if [ -s "$_ghf_resultfile" ]; then
echo "$(<"$_ghf_resultfile")"
fi
_glf_exit_code=1
fi
else
_glf_exit_code=1
fi
rm -f "$_glf_resultfile" 2>/dev/null
return $_glf_exit_code
}
# Upload archives
if upload_gitlab_asset "$archive_name" "$archive" && { [[ ! -f "$nolib_archive" ]] || upload_gitlab_asset "$nolib_archive_name" "$nolib_archive"; } then
# delete existing release for the tag
curl -sS -X DELETE -H "PRIVATE-TOKEN: $gitlab_token" "https://gitlab.vuhdo.io/api/v4/projects/$gitlab_id/releases/$tag" > /dev/null
_gl_payload_desc=$( cat "$changelog_githost" | jq --slurp --raw-input '.' | awk -F '--------------------------------------------------------------' '{print $1 FS "."}' | sed -e 's/.\{63\}$//' )
if [[ -n "$slug" || -n "$addonid" ]]; then
_gl_payload_desc="$_gl_payload_desc"'\nGet it from '
if [ -n "$slug" ]; then
_gl_payload_desc="$_gl_payload_desc""[$project_site_name]($project_site/projects/$slug)"
fi
if [[ -n "$slug" && -n "$addonid" ]]; then
_gl_payload_desc="$_gl_payload_desc or "
fi
if [ -n "$addonid" ]; then
_gl_payload_desc="$_gl_payload_desc""[WoWInterface](https://www.wowinterface.com/downloads/info$addonid.html)"
fi
fi
_gl_payload=$( cat <<-EOF
{
"tag_name": "$tag",
"name": "$tag",
"description": $_gl_payload_desc",
"assets": {"links":[$gitlab_assets]}
}
EOF
)
echo "Creating GitLab release: https://gitlab.vuhdo.io/$gitlab_slug/releases"
resultfile="$releasedir/gl_result.json"
result=$( curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "PRIVATE-TOKEN: $gitlab_token" \
-H "Content-Type: application/json" \
-d "$_gl_payload" \
"https://gitlab.vuhdo.io/api/v4/projects/$gitlab_id/releases" )
if [ $? -eq 0 ]; then
if [ "$result" = "201" ]; then
echo "Success!"
else
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
exit_code=1
fi
else
exit_code=1
fi
echo
rm -f "$resultfile" 2>/dev/null
else
exit_code=1
fi
fi
if [ -f "$_changelog_githost" ]; then
rm -f "$_changelog_githost" 2>/dev/null
fi
fi
fi
# All done.
echo "Packaging complete."
echo
exit $exit_code