Skip to content

Commit

Permalink
Add option to install specific version
Browse files Browse the repository at this point in the history
  • Loading branch information
EdwarDDay committed Jan 4, 2025
1 parent bb13910 commit 568c1dd
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/test_install_script.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ jobs:
runner:
- ubuntu-24.04
- macos-14
version:
- '0.2.0'
- '0.3.0'
- '0.4.0'
- ''
exclude:
- runner: macos-14
version: 0.2.0
- runner: macos-14
version: 0.3.0
runs-on: ${{ matrix.runner }}
steps:
- name: checkout
Expand All @@ -24,10 +34,17 @@ jobs:
java-version: 17

- name: install latest version
if: ${{ matrix.version == '' }}
run: sudo --preserve-env ./install.sh
env:
GH_TOKEN: ${{ github.token }}

- name: install specific version
if: ${{ matrix.version != '' }}
run: sudo --preserve-env ./install.sh --release-version ${{ matrix.version }}
env:
GH_TOKEN: ${{ github.token }}

- name: setup socket
run: |
sudo mkdir -p /var/run/kss/
Expand Down
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@
- option to install via release archive file
- option to set local maven repository settings
- version and help command line option
- option to specify install version explicitly

### Changed

- updated various dependencies
- default user for macos set to _www

## [0.4.0]
## [0.4.0] - 2024-08-25

### Added

- MacOS option in install script

## [0.3.0]
## [0.3.0] - 2024-08-18

### Added

Expand Down
38 changes: 32 additions & 6 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function usageText {
echo ' curl-authenticated - use curl authenticated with the token from the --token option'
echo ' curl - use curl without token - needs jq to parse rest response'
echo ' archive=<archive> - use tar archive as release'
echo '-v/--release-version Specify explicit release version (uses latest version by default)'
echo "-s/--service-directory[$service_directory]"
echo ' directory for service files'
echo "-c/--configuration-directory[$configuration_directory]"
Expand All @@ -92,6 +93,7 @@ function usage {
}

authorization_token=''
release_version=''
release_fetch_mode_set='false'

while [[ $# -gt 0 ]]; do
Expand Down Expand Up @@ -124,6 +126,14 @@ while [[ $# -gt 0 ]]; do
usage 'the --directory option needs an argument'
fi
;;
-v|--release-version)
if [ "$value" ]; then
release_version="$value"
shift
else
usage 'the --release-version option needs an argument'
fi
;;
-r|--release-fetch-mode)
release_fetch_mode_set='true'
case $value in
Expand Down Expand Up @@ -207,6 +217,10 @@ if [ "${release_fetch_mode}" == 'curl-authenticated' ] && [ "${authorization_tok
usage "'--release-fetch-mode' with option 'curl-authenticated' needs also '--token' to be specified"
fi

if [ "${release_fetch_mode}" == 'archive' ] && [ "${release-version}" != '' ]; then
usage "'--release-fetch-mode' with option 'archive' doesn't support a specific release version (--release-version option)"
fi

if [ "${release_fetch_mode}" == 'unknown' ]; then
usage "please specify '--release-fetch-mode' as no default option was found"
fi
Expand Down Expand Up @@ -254,13 +268,24 @@ fi

github_args=(--location ${authorization_args[@]+"${authorization_args[@]}"} --header 'X-GitHub-Api-Version: 2022-11-28')

# shellcheck disable=SC2016
query='query ($user: String!, $repo: String!) { repository(owner: $user, name: $repo) { latestRelease { releaseAssets(first: 10) { nodes { contentType url } } } } }'
if [ -z "$release_version" ]; then
release_rest_path='latest'
# shellcheck disable=SC2016
query='query ($user: String!, $repo: String!) { repository(owner: $user, name: $repo) { latestRelease { releaseAssets(first: 10) { nodes { contentType url } } } } }'
else
release_rest_path="tags/$release_version"
# shellcheck disable=SC2016
query='query ($user: String!, $repo: String!, $release: String!) { repository(owner: $user, name: $repo) { release(tagName: $release) { releaseAssets(first: 10) { nodes { contentType url } } } } }'
fi

function extractUrlFromGraphqlQuery() {
local response=$1
if [[ -n $(command -v jq || echo '') ]]; then
jq --raw-output '.data.repository.latestRelease.releaseAssets.nodes | map(select(.contentType == "application/gzip"))[0].url' <<< "$response"
if [ -z "$release_version" ]; then
jq --raw-output '.data.repository.latestRelease.releaseAssets.nodes | map(select(.contentType == "application/gzip"))[0].url' <<< "$response"
else
jq --raw-output '.data.repository.release.releaseAssets.nodes | map(select(.contentType == "application/gzip"))[0].url' <<< "$response"
fi
else
local response_tmp="${response#*\"contentType\":\"application\/gzip\",\"url\":\"}"
echo "${response_tmp%%\"*}"
Expand All @@ -281,7 +306,7 @@ archive)
;;
gh)
echo 'download latest release data via gh commandline tool' >&2
response="$(gh api graphql -F 'user=EdwarDDay' -F 'repo=kotlin-server-scripts' -f "query=$query")"
response="$(gh api graphql -F 'user=EdwarDDay' -F 'repo=kotlin-server-scripts' -F "release=$release_version" -f "query=$query")"
url="$(extractUrlFromGraphqlQuery "$response")"
downloadBinary
;;
Expand All @@ -291,7 +316,8 @@ curl-authenticated)
\"query\":\"$query\",
\"variables\":{
\"user\":\"EdwarDDay\",
\"repo\":\"kotlin-server-scripts\"
\"repo\":\"kotlin-server-scripts\",
\"release\":\"$release_version\"
}
}"
response="$(curl --request POST "${github_args[@]}" --fail --silent --url 'https://api.github.com/graphql' --data "$data")"
Expand All @@ -301,7 +327,7 @@ curl-authenticated)
# curl
*)
echo 'download latest release data via github rest endpoint and jq' >&2
url="$(curl --request GET "${github_args[@]}" --fail --silent --url 'https://api.github.com/repos/EdwarDDay/kotlin-server-scripts/releases/latest' | jq --raw-output '.assets | map(select(.content_type == "application/gzip"))[0].url')"
url="$(curl --request GET "${github_args[@]}" --fail --silent --url "https://api.github.com/repos/EdwarDDay/kotlin-server-scripts/releases/$release_rest_path" | jq --raw-output '.assets | map(select(.content_type == "application/gzip"))[0].url')"
downloadBinary
esac

Expand Down

0 comments on commit 568c1dd

Please sign in to comment.