From 64c0878b0212ded3709313521c61f5611c3737f0 Mon Sep 17 00:00:00 2001 From: Sergey Morgunov Date: Wed, 4 May 2022 14:23:56 +0300 Subject: [PATCH] * java/scala parameters of CMD as simple comma separated string * Docs --- .github/workflows/cmd.yml | 20 +++++++- README.md | 100 +++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 57 deletions(-) diff --git a/.github/workflows/cmd.yml b/.github/workflows/cmd.yml index fbd307a..2e4c740 100644 --- a/.github/workflows/cmd.yml +++ b/.github/workflows/cmd.yml @@ -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 @@ -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 @@ -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 "" diff --git a/README.md b/README.md index eb2fb6b..7f99533 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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