Changeset - b14d3faa45c4
[Not reviewed]
0 1 0
Branko Majic (branko) - 2 years ago 2022-08-21 15:41:25
branko@majic.rs
[factorio_development.sh] Added (personal) workaround for tag signing:

- Older versions of git (<2.23) do not have the tag.gpgSign
option. Try to emulate it by appending the --sign option if it is
set in git configuration.
1 file changed with 8 insertions and 1 deletions:
0 comments (0 inline, 0 general) First comment
games/factorio_development.sh
Show inline comments
 
@@ -757,197 +757,204 @@ function command_build() {
 
    rm -rf "$target_dir"
 

	
 
    success "Release built and placed under: $archive_file"
 
}
 

	
 

	
 
#
 
# Releases a mod version. Takes care of creating separate branch,
 
# making versioning changes/updates to mod information file and
 
# changelog, creating the tags, and even switching back the mod to
 
# development version.
 
#
 
# Arguments:
 
#
 
#   $1 (version)
 
#     Version of mod to release.
 
#
 
#   $2 (base_dir)
 
#     Base (top-level) directory with the mod files.
 
#
 
# Returns:
 
#
 
#   0 on success, 1 otherwise.
 
#
 
function command_release() {
 
    local version="$1"
 
    local base_dir="$2"
 

	
 
    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
 
    if [[ -f $build_config ]] && ! source "$build_config"; then
 
        error "Failed to load build configuration from: $build_config"
 
        return 1
 
    fi
 

	
 
    current_branch=$(git -C "$base_dir" rev-parse --abbrev-ref HEAD)
 
    release_branch="release-${version}"
 

	
 
    source_dir=$(get_source_directory "$base_dir") || return 1
 
    info_file=$(get_info_file "$base_dir") || return 1
 
    changelog_file=$(get_changelog_file "$base_dir") || return 1
 
    current_branch=$(get_current_branch "$base_dir") || return 1
 
    main_branch=$(get_main_branch "$base_dir") || return 1
 

	
 
    if [[ $current_branch != "$main_branch" ]]; then
 
        error "Releases must be based off of the main branch."
 
        return 1
 
    fi
 

	
 
    if [[ $(git -C "$base_dir" status --short) != "" ]]; then
 
        error "Releases must be based off of a clean git working tree."
 
        return 1
 
    fi
 

	
 
    if ! git -C "$base_dir" checkout -b "$release_branch"; then
 
        error "Failed to create release branch: $release_branch"
 
        return 1
 
    fi
 

	
 
    # Update versioning information in info file and changelog.
 
    sed -i -e "s/999.999.999/$version/" "$info_file" "$changelog_file"
 

	
 
    # Update release date.
 
    sed -i -e "s/9999-99-99/$(date +%Y-%m-%d)/" "$changelog_file"
 

	
 
    # Drop empty changelog sections. Changelog sections begin with two
 
    # whitespaces at line beginning, followed by a non-whitespace
 
    # character.
 
    #
 
    # First sed expression:
 
    #
 
    # 1. Finds a section line.
 
    # 2. Reads the next line and adds it to pattern space. If the next
 
    #    line is not a section line, outputs the section it found
 
    #    (P). Otherwise it deletes the matched section line (D).
 
    # 3. Finally, it checks if the next line read (in step 2) is also
 
    #    a section line, and if it is, repeats the process for it (has
 
    #    to be done via goto directive since sed cannot be told to
 
    #    re-read the lines once they have been read with the N
 
    #    directive).
 
    #
 
    # Second sed expression deals with empty sections at the end of
 
    # the file (special case).
 
    sed -i -E -e '/^  [^ ]/{: checknext; N; /\n   /P; D; /^  [^ ]/b checknext}' "$changelog_file"
 
    sed -i -z -E -e 's/\n  [^ \n]+\n$/\n/' "$changelog_file"
 

	
 
    # Build the release.
 
    if ! command_build "$base_dir"; then
 
        return 1
 
    fi
 

	
 
    # @WORKAROUND: For using git tag signing on older versions of git.
 
    if [[ $(git -C "$base_dir" config --get tag.gpgSign) == true ]]; then
 
        local git_tag_gpgsign=("--sign")
 
    else
 
        local git_tag_gpgsign=()
 
    fi
 

	
 
    # Commit the changes and create a tag. GIT_VERSION_TAG_PREFIX
 
    # comes from build configuration.
 
    if ! git -C "$base_dir" add "$changelog_file" "$info_file" || \
 
       ! git -C "$base_dir" commit --edit -m "Prepared release $version." || \
 
       ! git -C "$base_dir" tag -a -m "Release $version." "${GIT_VERSION_TAG_PREFIX}${version}"; then
 
       ! git -C "$base_dir" tag "${git_tag_gpgsign[@]}" -a -m "Release $version." "${GIT_VERSION_TAG_PREFIX}${version}"; then
 

	
 
        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"
 
    changelog=$(cat <<EOF
 
---------------------------------------------------------------------------------------------------
 
Version: 999.999.999
 
Date: 9999-99-99
 
  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
 

	
 
    return 0
 
}
 

	
 

	
 
#
 
# Aborts the current release process.
 
#
 
# Arguments:
 
#
 
#   $1 (base_dir)
 
#     Base (top-level) directory with the mod files.
 
#
 
# Returns:
 
#
 
#   0 on success, 1 otherwise.
 
#
 
function command_abort_release() {
 
    local base_dir="$1"
 

	
 
    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
 
    fi
 

	
 
    # Reset working directory, dropping eventual local changes.
 
    if ! git -C "$base_dir" reset --hard HEAD; then
 
        error "Failed to reset working directory."
 
        return 1
 
    fi
 

	
 
    # Switch back to main branch.
 
    if ! git -C "$base_dir" checkout "$main_branch"; then
 
        error "Failed to switch to main branch."
 
        return 1
 
    fi
 

	
 
    # Drop the release branch.
 
    if ! git -C "$base_dir" branch --delete --force "$release_branch"; then
 
        error "Failed to remove the release branch."
 
        return 1
 
    fi
 

	
 
    return 0
 
}
0 comments (0 inline, 0 general) First comment
You need to be logged in to comment. Login now