Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework sdkman-action #11

Merged
merged 30 commits into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
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
19 changes: 19 additions & 0 deletions .github/workflows/sdkmanrc-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Test using .sdkmanrc
on: [push, pull_request]

jobs:
build:
name: "JDK ${{ matrix.version }} on ${{ matrix.os }}"
strategy:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Setup Java ${{ matrix.version }}
id: sdkman
uses: ./
- name: Verify Java ${{ matrix.version }}
run: java -version
12 changes: 7 additions & 5 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ jobs:
fail-fast: false
matrix:
os: [ macos-latest, ubuntu-latest, windows-latest ]
version: [ 15.0.1.hs-adpt, 15.0.1.j9-adpt, 15.0.1-amzn, 15.0.1-zulu, 15.0.1.fx-zulu, 15.0.1.fx-librca, 15.0.1-librca, 15.0.1-open, 15.0.1-sapmchn ]
version: [ 17.0.0.35.1-amzn, 21.3.0.r17-grl, 17-open, 17.0.0.fx-librca, 17.0.0-librca, 17.0.0-ms, 17.0.0-oracle, 17-sapmchn, 17.0.0-tem, 17.0.0-zulu, 17.0.0.fx-zulu ]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Setup Java ${{ matrix.version }}
id: sdkman
uses: ./
with:
candidate: java
version: ${{ matrix.version }}
- uses: actions/setup-java@v1
- uses: actions/setup-java@v3
if: ${{ matrix.os == 'windows-latest' }}
id: setup-java
with:
java-version: 15
distribution: 'jdkfile'
java-version: 17
jdkFile: ${{ steps.sdkman.outputs.file }}
- name: Verify Java ${{ matrix.version }}
run: java --version
run: java -version
1 change: 1 addition & 0 deletions .sdkmanrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java=17.0.0-tem
33 changes: 28 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
# SDKMAN! action

This action installs any `candidate` via [sdkman](https://sdkman.io/).
This action installs any `candidate` via [sdkman](https://sdkman.io/). If inputs are provided then the
`sdk install <candidate> <version>` command will be executed. Otherwise, the `sdk env install` command will be executed.

## Inputs

### `candidate`

**Required** The name of the candidate to install.
**Optional** The name of the candidate to install.

### `version`

**Required** The version of the candidate to install.
**Optional** The version of the candidate to install.

## Outputs

Expand All @@ -20,16 +21,38 @@ Filename of the downloaded archive.

## Example usage

Install a specific candidate in using Windows runner:

```yaml
- uses: sdkman/sdkman-action@master
id: sdkman
with:
candidate: java
version: 15.0.0-amzn
- uses: actions/setup-java@v1
- uses: actions/setup-java@v3
id: setup-java
with:
distribution: 'jdkfile'
java-version: 15.0.0
jdkFile: ${{ steps.sdkman.outputs.file }}
- run: java --version
- run: java -version
```

Install a specific candidate in Linux or macOS runner:

```yaml
- uses: sdkman/sdkman-action@master
id: sdkman
with:
candidate: java
version: 15.0.0-amzn
- run: java -version
```

Install candidates from `.sdkmanrc` in Linux or macOS runner:

```yaml
- uses: sdkman/sdkman-action@master
id: sdkman
- run: java -version
```
59 changes: 22 additions & 37 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ description: 'Download the sdk you want to install'
inputs:
candidate:
description: 'The name of the candidate to install'
required: true
required: false
version:
description: 'The version of the candidate to install'
required: true
required: false
outputs:
file:
description: 'Filename of the downloaded archive.'
Expand All @@ -18,42 +18,27 @@ runs:
- id: sdkman
shell: bash
run: |
candidate=${{ inputs.candidate }}
version=${{ inputs.version }}
platform=$(uname)
base_name="${candidate}-${version}"

function __sdkman_echo_debug() {
if [[ "$sdkman_debug_mode" == 'true' ]]; then
echo "$1"
fi
}

function __sdkman_echo() {
if [[ "$sdkman_colour_enable" == 'false' ]]; then
echo -e "$2"
else
echo -e "\033[1;$1$2\033[0m"
fi
}

function __sdkman_echo_green() {
__sdkman_echo "32m" "$1"
}

if [ $RUNNER_OS == 'Linux' ] || [ $RUNNER_OS == 'macOS' ]; then
binary_input="/tmp/${base_name}.bin"
zip_output="/tmp/${base_name}.zip"

curl -L -o $binary_input https://api.sdkman.io/2/broker/download/$candidate/$version/$platform
post_installation_hook=hook_post_${candidate}_${version}.sh
curl -o "$post_installation_hook" https://api.sdkman.io/2/hooks/post/$candidate/$version/$platform
source $post_installation_hook
__sdkman_post_installation_hook
if [[ $RUNNER_OS == 'Linux' || $RUNNER_OS == 'macOS' ]]; then
export SDKMAN_DIR="$HOME/.sdkman" && curl -s "https://get.sdkman.io?rcupdate=false" | bash
if [[ -z "${{ inputs.candidate }}" && -z "${{ inputs.version }}" ]]; then
source $HOME/.sdkman/bin/sdkman-init.sh && sdk env install
else
candidate=${{ inputs.candidate }}
version=${{ inputs.version }}
source $HOME/.sdkman/bin/sdkman-init.sh && sdk install $candidate $version
fi
for child_dir in $(find "$SDKMAN_DIR/candidates" -mindepth 1 -maxdepth 1 -type d); do
echo "$child_dir/current/bin" >> $GITHUB_PATH
done
echo "file=" >> $GITHUB_OUTPUT
else
candidate=${{ inputs.candidate }}
version=${{ inputs.version }}
platform=$(uname)
base_name="${candidate}-${version}"

zip_output="$base_name.zip"
curl -L -o $zip_output https://api.sdkman.io/2/broker/download/$candidate/$version/$platform

echo "file=$zip_output" >> $GITHUB_OUTPUT
fi

echo "file=$zip_output" >> $GITHUB_OUTPUT