Repository: analysis-dev/diktat (kotlin)

Issue:
Run CI tests on different OS
Github matrix builds can be used to run on win and macos too

Pull request:
### What's done:
* Split different diktat runners in functional_tests.yml
* Specify ubuntu version explicitly
* Functional tests are executed on different OS

### Fixme:
* [x] remove diktat and ktlint versions from `env` in `functional_tests.yml`, they are actually taken from poms, and their existence there is confusing. Should use github actions' env vars file instead.

This pull request closes #626

Patch:
diff --git a/.github/workflows/diktat.yml b/.github/workflows/diktat.yml
index afbcea297d..70d08e9c95 100644
--- a/.github/workflows/diktat.yml
+++ b/.github/workflows/diktat.yml
@@ -8,7 +8,7 @@ on:
 
 jobs:
   diktat_check:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
 
     steps:
       - uses: actions/checkout@v2.3.3
diff --git a/.github/workflows/diktat_snapshot.yml b/.github/workflows/diktat_snapshot.yml
index 6f7440672b..7ec79c34f4 100644
--- a/.github/workflows/diktat_snapshot.yml
+++ b/.github/workflows/diktat_snapshot.yml
@@ -11,7 +11,7 @@ env:
 
 jobs:
   diktat_snapshot_check:
-    runs-on: ubuntu-latest
+    runs-on: ubuntu-20.04
 
     steps:
       - uses: actions/checkout@v2.3.3


Test patch:
diff --git a/.github/workflows/functional_tests.yml b/.github/workflows/functional_tests.yml
index 1a87ccb3db..ef3c4c2995 100644
--- a/.github/workflows/functional_tests.yml
+++ b/.github/workflows/functional_tests.yml
@@ -7,74 +7,135 @@ on:
     branches: [ master ]
 
 env:
-  DIKTAT_VERSION: 0.1.7
-  KTLINT_VERSION: 0.39.0
   GRADLE_OPTS: -Dorg.gradle.daemon=false  # to speed up gradle run
 
 jobs:
-  run-functional-tests:
-    runs-on: ubuntu-latest
+  run_diktat_from_CLI:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ ubuntu-latest, windows-latest, macos-latest ]
 
     steps:
       - uses: actions/checkout@v2.3.3
 
-      - name: Setup environment
+      - name: Setup environment variables
         run: |
-          cat pom.xml | grep "<diktat-check.version>.*</diktat-check.version>" | head -1 |awk -F'[><]' '{ENVIRON[DIKTAT_VERSION]=$3 ; print ENVIRON[DIKTAT_VERSION]}'
-          cat pom.xml | grep "<ktlint.version>.*</ktlint.version>" | head -1 |awk -F'[><]' '{ENVIRON[KTLINT_VERSION]=$3 ; print ENVIRON[KTLINT_VERSION]}'
-          curl -sSLO https://github.com/pinterest/ktlint/releases/download/$KTLINT_VERSION/ktlint && chmod a+x ktlint
-          curl -sSLO https://github.com/cqfn/diKTat/releases/download/v$DIKTAT_VERSION/diktat-$DIKTAT_VERSION.jar
+          cat pom.xml | grep "<diktat-check.version>.*</diktat-check.version>" | head -1 | awk -F'[><]' '{ printf "DIKTAT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
+          cat pom.xml | grep "<ktlint.version>.*</ktlint.version>" | head -1 | awk -F'[><]' '{ printf "KTLINT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
+        shell: bash
 
+      - name: Setup environment
+        run: |
+          curl -sSLO https://github.com/pinterest/ktlint/releases/download/${{ env.KTLINT_VERSION }}/ktlint && chmod a+x ktlint
+          curl -sSLO https://github.com/cqfn/diKTat/releases/download/v${{ env.DIKTAT_VERSION }}/diktat-${{ env.DIKTAT_VERSION }}.jar
+        shell: bash
+        
       - name: Copy diktat-analysis.yml from release
         run: |
-          unzip -q -d tmp diktat-$DIKTAT_VERSION.jar
+          unzip -q -d tmp diktat-${{ env.DIKTAT_VERSION }}.jar
           DIKTAT_CONFIG=diktat-analysis.yml
-          md5sum $DIKTAT_CONFIG
           find tmp -name $DIKTAT_CONFIG -exec cp "{}" . \;
-          md5sum $DIKTAT_CONFIG
+        shell: bash
 
       - name: Run diKTat from cli
         continue-on-error: true
+        if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
+        run: |
+          ./ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar "examples/maven/src/main/kotlin/Test.kt" &> out
+        shell: bash
+
+      - name: Run diKTat from cli on windows
+        continue-on-error: true
+        if: runner.os == 'Windows'
         run: |
-          ./ktlint -R diktat-$DIKTAT_VERSION.jar "examples/maven/src/main/kotlin/Test.kt" &> out
+          java.exe -jar ktlint -R diktat-${{ env.DIKTAT_VERSION }}.jar "examples/maven/src/main/kotlin/Test.kt" > out.txt 2>&1
+        shell: cmd
 
       - name: Check output
         id: cli-check
         run: |
+          if [ -f out.txt ]; then mv out.txt out; fi
           cat out
           grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
+        shell: bash
 
-      - name: Run diKTat from gradle kotlin DSL
-        continue-on-error: true
-        working-directory: ./examples/gradle-kotlin-dsl
+  run_diktat_from_gradle:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ ubuntu-latest, windows-latest, macos-latest ]
+        dir: [ ./examples/gradle-kotlin-dsl, ./examples/gradle-groovy-dsl ]
+    steps:
+      - uses: actions/checkout@v2.3.3
+
+      - name: Setup environment variables
         run: |
-          gradle diktatCheck &> out
+          cat pom.xml | grep "<diktat-check.version>.*</diktat-check.version>" | head -1 | awk -F'[><]' '{ printf "DIKTAT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
+        shell: bash
 
-      - name: Check gradle from kotlin DSL
-        working-directory: ./examples/gradle-kotlin-dsl
+      - name: Setup environment
         run: |
-          cat out
-          grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
+          curl -sSLO https://github.com/cqfn/diKTat/releases/download/v${{ env.DIKTAT_VERSION }}/diktat-${{ env.DIKTAT_VERSION }}.jar
+          unzip -q -d tmp diktat-${{ env.DIKTAT_VERSION }}.jar
+          DIKTAT_CONFIG=diktat-analysis.yml
+          find tmp -name $DIKTAT_CONFIG -exec cp "{}" . \;
+        shell: bash
 
-      - name: Run diKTat from gradle groovy DSL
+      - name: Run diKTat from gradle
         continue-on-error: true
-        working-directory: ./examples/gradle-groovy-dsl
+        if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
+        working-directory: ${{ matrix.dir }}
         run: |
           gradle diktatCheck &> out
+        shell: bash
+
+      - name: Run diKTat from gradle on windows
+        continue-on-error: true
+        if: runner.os == 'Windows'
+        working-directory: ${{ matrix.dir }}
+        run: |
+          gradle.exe diktatCheck > out.txt 2>&1
+        shell: cmd
 
-      - name: Check gradle from groovy DSL
-        working-directory: ./examples/gradle-groovy-dsl
+      - name: Check gradle
+        working-directory: ${{ matrix.dir }}
         run: |
+          if [ -f out.txt ]; then mv out.txt out; fi
           cat out
           grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
+        shell: bash
+
+  run_diktat_from_maven:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ ubuntu-latest, windows-latest, macos-latest ]
+    steps:
+      - uses: actions/checkout@v2.3.3
+
+      - name: Setup environment variables
+        run: |
+          cat pom.xml | grep "<diktat-check.version>.*</diktat-check.version>" | head -1 | awk -F'[><]' '{ printf "DIKTAT_VERSION=%s\n",$3 }' >> $GITHUB_ENV
+        shell: bash
+
+      - name: Setup environment
+        run: |
+          curl -sSLO https://github.com/cqfn/diKTat/releases/download/v${{ env.DIKTAT_VERSION }}/diktat-${{ env.DIKTAT_VERSION }}.jar
+          unzip -q -d tmp diktat-${{ env.DIKTAT_VERSION }}.jar
+          DIKTAT_CONFIG=diktat-analysis.yml
+          find tmp -name $DIKTAT_CONFIG -exec cp "{}" . \;
+        shell: bash
 
       - name: Run diKTat from maven
         working-directory: ./examples/maven
         continue-on-error: true
         run: mvn -B diktat:check &> out
+        shell: bash
 
       - name: Check maven
         working-directory: ./examples/maven
         run: |
           cat out
           grep -E "\[VARIABLE_NAME_INCORRECT_FORMAT\]" out
+        shell: bash