Skip to content

Commit c1a97bb

Browse files
authored
Add option to install specific version
PR: #53
1 parent bb13910 commit c1a97bb

File tree

3 files changed

+49
-8
lines changed

3 files changed

+49
-8
lines changed

.github/workflows/test_install_script.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ jobs:
1212
runner:
1313
- ubuntu-24.04
1414
- macos-14
15+
version:
16+
- '0.3.0'
17+
- '0.4.0'
18+
- ''
19+
exclude:
20+
- runner: macos-14
21+
version: 0.3.0
1522
runs-on: ${{ matrix.runner }}
1623
steps:
1724
- name: checkout
@@ -24,10 +31,17 @@ jobs:
2431
java-version: 17
2532

2633
- name: install latest version
34+
if: ${{ matrix.version == '' }}
2735
run: sudo --preserve-env ./install.sh
2836
env:
2937
GH_TOKEN: ${{ github.token }}
3038

39+
- name: install specific version
40+
if: ${{ matrix.version != '' }}
41+
run: sudo --preserve-env ./install.sh --release-version ${{ matrix.version }}
42+
env:
43+
GH_TOKEN: ${{ github.token }}
44+
3145
- name: setup socket
3246
run: |
3347
sudo mkdir -p /var/run/kss/

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@
1010
- option to install via release archive file
1111
- option to set local maven repository settings
1212
- version and help command line option
13+
- option to specify install version explicitly
1314

1415
### Changed
1516

1617
- updated various dependencies
1718
- default user for macos set to _www
1819

19-
## [0.4.0]
20+
## [0.4.0] - 2024-08-25
2021

2122
### Added
2223

2324
- MacOS option in install script
2425

25-
## [0.3.0]
26+
## [0.3.0] - 2024-08-18
2627

2728
### Added
2829

install.sh

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function usageText {
7070
echo ' curl-authenticated - use curl authenticated with the token from the --token option'
7171
echo ' curl - use curl without token - needs jq to parse rest response'
7272
echo ' archive=<archive> - use tar archive as release'
73+
echo '-v/--release-version Specify explicit release version (uses latest version by default)'
7374
echo "-s/--service-directory[$service_directory]"
7475
echo ' directory for service files'
7576
echo "-c/--configuration-directory[$configuration_directory]"
@@ -92,6 +93,7 @@ function usage {
9293
}
9394

9495
authorization_token=''
96+
release_version=''
9597
release_fetch_mode_set='false'
9698

9799
while [[ $# -gt 0 ]]; do
@@ -124,6 +126,14 @@ while [[ $# -gt 0 ]]; do
124126
usage 'the --directory option needs an argument'
125127
fi
126128
;;
129+
-v|--release-version)
130+
if [ "$value" ]; then
131+
release_version="$value"
132+
shift
133+
else
134+
usage 'the --release-version option needs an argument'
135+
fi
136+
;;
127137
-r|--release-fetch-mode)
128138
release_fetch_mode_set='true'
129139
case $value in
@@ -207,6 +217,10 @@ if [ "${release_fetch_mode}" == 'curl-authenticated' ] && [ "${authorization_tok
207217
usage "'--release-fetch-mode' with option 'curl-authenticated' needs also '--token' to be specified"
208218
fi
209219

220+
if [ "${release_fetch_mode}" == 'archive' ] && [ "${release_version}" != '' ]; then
221+
usage "'--release-fetch-mode' with option 'archive' doesn't support a specific release version (--release-version option)"
222+
fi
223+
210224
if [ "${release_fetch_mode}" == 'unknown' ]; then
211225
usage "please specify '--release-fetch-mode' as no default option was found"
212226
fi
@@ -254,13 +268,24 @@ fi
254268

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

257-
# shellcheck disable=SC2016
258-
query='query ($user: String!, $repo: String!) { repository(owner: $user, name: $repo) { latestRelease { releaseAssets(first: 10) { nodes { contentType url } } } } }'
271+
if [ -z "$release_version" ]; then
272+
release_rest_path='latest'
273+
# shellcheck disable=SC2016
274+
query='query ($user: String!, $repo: String!) { repository(owner: $user, name: $repo) { latestRelease { releaseAssets(first: 10) { nodes { contentType url } } } } }'
275+
else
276+
release_rest_path="tags/$release_version"
277+
# shellcheck disable=SC2016
278+
query='query ($user: String!, $repo: String!, $release: String!) { repository(owner: $user, name: $repo) { release(tagName: $release) { releaseAssets(first: 10) { nodes { contentType url } } } } }'
279+
fi
259280

260281
function extractUrlFromGraphqlQuery() {
261282
local response=$1
262283
if [[ -n $(command -v jq || echo '') ]]; then
263-
jq --raw-output '.data.repository.latestRelease.releaseAssets.nodes | map(select(.contentType == "application/gzip"))[0].url' <<< "$response"
284+
if [ -z "$release_version" ]; then
285+
jq --raw-output '.data.repository.latestRelease.releaseAssets.nodes | map(select(.contentType == "application/gzip"))[0].url' <<< "$response"
286+
else
287+
jq --raw-output '.data.repository.release.releaseAssets.nodes | map(select(.contentType == "application/gzip"))[0].url' <<< "$response"
288+
fi
264289
else
265290
local response_tmp="${response#*\"contentType\":\"application\/gzip\",\"url\":\"}"
266291
echo "${response_tmp%%\"*}"
@@ -281,7 +306,7 @@ archive)
281306
;;
282307
gh)
283308
echo 'download latest release data via gh commandline tool' >&2
284-
response="$(gh api graphql -F 'user=EdwarDDay' -F 'repo=kotlin-server-scripts' -f "query=$query")"
309+
response="$(gh api graphql -F 'user=EdwarDDay' -F 'repo=kotlin-server-scripts' -F "release=$release_version" -f "query=$query")"
285310
url="$(extractUrlFromGraphqlQuery "$response")"
286311
downloadBinary
287312
;;
@@ -291,7 +316,8 @@ curl-authenticated)
291316
\"query\":\"$query\",
292317
\"variables\":{
293318
\"user\":\"EdwarDDay\",
294-
\"repo\":\"kotlin-server-scripts\"
319+
\"repo\":\"kotlin-server-scripts\",
320+
\"release\":\"$release_version\"
295321
}
296322
}"
297323
response="$(curl --request POST "${github_args[@]}" --fail --silent --url 'https://api.github.com/graphql' --data "$data")"
@@ -301,7 +327,7 @@ curl-authenticated)
301327
# curl
302328
*)
303329
echo 'download latest release data via github rest endpoint and jq' >&2
304-
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')"
330+
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')"
305331
downloadBinary
306332
esac
307333

0 commit comments

Comments
 (0)