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

Workflows improvements (ENVs, Caches, Include/Exclude) #4

Merged
merged 1 commit into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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) }}
Comment on lines +45 to +46
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the use case for this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just to support an existed GA matrix behavior.
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#example-including-additional-values-in-combinations
It can be useful in the future when we will want to have a more special matrix strategy than the cartesian product of two array with Java and Scala versions.

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/cache-action@v6.3

- 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/setup-action@v1.1.2
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/cache-action@v6.3

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
Comment on lines +41 to +44
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't that enough to just call sbt "-Dvar1=value" ++$SCALA_VERSION test?
Why do we need to set vars and let then be resolved?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, maybe it's not a good example. 😞
I'm trying to solve the restriction that in GA we can't set an ENV vars in parent workflow and then use theirs in reusable workflows 😞
Firstly, currently, the achievement of this is that if cmd is not a single line sbt command but some script, I don't need to set vars as arguments of this script. For example

cmd: "script/big-task.sh"
env: |
  VAR1=value
  VAR2=value

Secondly, when GA will support YAML Anchors (actions/runner#1182), we will try to use anchor with env vars in parent workflow and just add them to many jobs instead of copy&paste vars as now (see my draft for main repo playframework/playframework#11142). 🤞

```

### 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