]*>
/[highlight="lua"]/g' -e 's/<\/code><\/pre><\/div>/[\/highlight]\n/g' \
-e 's//[code]/g' -e 's/<\/code><\/pre>/[\/code]\n/g' \
-e 's//[font="monospace"]/g' -e 's/<\/code>/[\/font]/g' \
-e 's/]*>/[url="\1"]/g' -e 's/<\/a>/\[\/url]/g' \
-e 's/]*>/[img]\1[\/img]/g' \
-e 's/
/_____________________________________________________________________________\n/g' \
-e 's/<\/p>/\n/g' \
-e '/^<[^>]\+>$/d' -e 's/<[^>]\+>//g' \
-e 's/"/"/g' \
-e 's/&/&/g' \
-e 's/<//g' \
-e "s/'/'/g" \
| line_ending_filter > "$wowi_changelog"
fi
else
if [ -n "$manual_changelog" ]; then
echo "Warning! Could not find a manual changelog at $topdir/$changelog"
manual_changelog=
fi
changelog="CHANGELOG.md"
changelog_markup="markdown"
changelog_path="$pkgdir/$changelog"
if [ -n "$wowi_gen_changelog" ] && [ -z "$wowi_convert_changelog" ]; then
wowi_markup="markdown"
fi
start_group "Generating changelog of commits into $changelog" "changelog"
_changelog_range=
if [ "$repository_type" = "git" ]; then
changelog_url=
changelog_version=
changelog_previous="[Previous Releases](${project_github_url}/releases)"
changelog_url_wowi=
changelog_version_wowi=
changelog_previous_wowi="[url=${project_github_url}/releases]Previous Releases[/url]"
if [ -z "$previous_version" ] && [ -z "$tag" ]; then
# no range, show all commits up to ours
changelog_url="[Full Changelog](${project_github_url}/commits/${project_hash})"
changelog_version="[${project_version}](${project_github_url}/tree/${project_hash})"
changelog_url_wowi="[url=${project_github_url}/commits/${project_hash}]Full Changelog[/url]"
changelog_version_wowi="[url=${project_github_url}/tree/${project_hash}]${project_version}[/url]"
_changelog_range="$project_hash"
elif [ -z "$previous_version" ] && [ -n "$tag" ]; then
# first tag, show all commits upto it
changelog_url="[Full Changelog](${project_github_url}/commits/${tag})"
changelog_version="[${project_version}](${project_github_url}/tree/${tag})"
changelog_url_wowi="[url=${project_github_url}/commits/${tag}]Full Changelog[/url]"
changelog_version_wowi="[url=${project_github_url}/tree/${tag}]${project_version}[/url]"
_changelog_range="$tag"
elif [ -n "$previous_version" ] && [ -z "$tag" ]; then
# compare between last tag and our commit
changelog_url="[Full Changelog](${project_github_url}/compare/${previous_version}...${project_hash})"
changelog_version="[$project_version](${project_github_url}/tree/${project_hash})"
changelog_url_wowi="[url=${project_github_url}/compare/${previous_version}...${project_hash}]Full Changelog[/url]"
changelog_version_wowi="[url=${project_github_url}/tree/${project_hash}]${project_version}[/url]"
_changelog_range="$previous_version..$project_hash"
elif [ -n "$previous_version" ] && [ -n "$tag" ]; then
# compare between last tag and our tag
changelog_url="[Full Changelog](${project_github_url}/compare/${previous_version}...${tag})"
changelog_version="[$project_version](${project_github_url}/tree/${tag})"
changelog_url_wowi="[url=${project_github_url}/compare/${previous_version}...${tag}]Full Changelog[/url]"
changelog_version_wowi="[url=${project_github_url}/tree/${tag}]${project_version}[/url]"
_changelog_range="$previous_version..$tag"
fi
# lazy way out
if [ -z "$project_github_url" ]; then
changelog_url=
changelog_version=$project_version
changelog_previous=
changelog_url_wowi=
changelog_version_wowi="[color=orange]${project_version}[/color]"
changelog_previous_wowi=
elif [ -z "$github_token" ]; then
# not creating releases :(
changelog_previous=
changelog_previous_wowi=
fi
changelog_date=$( TZ='' printf "%(%Y-%m-%d)T" "$project_timestamp" )
cat <<- EOF | line_ending_filter > "$changelog_path"
# $project
## $changelog_version ($changelog_date)
$changelog_url $changelog_previous
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 '/^[[:space:]]*This reverts commit [0-9a-f]\{40\}\.[[:space:]]*$/d' \
-e '/^[[:space:]]*$/d' \
| line_ending_filter >> "$changelog_path"
# WoWI uses BBCode, generate something usable to post to the site
# the file is deleted on successful upload
if [ -n "$addonid" ] && [ -n "$tag" ] && [ -n "$wowi_gen_changelog" ] && [ "$wowi_markup" = "bbcode" ]; then
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 '/^[[:space:]]*This reverts commit [0-9a-f]\{40\}\.[[:space:]]*$/d' \
-e '/^[[:space:]]*$/d' \
| line_ending_filter >> "$wowi_changelog"
echo "[/list]" | line_ending_filter >> "$wowi_changelog"
fi
elif [ "$repository_type" = "svn" ]; then
if [ -n "$previous_revision" ]; then
_changelog_range="-r$project_revision:$previous_revision"
else
_changelog_range="-rHEAD:1"
fi
changelog_date=$( TZ='' printf "%(%Y-%m-%d)T" "$project_timestamp" )
cat <<- EOF | line_ending_filter > "$changelog_path"
# $project
## $project_version ($changelog_date)
EOF
_svn_changelog=$( retry svn log "$topdir" "$_changelog_range" --xml )
echo "$_svn_changelog" \
| 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 '/^[[:space:]]*$/d' \
| line_ending_filter >> "$changelog_path"
# WoWI uses BBCode, generate something usable to post to the site
# the file is deleted on successful upload
if [ -n "$addonid" ] && [ -n "$tag" ] && [ -n "$wowi_gen_changelog" ] && [ "$wowi_markup" = "bbcode" ]; 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
echo "$_svn_changelog" \
| 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 '/^[[:space:]]*$/d' \
| line_ending_filter >> "$wowi_changelog"
echo "[/list]" | line_ending_filter >> "$wowi_changelog"
fi
unset _svn_changelog
elif [ "$repository_type" = "hg" ]; then
if [ -n "$previous_revision" ]; then
_changelog_range="::$project_revision - ::$previous_revision - filelog(.hgtags)"
else
_changelog_range="."
fi
changelog_date=$( TZ='' printf "%(%Y-%m-%d)T" "$project_timestamp" )
cat <<- EOF | line_ending_filter > "$changelog_path"
# $project
## $project_version ($changelog_date)
EOF
hg --cwd "$topdir" log -r "$_changelog_range" --template '- {fill(desc|strip, 76, "", " ")}\n' | line_ending_filter >> "$changelog_path"
# WoWI uses BBCode, generate something usable to post to the site
# the file is deleted on successful upload
if [ -n "$addonid" ] && [ -n "$tag" ] && [ -n "$wowi_gen_changelog" ] && [ "$wowi_markup" = "bbcode" ]; 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 "$(<"$changelog_path")"
end_group "changelog"
fi
###
### Create a license if not present and .pkgmeta requests one.
###
if [[ -n "$license" && ! -f "$topdir/$license" && -n "$slug" ]]; then
start_group "Saving license as $license" "license"
# curseforge.com is protected by cloudflare, but wowace.com isn't? >.>
if license_text=$( curl -sf --retry 3 --retry-delay 10 "https://www.wowace.com/project/$slug/license" 2>/dev/null ); then
# text is wrapped with \n\n\n
echo "$license_text" | sed -e '1,4d' -e '5s/^\s*//' -e '$d' | sed '$d' > "$pkgdir/$license"
head -n10 "$pkgdir/$license"
[[ "$( wc -l < "$pkgdir/$license" )" -gt 10 ]] && echo "..."
else
echo "There was an error saving the license. ($?)"
fi
end_group "license"
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"
# Skip commented out lines.
if [[ $yaml_line =~ ^[[:space:]]*\# ]]; then
continue
fi
# 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"
zip_root_dirs+=("$yaml_value")
# Copy the license into $destdir if one doesn't already exist.
if [[ -n "$license" && -f "$pkgdir/$license" && ! -f "$destdir/$license" ]]; then
cp -f "$pkgdir/$license" "$destdir/$license"
fi
# Check to see if the base source directory is empty
_mf_basedir="/${yaml_key%/*}"
while [[ -n "$_mf_basedir" && -z "$( ls -A "${releasedir}${_mf_basedir}" )" ]]; do
echo "Removing empty directory ${_mf_basedir#/}"
rm -fr "${releasedir}${_mf_basedir}"
_mf_basedir="${_mf_basedir%/*}"
done
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.
###
if [ -z "$skip_zipfile" ]; then
archive_version="$project_version" # XXX used for wowi version. should probably switch to label, but the game type gets added on by default :\
archive_label="$( filename_filter "$label_template" )"
archive_name="$( filename_filter "$file_template" ).zip"
archive="$releasedir/$archive_name"
nolib_archive_version="${project_version}-nolib"
nolib_archive_label="$( nolib=true filename_filter "$archive_label" )"
nolib_archive_name="$( nolib=true filename_filter "$file_template" ).zip"
# someone didn't include {nolib} and they're forcing nolib creation
if [ "$archive_label" = "$nolib_archive_label" ]; then
nolib_archive_label="${nolib_archive_label}-nolib"
fi
if [ "$archive_name" = "$nolib_archive_name" ]; then
nolib_archive_name="${nolib_archive_name%.zip}-nolib.zip"
fi
nolib_archive="$releasedir/$nolib_archive_name"
if [ -n "$nolib" ]; then
archive_version="$nolib_archive_version"
archive_label="$nolib_archive_label"
archive_name="$nolib_archive_name"
archive="$nolib_archive"
nolib_archive=
fi
if [[ -n $GITHUB_ACTIONS ]]; then
echo "archive_path=${archive}" >> "$GITHUB_OUTPUT"
fi
start_group "Creating archive: $archive_name ($archive_label)" "archive"
if [ -f "$archive" ]; then
rm -f "$archive"
fi
( cd "$releasedir" && zip -X -r "$archive" "${zip_root_dirs[@]}" )
if [ ! -f "$archive" ]; then
exit 1
fi
end_group "archive"
# Create nolib version of the zipfile
if [ -n "$enable_nolib_creation" ] && [ -z "$nolib" ] && [ -n "$nolib_exclude" ]; then
# run the nolib_filter
find "$pkgdir" -type f \( -name "*.xml" -o -name "*.toc" \) -print | while read -r file; do
case $file in
*.toc) _filter="toc_filter no-lib-strip true" ;;
*.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\//}
start_group "Creating no-lib archive: $nolib_archive_name ($nolib_archive_label)" "archive.nolib"
if [ -f "$nolib_archive" ]; then
rm -f "$nolib_archive"
fi
# set noglob so each nolib_exclude path gets quoted instead of expanded
# shellcheck disable=SC2086
( set -f; cd "$releasedir" && zip -X -r -q "$nolib_archive" "${zip_root_dirs[@]}" -x $nolib_exclude )
if [ ! -f "$nolib_archive" ]; then
exit_code=1
fi
end_group "archive.nolib"
fi
fi
###
### Deploy the zipfile.
###
# Upload to CurseForge.
upload_curseforge() {
if [[ -n "$skip_cf_upload" || -z "$slug" || -z "$cf_token" || -z "$project_site" ]]; then
return 0
fi
local _cf_game_version_id _cf_game_version _cf_versions
_cf_versions=$( curl -s -H "x-api-token: $cf_token" "$project_site/api/game/versions" )
if [[ -n $_cf_versions && $_cf_versions != *"errorMessage"* ]]; then
_cf_game_version_id=
_cf_game_version=
local version_name version_id game_id
for type in "classic" "bcc" "wrath" "cata" "retail"; do # sort order (last id is show as the version on the project's files page apparently)
version_name="${game_type_version[$type]}"
[[ -z $version_name ]] && continue
case $type in
classic) game_id=67408 ;;
bcc) game_id=73246 ;;
wrath) game_id=73713 ;;
cata) game_id=77522 ;;
*) game_id=517
esac
# check the version
if ! jq -e --arg v "$version_name" --argjson t "$game_id" 'map(select(.gameVersionTypeID == $t and .name == $v)) | length > 0' <<< "$_cf_versions" &>/dev/null; then
# no match, so grab the next highest version (try to avoid testing versions)
version_name=$( echo "$_cf_versions" | jq -r --arg v "$version_name" --argjson t "$game_id" 'map(select(.gameVersionTypeID == $t and .name < $v)) | max_by(.id) | .name // empty' )
if [[ -z $version_name ]]; then
# no? just grab the highest version
version_name=$( echo "$_cf_versions" | jq -r --argjson t "$game_id" 'map(select(.gameVersionTypeID == $t)) | max_by(.id) | .name' )
fi
echo "WARNING: No CurseForge game version match for \"${game_type_version[$type]}\", using \"$version_name\"" >&2
fi
_cf_game_version+=",${version_name}"
# get the id
version_id=$( echo "$_cf_versions" | jq -r --arg v "$version_name" --argjson t "$game_id" '.[] | select(.gameVersionTypeID == $t and .name == $v) | .id' )
_cf_game_version_id+=",${version_id}"
done
_cf_game_version_id="[${_cf_game_version_id#,}]"
_cf_game_version="${_cf_game_version#,}"
fi
if [ -z "$_cf_game_version" ]; then
echo "Error fetching game version info from $project_site/api/game/versions"
echo
echo "Skipping upload to CurseForge."
echo
exit_code=1
return 0
fi
local _cf_payload _cf_payload_relations
local resultfile result
local return_code=0
_cf_payload=$( cat <<-EOF
{
"displayName": "$archive_label",
"gameVersions": $_cf_game_version_id,
"releaseType": "$file_type",
"changelog": $( jq --slurp --raw-input '.' < "$changelog_path" ),
"changelogType": "$changelog_markup"
}
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 ($_cf_game_version $file_type) to https://www.curseforge.com/projects/$slug"
resultfile="$releasedir/cf_result.json"
if result=$( echo "$_cf_payload" | curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "x-api-token: $cf_token" \
-F "metadata=<-" \
-F "file=@$archive" \
"$project_site/api/projects/$slug/upload-file"
); then
case $result in
200) echo "Success!" ;;
302)
echo "Error! ($result)"
# don't need to ouput the redirect page
return_code=1
;;
404)
echo "Error! No project for \"$slug\" found."
return_code=1
;;
*)
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
return_code=1
;;
esac
else
return_code=1
fi
echo
rm -f "$resultfile" 2>/dev/null
# shellcheck disable=SC2086
return $return_code
}
# Upload tags to WoWInterface.
upload_wowinterface() {
if [[ -z "$tag" || -z "$addonid" || -z "$wowi_token" ]]; then
return 0
fi
local _wowi_versions _wowi_game_version
_wowi_versions=$( curl -s https://api.wowinterface.com/addons/compatible.json )
if [ -n "$_wowi_versions" ]; then
local version wowi_type
for type in "${!game_type_version[@]}"; do
version="${game_type_version[$type]}"
case $type in
classic) wowi_type="Classic" ;;
bcc) wowi_type="TBC-Classic" ;;
wrath) wowi_type="WOTLK-Classic" ;;
cata) wowi_type="Cata-Classic" ;;
*) wowi_type="Retail"
esac
# check the version
if ! jq -e --arg v "$version" 'map(select(.id == $v)) | length > 0' <<< "$_wowi_versions" &>/dev/null; then
# use the next highest version (try to avoid testing versions)
version=$( echo "$_wowi_versions" | jq -r --arg v "$version" --arg t "$wowi_type" 'map(select(.game == $t and .id < $v)) | max_by(.id) | .id // empty' )
if [[ -z $version ]]; then
# just grab the highest version
version=$( echo "$_wowi_versions" | jq -r --arg t "$wowi_type" 'map(select(.game == $t)) | max_by(.id) | .id // empty' )
fi
if [[ -z $version ]]; then
echo "WARNING: No WoWInterface game version match for \"${game_type_version[$type]}\", \"$wowi_type\" is not supported" >&2
else
echo "WARNING: No WoWInterface game version match for \"${game_type_version[$type]}\", using \"$version\"" >&2
fi
fi
if [[ -n $version ]]; then
_wowi_game_version+=",${version}"
fi
done
_wowi_game_version="${_wowi_game_version#,}"
fi
if [ -z "$_wowi_game_version" ]; then
echo "Error fetching game version info from https://api.wowinterface.com/addons/compatible.json"
echo
echo "Skipping upload to WoWInterface."
echo
exit_code=1
return 1
fi
local -a _wowi_args
local resultfile result
local return_code=0
if [ -f "$wowi_changelog" ]; then
_wowi_args+=("-F changelog=<$wowi_changelog")
elif [ -n "$manual_changelog" ] || [ "$wowi_markup" = "markdown" ]; then
_wowi_args+=("-F changelog=<$changelog_path")
fi
if [ -z "$wowi_archive" ]; then
_wowi_args+=("-F archive=No")
fi
echo "Uploading $archive_name ($_wowi_game_version) to https://www.wowinterface.com/downloads/info$addonid"
resultfile="$releasedir/wi_result.json"
if 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=$_wowi_game_version" \
"${_wowi_args[@]}" \
-F "updatefile=@$archive" \
"https://api.wowinterface.com/addons/update"
); then
case $result in
202)
echo "Success!"
if [ -f "$wowi_changelog" ]; then
rm -f "$wowi_changelog" 2>/dev/null
fi
;;
401)
echo "Error! No addon for id \"$addonid\" found or you do not have permission to upload files."
return_code=1
;;
403)
echo "Error! Incorrect api key or you do not have permission to upload files."
return_code=1
;;
*)
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
return_code=1
;;
esac
else
return_code=1
fi
echo
rm -f "$resultfile" 2>/dev/null
# shellcheck disable=SC2086
return $return_code
}
# Upload to Wago
upload_wago() {
if [[ -z "$wagoid" || -z "$wago_token" ]]; then
return 0
fi
local _wago_versions _wago_game_version _wago_support_property
_wago_versions=$( curl -s https://addons.wago.io/api/data/game | jq -c '.patches' 2>/dev/null )
if [ -n "$_wago_versions" ]; then
_wago_support_property=
local version wago_type
for type in "${!game_type_version[@]}"; do
version="${game_type_version[$type]}"
case $type in
bcc) wago_type="bc" ;;
wrath) wago_type="wotlk" ;;
*) wago_type="$type"
esac
# check the version
if ! jq -e --arg t "$wago_type" --arg v "$version" '.[$t] | index($v)' <<< "$_wago_versions" &>/dev/null; then
# no match, so grab the next highest version (try to avoid testing versions)
version=$( echo "$_wago_versions" | jq -r --arg t "$wago_type" --arg v "$version" '.[$t] | map(select(. < $v)) | max // empty' )
if [[ -z $version ]]; then
# just grab the highest version
version=$( echo "$_wago_versions" | jq -r --arg t "$wago_type" '.[$t] | max' )
fi
echo "WARNING: No Wago game version match for \"${game_type_version[$type]}\", using \"$version\"" >&2
fi
_wago_support_property+="\"supported_${wago_type}_patch\": \"${version}\", "
_wago_game_version+=",${version}"
done
_wago_game_version="${_wago_game_version#,}"
fi
if [ -z "$_wago_support_property" ]; then
echo "Error fetching game version info from https://addons.wago.io/api/data/game"
echo
echo "Skipping upload to Wago."
echo
exit_code=1
return 1
fi
local _wago_payload _wago_stability
local resultfile result
local return_code=0
_wago_stability="$file_type"
if [[ "$file_type" == "release" ]]; then
_wago_stability="stable"
fi
_wago_payload=$( cat <<-EOF
{
"label": "$archive_label",
$_wago_support_property
"stability": "$_wago_stability",
"changelog": $( jq --slurp --raw-input '.' < "$changelog_path" )
}
EOF
)
echo "Uploading $archive_name ($_wago_game_version $file_type) to https://addons.wago.io/addons/$wagoid"
resultfile="$releasedir/wago_result.json"
if result=$( echo "$_wago_payload" | curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "authorization: Bearer $wago_token" \
-H "accept: application/json" \
-F "metadata=<-" \
-F "file=@$archive" \
"https://addons.wago.io/api/projects/$wagoid/version"
); then
case $result in
200|201) echo "Success!" ;;
302)
echo "Error! ($result)"
# don't need to ouput the redirect page
return_code=1
;;
404)
echo "Error! No Wago project for id \"$wagoid\" found."
return_code=1
;;
*)
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
return_code=1
;;
esac
else
return_code=1
fi
echo
rm -f "$resultfile" 2>/dev/null
# shellcheck disable=SC2086
return $return_code
}
# Create a GitHub Release for tags and upload the zipfile as an asset.
upload_github_asset() {
local asset_id result return_code=0
local _ghf_release_id=$1
local _ghf_file_name=$2
local _ghf_file_path=$3
local _ghf_resultfile="$releasedir/gh_asset_result.json"
local _ghf_content_type="application/${_ghf_file_name##*.}" # zip or json
# check if an asset exists and delete it (editing a release)
asset_id=$( curl -sS \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_token" \
"https://api.github.com/repos/$project_github_slug/releases/$_ghf_release_id/assets" \
| jq --arg file "$_ghf_file_name" '.[] | select(.name? == $file) | .id'
)
if [ -n "$asset_id" ]; then
curl -s \
-X DELETE \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_token" \
"https://api.github.com/repos/$project_github_slug/releases/assets/$asset_id" &>/dev/null
fi
echo -n "Uploading $_ghf_file_name... "
if result=$( curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$_ghf_resultfile" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_token" \
-H "Content-Type: $_ghf_content_type" \
--data-binary "@$_ghf_file_path" \
"https://uploads.github.com/repos/$project_github_slug/releases/$_ghf_release_id/assets?name=$_ghf_file_name"
); then
if [ "$result" = "201" ]; then
echo "Success!"
else
echo "Error ($result)"
if [ -s "$_ghf_resultfile" ]; then
echo "$(<"$_ghf_resultfile")"
fi
return_code=1
fi
else
return_code=1
fi
rm -f "$_ghf_resultfile" 2>/dev/null
# shellcheck disable=SC2086
return $return_code
}
upload_github() {
if [[ -z "$tag" || -z "$project_github_slug" || -z "$github_token" ]]; then
return 0
fi
local _gh_metadata _gh_previous_metadata _gh_payload _gh_release_url _gh_method
local release_id versionfile resultfile result flavor title
local return_code=0
title=$( echo "$project" | jq --raw-input '.' )
_gh_metadata='{ "name": '"$title"', "version": "'"$project_version"'", "filename": "'"$archive_name"'", "nolib": false, "metadata": ['
for type in "${!game_type_version[@]}"; do
flavor="${game_flavor[$type]}"
[[ $flavor == "retail" ]] && flavor="mainline"
_gh_metadata+='{ "flavor": "'"${flavor}"'", "interface": '"${game_type_interface[$type]}"' },'
done
_gh_metadata=${_gh_metadata%,}
_gh_metadata+='] }'
if [ -f "$nolib_archive" ]; then
_gh_metadata+=',{ "name": '"$title"', "version": "'"$project_version"'", "filename": "'"$nolib_archive_name"'", "nolib": true, "metadata": ['
for type in "${!game_type_version[@]}"; do
flavor="${game_flavor[$type]}"
[[ $flavor == "retail" ]] && flavor="mainline"
_gh_metadata+='{ "flavor": "'"${flavor}"'", "interface": '"${game_type_interface[$type]}"' },'
done
_gh_metadata=${_gh_metadata%,}
_gh_metadata+='] }'
fi
_gh_metadata='{ "releases": ['"$_gh_metadata"'] }'
versionfile="$releasedir/release.json"
jq -c '.' <<< "$_gh_metadata" > "$versionfile" || echo "There was an error creating release.json" >&2
_gh_payload=$( cat <<-EOF
{
"tag_name": "$tag",
"name": "$tag",
"body": $( jq --slurp --raw-input '.' < "$changelog_path" ),
"draft": false,
"prerelease": $( [[ "$file_type" != "release" ]] && echo true || echo false )
}
EOF
)
resultfile="$releasedir/gh_result.json"
release_id=$( curl -sS \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_token" \
"https://api.github.com/repos/$project_github_slug/releases/tags/$tag" \
| jq '.id // empty'
)
if [ -n "$release_id" ]; then
echo "Updating GitHub release: https://github.com/$project_github_slug/releases/tag/$tag"
_gh_release_url="https://api.github.com/repos/$project_github_slug/releases/$release_id"
_gh_method="PATCH"
# combine version info
_gh_metadata_url=$( curl -sS \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_token" \
"https://api.github.com/repos/$project_github_slug/releases/$release_id/assets" \
| jq -r '.[] | select(.name? == "release.json") | .url // empty'
)
if [ -n "$_gh_metadata_url" ]; then
if _gh_previous_metadata=$( curl -sSL --fail \
-H "Accept: application/octet-stream" \
-H "Authorization: token $github_token" \
"$_gh_metadata_url"
); then
jq -sc '.[0].releases + .[1].releases | unique_by(.filename) | { releases: [.[]] }' <<< "${_gh_metadata} ${_gh_previous_metadata}" > "$versionfile"
else
echo "Warning: Unable to update release.json ($?)"
fi
fi
else
echo "Creating GitHub release: https://github.com/$project_github_slug/releases/tag/$tag"
_gh_release_url="https://api.github.com/repos/$project_github_slug/releases"
_gh_method="POST"
fi
if result=$( echo "$_gh_payload" | curl -sS --retry 3 --retry-delay 10 \
-w "%{http_code}" -o "$resultfile" \
-H "Accept: application/vnd.github.v3+json" \
-H "Authorization: token $github_token" \
-X "$_gh_method" \
-d @- \
"$_gh_release_url"
); then
if [ "$result" = "200" ] || [ "$result" = "201" ]; then # edited || created
if [ -z "$release_id" ]; then
release_id=$( jq '.id' < "$resultfile" )
fi
upload_github_asset "$release_id" "$archive_name" "$archive"
if [ -f "$nolib_archive" ]; then
upload_github_asset "$release_id" "$nolib_archive_name" "$nolib_archive"
fi
if [ -s "$versionfile" ]; then
upload_github_asset "$release_id" "release.json" "$versionfile"
fi
else
echo "Error! ($result)"
if [ -s "$resultfile" ]; then
echo "$(<"$resultfile")"
fi
return_code=1
fi
else
return_code=1
fi
echo
rm -f "$resultfile" 2>/dev/null
[ -z "$CI" ] && rm -f "$versionfile" 2>/dev/null
# shellcheck disable=SC2086
return $return_code
}
if [[ -z $skip_upload && -n $archive && -s $archive ]]; then
if ! command -v jq &>/dev/null; then
echo "Skipping upload because \"jq\" was not found."
echo
exit_code=1
else
retry upload_curseforge || exit_code=1
upload_wowinterface || exit_code=1
upload_wago || exit_code=1
upload_github || exit_code=1
fi
fi
# All done.
echo
echo "Packaging complete."
echo
# shellcheck disable=SC2086
exit $exit_code