Repository: analysis-dev/diktat (kotlin)

Issue:
Run functional tests with diktat snapshot build
We can merge diktat_snapshot_check and functional_tests into a single workflow, which will in the first job deploy diktat-snapshot to github packages.

Pull request:
### What's done:
* Upload diktat.jar from build_and_test
* Run CLI diktat using snapshot jar
* Run all tests on different platforms
* Removed functional_tests.yml

This pull request closes #625

Patch:
diff --git a/examples/maven/pom.xml b/examples/maven/pom.xml
index b703cfe7c7..ef5f201c07 100644
--- a/examples/maven/pom.xml
+++ b/examples/maven/pom.xml
@@ -7,12 +7,16 @@
     <packaging>pom</packaging>
     <version>1.0.0-SNAPSHOT</version>
 
+    <properties>
+        <diktat.version>0.1.7</diktat.version>
+    </properties>
+
     <build>
         <plugins>
             <plugin>
                 <groupId>org.cqfn.diktat</groupId>
                 <artifactId>diktat-maven-plugin</artifactId>
-                <version>0.1.7</version>
+                <version>${diktat.version}</version>
                 <configuration>
                     <diktatConfigFile>diktat-analysis.yml</diktatConfigFile>
                     <inputs>
diff --git a/pom.xml b/pom.xml
index b375c45593..4a5cf7850d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -66,6 +66,7 @@
         <module>diktat-gradle-plugin</module>
     </modules>
 
+    <!-- Even though deployment is handled by nexus plugin, this section is required for it's operation -->
     <distributionManagement>
         <snapshotRepository>
             <id>ossrh</id>
@@ -200,6 +201,11 @@
                     <artifactId>maven-plugin-plugin</artifactId>
                     <version>3.6.0</version>
                 </plugin>
+                <plugin>
+                    <groupId>org.apache.maven.plugins</groupId>
+                    <artifactId>maven-failsafe-plugin</artifactId>
+                    <version>3.0.0-M5</version>
+                </plugin>
                 <plugin>
                     <groupId>org.codehaus.mojo</groupId>
                     <artifactId>versions-maven-plugin</artifactId>


Test patch:
diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml
index ad8a117897..6dbc1c6113 100644
--- a/.github/workflows/build_and_test.yml
+++ b/.github/workflows/build_and_test.yml
@@ -4,11 +4,12 @@ on:
   pull_request
 
 jobs:
-  test:
-    name: Unit Test
+  build_and_test_with_code_coverage:
+    name: Build, test and upload code coverage
     runs-on: ubuntu-18.04
 
     steps:
+      # actions/checkout v1.* is needed for correct codecov upload, see github issues for details
       - uses: actions/checkout@v1
       - name: Set up JDK 11
         uses: actions/setup-java@v1
@@ -31,3 +32,91 @@ jobs:
           file: ./*/target/site/jacoco/jacoco.xml
           flags: unittests
           fail_ci_if_error: true # optional (default = false)
+      - name: Upload diktat jar
+        uses: actions/upload-artifact@v2
+        with:
+          name: diktat-ruleset
+          path: diktat-ruleset/target/diktat-*.jar
+          # no need to store artifact longer, it is used only by dependant jobs
+          retention-days: 1
+
+  run_diktat_from_CLI:
+    name: Run diktat via CLI
+    runs-on: ${{ matrix.os }}
+    needs: build_and_test_with_code_coverage
+    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 "<version>.*</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
+        shell: bash
+
+      - name: Download diktat jar
+        uses: actions/download-artifact@v2
+        with:
+          name: diktat-ruleset
+
+      - 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: |
+          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
+
+  build_and_test:
+    name: Build and test
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        os: [ ubuntu-latest, windows-latest, macos-latest ]
+    steps:
+      - uses: actions/checkout@v2.3.3
+      - name: Set up JDK 11
+        uses: actions/setup-java@v1
+        with:
+          java-version: 1.11
+      - name: Cache local Maven repository
+        uses: actions/cache@v2
+        with:
+          path: ~/.m2/repository
+          key: ${{ runner.os }}-maven-build-${{ hashFiles('**/pom.xml') }}
+          restore-keys: |
+            ${{ runner.os }}-maven-build-
+
+      - name: Maven Install
+        if: ${{ runner.os == 'Linux' || runner.os == 'macOS' }}
+        run: |
+          mvn -B clean install
+        shell: bash
+
+      - name: Maven Install on windows
+        if: runner.os == 'Windows'
+        run: |
+          mvn -B clean install
+        shell: cmd
diff --git a/.github/workflows/functional_tests.yml b/.github/workflows/functional_tests.yml
deleted file mode 100644
index ef3c4c2995..0000000000
--- a/.github/workflows/functional_tests.yml
+++ /dev/null
@@ -1,141 +0,0 @@
-name: Run functional tests
-
-on:
-  push:
-    branches: [ master ]
-  pull_request:
-    branches: [ master ]
-
-env:
-  GRADLE_OPTS: -Dorg.gradle.daemon=false  # to speed up gradle run
-
-jobs:
-  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 variables
-        run: |
-          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-${{ env.DIKTAT_VERSION }}.jar
-          DIKTAT_CONFIG=diktat-analysis.yml
-          find tmp -name $DIKTAT_CONFIG -exec cp "{}" . \;
-        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: |
-          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
-
-  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: |
-          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 gradle
-        continue-on-error: true
-        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
-        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