Changeset - 70ab5cf613b4
[Not reviewed]
0 1 0
Branko Majic (branko) - 20 months ago 2022-08-21 15:37:21
branko@majic.rs
[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.
1 file changed with 56 insertions and 7 deletions:
0 comments (0 inline, 0 general)
games/factorio_development.sh
Show inline comments
 
@@ -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 <<EOF
 
---------------------------------------------------------------------------------------------------
 
Version: 999.999.999
 
Date: 9999-99-99
 
$(< "$changelog_file")
 
"
 
  Changes:
 
  Features:
 
  Bugfixes:
 
$(cat "$changelog_file")
 
EOF
 
                )
 
    echo "$changelog" > "$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
0 comments (0 inline, 0 general)