Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 30 additions & 56 deletions .github/prepare_release.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
#!/bin/bash -e

is_minor="$1" # type is "minor" or "patch"
is_patch="$2" # type is "minor" or "patch"
# The version to publish is read from LLama/LLamaSharp.csproj and used verbatim.
# Bump <Version> there in the release PR: whatever it says is exactly what ships.
version=$(dotnet msbuild ./LLama/LLamaSharp.csproj -getProperty:Version)
version="${version//[$'\t\r\n ']/}"

echo "is_minor: $is_minor"
echo "is_patch: $is_patch"
if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Could not read a valid version from LLama/LLamaSharp.csproj (got '$version')."
exit 1
fi

if [ "$is_minor" = true ] && [ "$is_patch" = true ]; then
echo "Only one of minor version and patch version should be specified."
echo "Releasing version: $version";

# Refuse to rebuild a version that is already on nuget.org, so a re-run of the
# workflow fails loudly instead of silently doing nothing. This job ends in a push
# to nuget.org, so if the API cannot be reached there is no point carrying on.
nuget_index="https://api.nuget.org/v3-flatcontainer/llamasharp/index.json"
if ! published=$(curl -sf --connect-timeout 10 --max-time 60 --retry 3 --retry-delay 5 "$nuget_index"); then
echo "Could not query nuget.org for the published versions of LLamaSharp."
echo "Refusing to release without that check, since the release publishes to nuget.org anyway."
exit 1
elif [ "$is_minor" = true ] && [ "$is_patch" = false ]; then
type="minor"
echo "decided to update minor version"
elif [ "$is_minor" = false ] && [ "$is_patch" = true ]; then
type="patch"
echo "decided to update patch version"
else
echo "At least one of minor version and patch version should be specified."
fi

if ! echo "$published" | grep -Fq '"versions"'; then
echo "Unexpected response from $nuget_index, expected a JSON document listing versions."
exit 1
fi

if echo "$published" | grep -Fq "\"$version\""; then
echo "LLamaSharp $version is already published on nuget.org."
echo "Bump <Version> in LLama/LLamaSharp.csproj before releasing again."
exit 1
fi

Expand All @@ -25,58 +38,19 @@ mkdir ./temp/runtimes;
cp ./LLama/runtimes ./temp -R;
cp ./LLama/runtimes/build/*.* ./temp/;

# get the current version
cd temp;
dotnet add package LLamaSharp;
version=$(dotnet list temp.csproj package | grep LLamaSharp);
# TODO: This didn´t work on osx...we need a solution
read -ra arr <<< "$version"
version="${arr[-1]}"
echo "The latest version: $version";


# update the version
if [[ $type == "minor" ]]; then
regex="[0-9]+\.([0-9]+)\.[0-9]+$"
if [[ $version =~ $regex ]]; then
b="${BASH_REMATCH[1]}"
b=$((b + 1))
updated_version="${version%%.*}.$b.0"
echo "Updated version: $updated_version"
else
echo "Invalid version format"
exit 1
fi
elif [[ $type == "patch" ]]; then
regex="([0-9]+)$"
if [[ $version =~ $regex ]]; then
c="${BASH_REMATCH[1]}"
c=$((c + 1))
updated_version="${version%.*}.$c"
echo "Updated version: $updated_version"
else
echo "Invalid version format"
exit 1
fi
else
echo "Invalid type"
exit 1
fi

cd ..
# pack the main package
dotnet pack ./LLama/LLamaSharp.csproj -c Release -o ./temp/ /p:PackageVersion=$updated_version /p:Version=$updated_version /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg;
dotnet pack ./LLama/LLamaSharp.csproj -c Release -o ./temp/ /p:PackageVersion=$version /p:Version=$version /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg;

# pack the backends
cd temp
for nuspec in *.nuspec
do
echo "Packing $nuspec"
nuget pack $nuspec -version $updated_version
nuget pack $nuspec -version $version
done

# write the version to the file
echo $updated_version > version.txt
echo $version > version.txt

cd ..
exit 0
2 changes: 1 addition & 1 deletion .github/workflows/release-minor-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
release-minor-trigger:
if: contains(github.event.pull_request.labels.*.name, 'minor-release') && !contains(github.event.pull_request.labels.*.name, 'patch-release')
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'minor-release') && !contains(github.event.pull_request.labels.*.name, 'patch-release')
runs-on: ubuntu-22.04

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-minor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
git fetch origin;

chmod +x ./.github/prepare_release.sh
./.github/prepare_release.sh true false
./.github/prepare_release.sh

- name: Upload packages artifacts
uses: actions/upload-artifact@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-patch-trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:

jobs:
release-patch-trigger:
if: contains(github.event.pull_request.labels.*.name, 'patch-release') && !contains(github.event.pull_request.labels.*.name, 'minor-release')
if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'patch-release') && !contains(github.event.pull_request.labels.*.name, 'minor-release')
runs-on: ubuntu-22.04

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-patch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
git fetch origin;

chmod +x ./.github/prepare_release.sh
./.github/prepare_release.sh false true
./.github/prepare_release.sh

- name: Upload packages artifacts
uses: actions/upload-artifact@v4
Expand Down
Loading