diff --git a/.github/workflows/binary-check.yml b/.github/workflows/binary-check.yml index 334dcf6..16dda88 100644 --- a/.github/workflows/binary-check.yml +++ b/.github/workflows/binary-check.yml @@ -3,6 +3,10 @@ name: Validate Binary Compatibility on: workflow_call: inputs: + ref: + type: string + required: false + default: '' java: type: string required: false @@ -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 diff --git a/.github/workflows/sbt-matrix.yml b/.github/workflows/cmd.yml similarity index 54% rename from .github/workflows/sbt-matrix.yml rename to .github/workflows/cmd.yml index 2b956fc..0fa7df4 100644 --- a/.github/workflows/sbt-matrix.yml +++ b/.github/workflows/cmd.yml @@ -1,14 +1,24 @@ -name: SBT command on matrix Java/Scala versions +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: true + required: false + default: "8" scala: type: string - required: true + required: false + default: "" + add-dimensions: + type: string + required: false + default: "{}" include: type: string required: false @@ -34,22 +44,41 @@ on: default: "" jobs: + prepare-matrix: + name: Prepare Matrix + runs-on: ubuntu-20.04 + outputs: + matrix: ${{ steps.prepare-matrix.outputs.matrix }} + steps: + - id: prepare-matrix + run: | + add_dimensions=$(echo -n '${{ inputs.add-dimensions }}' | sed 's/^.*{//;s/}.*$//') # Remove leading { and trailing } + # 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: Scala ${{ matrix.scala }} & JDK ${{ matrix.java }} + name: ${{ toJSON(matrix) }} + needs: prepare-matrix runs-on: ubuntu-20.04 strategy: # WA: https://github.community/t/reusable-workflow-with-strategy-matrix/205676/6 - matrix: - java: ${{ fromJson(inputs.java) }} - scala: ${{ fromJson(inputs.scala) }} - include: ${{ fromJson(inputs.include) }} - exclude: ${{ fromJson(inputs.exclude) }} + 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 != '' @@ -59,14 +88,11 @@ jobs: id: coursier-cache uses: coursier/cache-action@v6.3 - - name: Saving cache-hit-coursier env variable - run: echo 'CACHE_HIT_COURSIER=${{ steps.coursier-cache.outputs.cache-hit-coursier }}' >> $GITHUB_ENV - - name: Custom Cache uses: actions/cache@v2 if: ${{ inputs.cache-key != '' && inputs.cache-path != '' }} with: - key: ${{ inputs.cache-key }} + key: ${{ format(inputs.cache-key, matrix.java) }} path: ${{ inputs.cache-path }} - name: Install Adoptium Temurin OpenJDK @@ -76,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 "" @@ -89,10 +116,14 @@ jobs: echo "ls -alFhR ~/.cache/coursier | grep play | grep jar" ls -alFhR ~/.cache/coursier | grep play | grep jar || true - - name: Run sbt command + - name: Convert matrix elements to environment variables + run: | + jq -n -r '$in | to_entries|map("MATRIX_\(.key|ascii_upcase)=\(.value|tostring)")|.[]' --argjson in '${{ toJSON(matrix) }}' >> $GITHUB_ENV + + - name: Run command run: ${{ inputs.cmd }} env: - SCALA_VERSION: ${{ matrix.scala }} + CACHE_HIT_COURSIER: ${{ steps.coursier-cache.outputs.cache-hit-coursier }} - name: Cleanup before cache shell: bash diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e58ed21..edf4ad0 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -3,6 +3,10 @@ name: Publish on: workflow_call: inputs: + ref: + type: string + required: false + default: '' java: type: string required: false @@ -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 diff --git a/.github/workflows/sbt.yml b/.github/workflows/sbt.yml deleted file mode 100644 index 2f54070..0000000 --- a/.github/workflows/sbt.yml +++ /dev/null @@ -1,90 +0,0 @@ -name: SBT command on single Java version - -on: - workflow_call: - inputs: - java: - 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 - default: "" - cache-path: - type: string - required: false - default: "" - -jobs: - cmd: - name: JDK ${{ inputs.java }} - runs-on: ubuntu-20.04 - 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 - id: coursier-cache - uses: coursier/cache-action@v6.3 - - - name: Saving cache-hit-coursier env variable - run: echo 'CACHE_HIT_COURSIER=${{ steps.coursier-cache.outputs.cache-hit-coursier }}' >> $GITHUB_ENV - - - 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 Adoptium Temurin OpenJDK - uses: coursier/setup-action@v1.2.0-M3 - with: - jvm: adoptium:${{ inputs.java }} - - - name: Print helpful configs and files and show environment - run: | - echo "$ cat /etc/sbt/jvmopts" - cat /etc/sbt/jvmopts || true - echo "" - echo "$ cat /etc/sbt/sbtopts" - cat /etc/sbt/sbtopts || true - echo "" - echo "$ env" - env - echo "ls -alFhR ~/.ivy2 | grep play | grep jar" - ls -alFhR ~/.ivy2 | grep play | grep jar || true - echo "ls -alFhR ~/.cache/coursier | grep play | grep jar" - ls -alFhR ~/.cache/coursier | grep play | grep jar || true - - - name: Run sbt command - run: ${{ inputs.cmd }} - env: - SCALA_VERSION: ${{ inputs.scala }} - - - name: Cleanup before cache - shell: bash - run: | - find $HOME/Library/Caches/Coursier/v1 -name "ivydata-*.properties" -delete || true - find $HOME/.ivy2/cache -name "ivydata-*.properties" -delete || true - find $HOME/.cache/coursier/v1 -name "ivydata-*.properties" -delete || true - find $HOME/.sbt -name "*.lock" -delete || true diff --git a/README.md b/README.md index eb2fb6b..7e05fb2 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/cmd.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,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 @@ -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**: @@ -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**: @@ -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/trigger-cache-invalidation.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