Skip to content

Commit

Permalink
* java/scala parameters of CMD as simple comma separated string
Browse files Browse the repository at this point in the history
* Docs
  • Loading branch information
ihostage committed May 4, 2022
1 parent fa0917a commit 64c0878
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 57 deletions.
20 changes: 18 additions & 2 deletions .github/workflows/cmd.yml
Expand Up @@ -6,7 +6,11 @@ on:
java:
type: string
required: false
default: "[ 8 ]"
default: "8"
scala:
type: string
required: false
default: ""
add-dimensions:
type: string
required: false
Expand Down Expand Up @@ -45,7 +49,18 @@ jobs:
- id: prepare-matrix
run: |
add_dimensions=$(echo -n '${{ inputs.add-dimensions }}' | sed 's/^.*{//;s/}.*$//') # Remove leading { and trailing }
echo ::set-output name=matrix::{\"java\":$(echo '${{ inputs.java }}'), $(echo ${add_dimensions:+$add_dimensions,})\"include\":$(echo '${{ inputs.include }}'), \"exclude\":$(echo '${{ inputs.exclude }}')}
# input java/scala | replace whitespaces/commas by newline | quotation | join by comma
java=$(echo -n '${{inputs.java}}' | sed 's/[[:blank:],]\+/\n/g' | sed 's/^..*$/"&"/' | sed ':a; N; $!ba; s/\n/,/g')
scala=$(echo -n '${{inputs.scala}}' | sed 's/[[:blank:],]\+/\n/g' | sed 's/^..*$/"&"/' | sed ':a; N; $!ba; s/\n/,/g')
matrix="{"
matrix+="\"java\": [$java],"
[[ ! -z "$scala" ]] && matrix+="\"scala\": [$scala],"
matrix+="$(echo ${add_dimensions:+$add_dimensions,})"
matrix+="\"include\":$(echo -n '${{ inputs.include }}'),"
matrix+="\"exclude\":$(echo -n '${{ inputs.exclude }}')"
matrix+="}"
echo $matrix
echo ::set-output name=matrix::$(echo $matrix)
cmd:
name: ${{ toJSON(matrix) }}
needs: prepare-matrix
Expand Down Expand Up @@ -82,6 +97,7 @@ jobs:

- name: Print helpful configs and files and show environment
run: |
echo "Matrix: ${{ toJSON(matrix) }}"
echo "$ cat /etc/sbt/jvmopts"
cat /etc/sbt/jvmopts || true
echo ""
Expand Down
100 changes: 45 additions & 55 deletions README.md
Expand Up @@ -5,51 +5,20 @@ This repository contains a few configurations of GitHub features. For example a

## GitHub Actions Reusing Workflows

* [Single SBT task](#single-sbt-task)
* [Java/Scala matrix SBT task](#javascala-matrix-sbt-task)
* [Universal CMD task](#universal-cmd-task)
* [Publishing to Sonatype](#publishing-to-sonatype)
* [Validate Binary Compatibility](#validate-binary-compatibility)
* [Mark Pull Request as Ready To Merge](#mark-pull-request-as-ready-to-merge)
* [Clear Cache](#clear-cache)

### Single SBT task
### Universal CMD task

This workflow is used for running a single SBT task. It can to use for running an any BASH script or command, but we don't recommend doing that.
This workflow is used for running any CMD task on matrix of Java versions and other dimensions.

**Path**: [`.github/workflows/sbt.yml`](.github/workflows/sbt.yml)
Every matrix dimension will be access by environment variable like `MATRIX_$(uppercase(dimension_name))` (for example `MATRIX_JAVA`).

**Image**: [Ubuntu 20.04](https://hub.docker.com/layers/ubuntu/library/ubuntu/20.04/images/sha256-57df66b9fc9ce2947e434b4aa02dbe16f6685e20db0c170917d4a1962a5fe6a9?context=explore)

**Uses actions**:
* [Coursier/Setup Action](https://github.com/coursier/setup-action)
* [Coursier/Cache Action](https://github.com/coursier/cache-action)

**Parameters**:

| Parameter | Since | Required | Default | Description |
|------------|-------|--------------------|---------|----------------------|
| cmd | 1.0.0 | :exclamation: | - | Running command |
| java | 1.0.0 | :heavy_minus_sign: | 8 | _AdoptJDK_ version |
| scala | 1.0.0 | :heavy_minus_sign: | '' | _Scala_ version |
| cache-key | 1.0.0 | :heavy_minus_sign: | '' | Key of custom cache |
| cache-path | 1.0.0 | :heavy_minus_sign: | '' | Path of custom cache |
| env | 1.0.0 | :heavy_minus_sign: | '' | Custom ENV vars |

**How to use**:

```yaml
uses: playframework/.github/.github/workflows/sbt.yml@v1
with:
cmd: sbt "-Dvar1=$VAR_1" "-Dvar2=$VAR_2" ++$SCALA_VERSION test
env: |
VAR_1=value
VAR_2=value
```

### Java/Scala matrix SBT task

This workflow is used for running an SBT task on matrix of Java/Scala versions.

**Path**: [`.github/workflows/sbt-matrix.yml`](.github/workflows/sbt-matrix.yml)
**Path**: [`.github/workflows/sbt-matrix.yml`](.github/workflows/cmd.yml)

**Image**: [Ubuntu 20.04](https://hub.docker.com/layers/ubuntu/library/ubuntu/20.04/images/sha256-57df66b9fc9ce2947e434b4aa02dbe16f6685e20db0c170917d4a1962a5fe6a9?context=explore)

Expand All @@ -59,31 +28,33 @@ This workflow is used for running an SBT task on matrix of Java/Scala versions.

**Parameters**:

| Parameter | Since | Required | Default | Description |
|------------|-------|--------------------|---------|----------------------|
| cmd | 1.0.0 | :exclamation: | - | Running command |
| java | 1.0.0 | :exclamation: | - | _AdoptJDK_ version |
| scala | 1.0.0 | :exclamation: | - | _Scala_ version |
| include | 1.0.0 | :heavy_minus_sign: | [] | Matrix include's |
| exclude | 1.0.0 | :heavy_minus_sign: | [] | Matrix exclude's |
| cache-key | 1.0.0 | :heavy_minus_sign: | '' | Key of custom cache |
| cache-path | 1.0.0 | :heavy_minus_sign: | '' | Path of custom cache |
| env | 1.0.0 | :heavy_minus_sign: | '' | Custom ENV vars |
| Parameter | Since | Required | Default | Description |
|-------------------|-------|--------------------|---------|---------------------------------------------------|
| cmd | 2.0.0 | :exclamation: | - | Running command |
| java | 2.0.0 | :exclamation: | 8 | _AdoptJDK_ version (space/comma delimited list) |
| scala | 2.0.0 | :exclamation: | '' | _Scala_ version (space/comma delimited list) |
| add-dimensions | 2.0.0 | :exclamation: | '' | Other matrix dimensions (json object) |
| include | 2.0.0 | :heavy_minus_sign: | [] | Matrix include's (json object array) |
| exclude | 2.0.0 | :heavy_minus_sign: | [] | Matrix exclude's (json object array) |
| cache-key | 2.0.0 | :heavy_minus_sign: | '' | Key of custom cache |
| cache-path | 2.0.0 | :heavy_minus_sign: | '' | Path of custom cache |
| env | 2.0.0 | :heavy_minus_sign: | '' | Custom ENV vars |


**How to use**:

```yaml
uses: playframework/.github/.github/workflows/sbt-matrix.yml@v1
uses: playframework/.github/.github/workflows/cmd.yml@v2
with:
java: >-
[ "11", "8" ]
scala: >-
[ "2.12.15", "2.13.8", "3.0.2" ]
cmd: sbt "-Dvar1=$VAR_1" "-Dvar2=$VAR_2" ++$SCALA_VERSION test
java: 11, 8
scala: 2.12.15, 2.13.8, 3.0.2
add-dimensions: >-
{
"color": [ "red", "green"]
}
cmd: sbt "-Dcustom_var=$CUSTOM_VAR" "-Dcolor=$MATRIX_COLOR" "-Djava=$MATRIX_JAVA" ++$MATRIX_SCALA test
env: |
VAR_1=value
VAR_2=value
CUSTOM_VAR=value
```

### Publishing to Sonatype
Expand Down Expand Up @@ -175,6 +146,25 @@ needs: # Should be latest
uses: playframework/.github/.github/workflows/rtm.yml@v1
```

### Clear Cache

This workflow is used for clearing cache. Run this workflow manually from _Actions_ page.

**Path**: [`.github/workflows/sbt.yml`](.github/workflows/trigger-cache-invalidation.yml)

**Image**: [Ubuntu 20.04](https://hub.docker.com/layers/ubuntu/library/ubuntu/20.04/images/sha256-57df66b9fc9ce2947e434b4aa02dbe16f6685e20db0c170917d4a1962a5fe6a9?context=explore)

**Uses actions**:
* [Actions/Cache](https://github.com/actions/cache)

**No Parameters**

**How to use**:

```yaml
uses: playframework/.github/.github/workflows/trigger-cache-invalidation.yml@v1
```

## GitHub Actions Starter workflows

TODO

0 comments on commit 64c0878

Please sign in to comment.