Skip to content

Commit

Permalink
Merge pull request #82 from doomchild/release/2.18.0
Browse files Browse the repository at this point in the history
Release/2.18.0
  • Loading branch information
doomchild authored Jul 26, 2024
2 parents 615ae2d + 2790d0b commit 2477906
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 5 deletions.
102 changes: 102 additions & 0 deletions ci/promote
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
#!/usr/bin/env bash
# shellcheck disable=SC2155 # Declare and assign separately to avoid masking return values.
# shellcheck disable=SC2207 # Prefer mapfile or read -a to split command output.

##
# Setup environment.
#
# @see https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
##
set -o errexit # Exit immediately if pipeline fails.
set -o errtrace # Subshells inherit ERR trap.
set -o pipefail # Return last value of failing pipeline.

declare PROJECT_HOME="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd .. && pwd)"

cd "${PROJECT_HOME}" || exit 1;

__commit_all_changes () {
local nextVersion=${1}

git add -A \
&& git commit --message "Version bump to ${nextVersion}"
}

__create_release_branch () {
local nextVersion=${1}

git checkout -b "release/${nextVersion}" origin/dev
}

__get_current_version () {
jq --raw-output '.version' < "${PROJECT_HOME}/project-metadata.json"
}

__get_hashes () {
git log --format=%H --grep="^Revert" --invert-grep --no-merges origin/dev ^origin/main
}

__get_semvers () {
git log --format=%b --grep="^Revert" --invert-grep --no-merges origin/dev ^origin/main \
| grep -i "semver" \
| tr '[:upper:]' '[:lower:]' \
| cut -d ":" -f 2
}

__get_max_semver () {
__get_semvers | sort --unique | head --lines 1
}

__get_next_version () {
semver --increment "$(__get_max_semver)" "$(__get_current_version)"
}

__has_matching_counts () {
local hashes=$(__get_hashes)
local semvers=$(__get_semvers)

if [[ "${#hashes[@]}" -eq "${#semvers[@]}" ]]; then
echo true
else
echo false
fi
}

__update_version () {
local nextVersion=${1}

jq --arg version "${nextVersion}" '.version = $version' "${PROJECT_HOME}/project-metadata.json" > "${PROJECT_HOME}/temp-metadata.json" \
&& mv "${PROJECT_HOME}/temp-metadata.json" "${PROJECT_HOME}/project-metadata.json"
}

__promote () {
local hashes=$(__get_hashes)
local semvers=$(__get_semvers)
local currentBranch=$(git rev-parse --abbrev-ref HEAD)
local currentVersion=$(__get_current_version)
local maxSemVer=$(__get_max_semver)
local nextVersion=$(__get_next_version)
local semVers=($(__get_semvers))
local semVersJoined=$(printf ",%s" "${semVers[@]}")

echo "Current Version: ${currentVersion}" 1>&2
echo "SemVer Levels: ${semVersJoined:1}" 1>&2
echo "Max SemVer: ${maxSemVer}" 1>&2
echo "Next Version: ${nextVersion}" 1>&2

if [[ "${currentBranch}" == "dev" ]]; then
if [[ $(__has_matching_counts) == true ]]; then
__create_release_branch "${nextVersion}" \
&& __update_version "${nextVersion}" \
&& __commit_all_changes "${nextVersion}"
else
echo "error: Expected count of ${#semvers[@]} semvers to match count of ${#hashes[@]} hashes" 1>&2
exit 1
fi
else
echo "error: Expected current branch to be dev; found ${currentBranch}" 1>&2
exit 1
fi
}

__promote
2 changes: 1 addition & 1 deletion project-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "task-chaining",
"description": "Extension methods to System.Threading.Task to allow Promise-like chaining",
"title": "TaskChaining",
"version": "2.17.0",
"version": "2.18.0",
"ciEnvironment": {
"variables": [
{
Expand Down
8 changes: 4 additions & 4 deletions src/TaskExtras.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ private static Task<T> DoRetry<T>(
/// <typeparam name="T">The underlying type of the tasks in <paramref name="tasks"/>.</typeparam>
/// <param name="tasks">The collection of tasks to partition.</param>
/// <returns>A tuple of the partitioned tasks.</returns>
public static Task<(IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled)> Partition<T>(
public static Task<(IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled)> Partition<T>(
IEnumerable<Task<T>> tasks
)
{
return tasks.Aggregate<Task<T>, Task<(IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled)>>(
Task.FromResult(((IEnumerable<Task<T>>)new List<Task<T>>(), (IEnumerable<Task<T>>)new List<Task<T>>())),
ZipTasksWith<T, (IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled), (IEnumerable<Task<T>> Faulted, IEnumerable<Task<T>> Fulfilled), Exception>
return tasks.Aggregate<Task<T>, Task<(IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled)>>(
Task.FromResult(((IReadOnlyList<Task<T>>)new List<Task<T>>(), (IReadOnlyList<Task<T>>)new List<Task<T>>())),
ZipTasksWith<T, (IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled), (IReadOnlyList<Task<T>> Faulted, IReadOnlyList<Task<T>> Fulfilled), Exception>
(
(values, v) => (values.Faulted, values.Fulfilled.Append(Task.FromResult(v)).ToList()),
(values, v) => (values.Faulted.Append<Task<T>>(Task.FromException<T>(v)).ToList(), values.Fulfilled)
Expand Down

0 comments on commit 2477906

Please sign in to comment.