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
* Add `ref` parameter to any workflows for checkout to special branch, tag or SHA
  • Loading branch information
ihostage committed May 5, 2022
1 parent fa0917a commit b8373dd
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 66 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/binary-check.yml
Expand Up @@ -3,6 +3,10 @@ name: Validate Binary Compatibility
on:
workflow_call:
inputs:
ref:
type: string
required: false
default: ''
java:
type: string
required: false
Expand All @@ -14,10 +18,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0
ref: ${{ inputs.ref }}

- name: Coursier Cache
id: coursier-cache
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/cmd.yml
Expand Up @@ -3,10 +3,18 @@ name: Command with a default JVM, coursier caching and an optional matrix
on:
workflow_call:
inputs:
ref:
type: string
required: false
default: ''
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 +53,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/quotes by newline | drop empty | quotation | join by comma
java=$(echo -n '${{inputs.java}}' | sed 's/[[:blank:],"]\+/\n/g' | awk NF | sed 's/^..*$/"&"/' | sed ':a; N; $!ba; s/\n/,/g')
scala=$(echo -n '${{inputs.scala}}' | sed 's/[[:blank:],"]\+/\n/g' | awk NF | 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 All @@ -55,10 +74,11 @@ jobs:
matrix: ${{fromJson(needs.prepare-matrix.outputs.matrix)}}
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0
ref: ${{ inputs.ref }}

- name: Set ENV variables
if: inputs.env != ''
Expand All @@ -82,6 +102,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
7 changes: 6 additions & 1 deletion .github/workflows/publish.yml
Expand Up @@ -3,6 +3,10 @@ name: Publish
on:
workflow_call:
inputs:
ref:
type: string
required: false
default: ''
java:
type: string
required: false
Expand All @@ -23,10 +27,11 @@ jobs:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v3
with:
# we don't know what commit the last tag was it's safer to get entire repo so previousStableVersion resolves
fetch-depth: 0
ref: ${{ inputs.ref }}

- name: Coursier Cache
id: coursier-cache
Expand Down
115 changes: 54 additions & 61 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,34 @@ 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 |
|-------------------|-------|--------------------|---------|---------------------------------------------------|
| ref | 2.0.0 | :exclamation: | '' | Branch, tag or SHA for checkout |
| 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 All @@ -102,9 +74,10 @@ This workflow is used for publishing snapshots artifacts to [Sonatype Snapshots]

**Parameters**:

| Parameter | Since | Required | Default | Description |
|-----------|-------|--------------------|---------|--------------------|
| java | 1.0.0 | :heavy_minus_sign: | 8 | _AdoptJDK_ version |
| Parameter | Since | Required | Default | Description |
|-----------|-------|--------------------|---------|------------------------------------|
| ref | 2.0.0 | :exclamation: | '' | Branch, tag or SHA for checkout |
| java | 1.0.0 | :heavy_minus_sign: | 8 | _AdoptJDK_ version |

**Secrets**:

Expand Down Expand Up @@ -142,9 +115,10 @@ This workflow is used for validate binary compatibility the current version.

**Parameters**:

| Parameter | Since | Required | Default | Description |
|-----------|-------|--------------------|---------|--------------------|
| java | 1.0.0 | :heavy_minus_sign: | 8 | _AdoptJDK_ version |
| Parameter | Since | Required | Default | Description |
|-----------|-------|--------------------|---------|------------------------------------|
| ref | 2.0.0 | :exclamation: | '' | Branch, tag or SHA for checkout |
| java | 1.0.0 | :heavy_minus_sign: | 8 | _AdoptJDK_ version |

**How to use**:

Expand Down Expand Up @@ -175,6 +149,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 b8373dd

Please sign in to comment.