Skip to content

Commit

Permalink
feat: Add manifest installation script
Browse files Browse the repository at this point in the history
This script downloads the latest manifest from GitHub Releases.
With this manifest installed, the .NET SDK can locate and install
other workload packages.
  • Loading branch information
trungnt2910 committed Jul 22, 2023
1 parent 728c569 commit bf66a67
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,33 @@

An attempt to create a .NET SDK workload that provides the `net8.0-haiku` TFM.

## Installation

To install, run the `install-manifest.sh` script:

```sh
bash -c "$(curl -fsSL https://raw.githubusercontent.com/trungnt2910/dotnet-haiku/HEAD/install-manifest.sh)"
```

The script requires `dotnet`, `curl`, `jq`, and `unzip` to be installed and be available in `$PATH`.
It installs the latest version of the [advertising manifests](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-workload-install#advertising-manifests) for the Haiku workload.

After that, the `haiku` workload will be available for install like any other workload:

```sh
dotnet workload install haiku
```

Note that you have to subscribe to **[@trungnt2910](https://github.com/trungnt2910)**'s GitHub Packages feed.
If .NET for Haiku from the [dotnet-builds](https://github.com/trungnt2910/dotnet-builds/tree/master#installation) repository has already been installed, you have already subscribed to this feed.
Otherwise, run:

```sh
dotnet nuget add source --username your_github_username --password your_github_token --store-password-in-clear-text --name dotnet_haiku_nuget "https://nuget.pkg.github.com/trungnt2910/index.json"
```

`your_github_token` should be a [personal access token](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry#authenticating-to-github-packages) with at least the `read:packages` permission.

## Building instructions

### Clone this repository
Expand Down
89 changes: 89 additions & 0 deletions install-manifest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#!/bin/bash -e

DOTNET_PATH="dotnet"

if [ -z "$DOTNET_ROOT" ]; then
DOTNET_PATH=$(command -v dotnet)
else
DOTNET_PATH="$DOTNET_ROOT/dotnet"
fi

if [ -z "$DOTNET_PATH" ]; then
echo "Could not find dotnet. Install dotnet and try again."
exit 1
fi

echo "Using dotnet from $DOTNET_PATH"

DOTNET_VERSION=$(eval "$DOTNET_PATH --version")

echo "Detected .NET SDK version $DOTNET_VERSION"

set +e

prereleaseStart=$(($(expr index "$DOTNET_VERSION" "-") - 1))

if [ "$prereleaseStart" -gt 0 ]; then
firstDot=$(expr index "${DOTNET_VERSION:$(($prereleaseStart + 1)):${#DOTNET_VERSION}}" ".")
firstDot=$(($firstDot + $prereleaseStart))
secondDot=$(expr index "${DOTNET_VERSION:$((firstDot + 1)):${#DOTNET_VERSION}}" ".")

if [ "$secondDot" -eq 0 ]; then
secondDot="${#DOTNET_VERSION}"
else
secondDot=$(($secondDot + $firstDot))
fi

DOTNET_FEATURE_BAND="${DOTNET_VERSION:0:$secondDot}"
else
DOTNET_FEATURE_BAND="${DOTNET_VERSION:0:$((${#DOTNET_VERSION} - 2))}00"
fi

set -e

echo "Detected .NET SDK feature band $DOTNET_FEATURE_BAND"

GITHUB_SERVER_URL=${GITHUB_SERVER_URL:-"https://github.com"}
GITHUB_API_URL=${GITHUB_API_URL:-"https://api.github.com"}
GITHUB_REPOSITORY=${GITHUB_REPOSITORY:-"trungnt2910/dotnet-haiku"}

manifestName="trungnt2910.net.sdk.haiku"
manifestPackageName="$manifestName.manifest-$DOTNET_FEATURE_BAND"

manifestPackageVersion=""
releaseUrl="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/tag/"
pageNum=1
while [ -z "$manifestPackageVersion" ];
do
json=$(curl -s $GITHUB_API_URL/repos/$GITHUB_REPOSITORY/releases?page=$pageNum)
pageNum=$((pageNum + 1))
if [ $(echo $json | jq length) -eq 0 ]; then
# This means that we've passed the end and reached an empty array
break
fi
if [ $(echo $json | jq 'objects // {} | has("message")') == "true" ]; then
# API has return an error object
echo "Unable to fetch releases from GitHub API"
exit 2
fi
# Store array of revisions
revisions=($(echo $json | jq -e -r ".[] | .html_url | select(true)[${#releaseUrl}:]")) \
|| continue
manifestPackageVersion=${revisions[0]}
done

echo "Latest manifest package version is $manifestPackageVersion"

manifestPackageUrl="$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/releases/download/$manifestPackageVersion/$manifestPackageName.$manifestPackageVersion.nupkg"

echo "Downloading manifest package from $manifestPackageUrl"

manifestInstallDir="$(dirname "$DOTNET_PATH")/sdk-manifests/$DOTNET_FEATURE_BAND/$manifestName"

tmpFilePath="$(mktemp)"
curl -sL $manifestPackageUrl -u $GITHUB_USERNAME:$GITHUB_TOKEN -o $tmpFilePath
unzip -j $tmpFilePath 'data/*.*' -d $manifestInstallDir
rm $tmpFilePath

echo "Installed manifest package to $manifestInstallDir"
echo "Run '$DOTNET_PATH workload install haiku' to install the Haiku workload."

0 comments on commit bf66a67

Please sign in to comment.