Changeset - 70ab5cf613b4
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 years 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) First comment
games/factorio_development.sh
Show inline comments
 
@@ -426,12 +426,45 @@ function get_current_branch() {
 
    fi
 

	
 
    return 0
 
}
 

	
 

	
 
#
 
# 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
 
# ========
 

	
 
#
 
# Initialises mod directory structure.
 
#
 
@@ -633,13 +666,13 @@ function command_build() {
 

	
 
    # Extract modpack name and version
 
    if ! jq . "$info_file" > /dev/null; then
 
        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.
 
    if [[ ! $mod_version =~ ^[[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+$ ]]; then
 
        error "Invalid mod version read from info file: $mod_version"
 
        return 1
 
@@ -746,13 +779,13 @@ function command_build() {
 
#   0 on success, 1 otherwise.
 
#
 
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"
 

	
 
    # Read build configuration.
 
    # shellcheck disable=SC1090 # build configuration file is create per-mod directory
 
@@ -826,18 +859,24 @@ function command_release() {
 
        error "Failed to create release commit and tag."
 
        return 1
 
    fi
 

	
 
    # 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
 
        error "Failed to create developement commit."
 
        return 1
 
    fi
 
@@ -858,25 +897,35 @@ $(< "$changelog_file")
 
#
 
#   0 on success, 1 otherwise.
 
#
 
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
 

	
 
        error "Failed to drop the git tag: ${GIT_VERSION_TAG_PREFIX}${version}"
 
        return 1
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now