From 70ab5cf613b40fecd4438c6e1bc12a3c1ec13bf1 2022-08-21 15:37:21 From: Branko Majic Date: 2022-08-21 15:37:21 Subject: [PATCH] [factorio_development.sh] Fix changelog updates and drop release archive when aborting the release: - It is not possible to read from and update the changelog file at the same time. --- diff --git a/games/factorio_development.sh b/games/factorio_development.sh index 3b9a718bab2ccc65eb72408c8439e0b08351c268..9d41bc2b0266a6881ed3f7d9a086c40c8395fd2a 100755 --- a/games/factorio_development.sh +++ b/games/factorio_development.sh @@ -429,6 +429,39 @@ function get_current_branch() { } +# +# Retrieves the mod name, as set in the info file. +# +# Arguments: +# +# $1 (base_dir) +# Base mod directory. +# +# Outputs: +# +# Mod name. +# +# Returns: +# +# 0 on success, 1 otherwise. +# +function get_mod_name() { + local base_dir="$1" + + local info_file mod_name + + info_file=$(get_info_file "$base_dir") || return 1 + + if ! mod_name=$(jq -r ".name" "$info_file") || [[ -z $mod_name ]]; then + error "Failed to obtain mod name from: $info_file" + return 1 + fi + + echo "$mod_name" + return 0 +} + + # Commands # ======== @@ -636,7 +669,7 @@ function command_build() { error "Could not parse mod info file: $info_file" return 1 fi - mod_name=$(jq -r ".name" "$info_file") + mod_name=$(get_mod_name "$base_dir") || return 1 mod_version=$(jq -r ".version" "$info_file") # Validate version string format. @@ -749,7 +782,7 @@ function command_release() { local version="$1" local base_dir="$2" - local info_file changelog_file build_config + local info_file changelog_file build_config changelog local main_branch current_branch release_branch build_config="$base_dir/build.cfg" @@ -829,12 +862,18 @@ function command_release() { # Switch back to development version. sed -i -e "s/$version/999.999.999/" "$info_file" - # shellcheck disable=SC2094 # changelog file will be read in its entirety via $(<) first. - cat > "$changelog_file" <<< "--------------------------------------------------------------------------------------------------- + changelog=$(cat < "$changelog_file" + # Commit the changes. if ! git -C "$base_dir" add "$changelog_file" "$info_file" || \ ! git -C "$base_dir" commit -m "Switched back to development version."; then @@ -861,19 +900,29 @@ $(< "$changelog_file") function command_abort_release() { local base_dir="$1" - local info_file changelog_file build_config + local info_file changelog_file build_config mod_name release_archive local current_branch release_branch version load_build_configuration "$base_dir" || return 1 main_branch=$(get_main_branch "$base_dir") || return 1 release_branch=$(get_current_branch "$base_dir") || return 1 + mod_name=$(get_mod_name "$base_dir") || return 1 version="${release_branch##release-}" + release_archive="${base_dir}/dist/${mod_name}_${version}.zip" if [[ ! $release_branch =~ ^release-[[:digit:]]+\.[[:digit:]]+\.[[:digit:]] ]]; then error "Current branch is not a release branch." return 1 fi + # Drop the release archive. + if [[ -f "${base_dir}/dist/${mod_name}_${version}.zip" ]] && + ! rm "$release_archive"; then + + error "Failed to remove the release file: $release_archive" + return 1 + fi + # Drop the tag. if [[ -n $(git -C "$base_dir" tag --list "${GIT_VERSION_TAG_PREFIX}${version}") ]] && ! git tag --delete "${GIT_VERSION_TAG_PREFIX}${version}"; then