Skip to content

Commit

Permalink
Merge pull request #4 from ihostage/sharable-actions
Browse files Browse the repository at this point in the history
Workflows improvements (ENVs, Caches, Include/Exclude)
  • Loading branch information
mkurz authored Apr 10, 2022
2 parents fa1c8b3 + 3dfc68d commit 15f8284
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/sbt-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,29 @@ on:
scala:
type: string
required: true
include:
type: string
required: false
default: "[]"
exclude:
type: string
required: false
default: "[]"
cmd:
type: string
required: true
env:
type: string
required: false
default: ""
cache-key:
type: string
required: false
default: ""
cache-path:
type: string
required: false
default: ""

jobs:
cmd:
Expand All @@ -22,16 +42,29 @@ jobs:
matrix:
java: ${{ fromJson(inputs.java) }}
scala: ${{ fromJson(inputs.scala) }}
include: ${{ fromJson(inputs.include) }}
exclude: ${{ fromJson(inputs.exclude) }}
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Set ENV variables
if: inputs.env != ''
run: echo '${{ inputs.env }}' >> $GITHUB_ENV

- name: Coursier Cache
uses: coursier/[email protected]

- name: Custom Cache
uses: actions/cache@v2
if: ${{ inputs.cache-key != '' && inputs.cache-path != '' }}
with:
key: ${{ inputs.cache-key }}
path: ${{ inputs.cache-path }}

- name: Install AdoptOpenJDK
uses: coursier/[email protected]
with:
Expand Down
14 changes: 14 additions & 0 deletions .github/workflows/sbt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,17 @@ on:
type: string
required: false
default: 8
scala:
type: string
required: false
default: ""
cmd:
type: string
required: true
env:
type: string
required: false
default: ""
cache-key:
type: string
required: false
Expand All @@ -30,6 +38,10 @@ jobs:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0

- name: Set ENV variables
if: inputs.env != ''
run: echo '${{ inputs.env }}' >> $GITHUB_ENV

- name: Coursier Cache
uses: coursier/[email protected]

Expand All @@ -47,3 +59,5 @@ jobs:

- name: Run sbt command
run: ${{ inputs.cmd }}
env:
SCALA_VERSION: ${{ inputs.scala }}
28 changes: 21 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,20 @@ This workflow is used for running a single SBT task. It can to use for running a
|------------|-------|--------------------|---------|----------------------|
| 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 test
cmd: sbt "-Dvar1=$VAR_1" "-Dvar2=$VAR_2" ++$SCALA_VERSION test
env: |
VAR_1=value
VAR_2=value
```
### Java/Scala matrix SBT task
Expand All @@ -53,11 +58,17 @@ 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 |
| 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 |


**How to use**:

Expand All @@ -68,7 +79,10 @@ with:
[ "11", "8" ]
scala: >-
[ "2.12.15", "2.13.8", "3.0.2" ]
cmd: sbt test
cmd: sbt "-Dvar1=$VAR_1" "-Dvar2=$VAR_2" ++$SCALA_VERSION test
env: |
VAR_1=value
VAR_2=value
```

### Publishing to Sonatype
Expand Down

0 comments on commit 15f8284

Please sign in to comment.