From 15b68d8b2afd56b4513fe2d5c89fbed93fbaddc8 Mon Sep 17 00:00:00 2001 From: Uladzislau Date: Sat, 13 Apr 2024 00:35:01 +0200 Subject: [PATCH] IJMP-1655 Build and release automation fixed Signed-off-by: Uladzislau --- .github/actions/setup/action.yml | 30 ---- .github/actions/sonar/action.yml | 10 +- .github/workflows/build.yml | 165 ++++++++++++++++++ .github/workflows/gradle.yml | 132 -------------- .github/workflows/release.yml | 120 +++++++++++++ .gitignore | 2 +- Jenkinsfile.groovy | 153 ---------------- build.gradle.kts | 12 +- .../formainframe/editor/EditorTestSpec.kt | 28 --- 9 files changed, 296 insertions(+), 356 deletions(-) delete mode 100644 .github/actions/setup/action.yml create mode 100644 .github/workflows/build.yml delete mode 100644 .github/workflows/gradle.yml create mode 100644 .github/workflows/release.yml delete mode 100644 Jenkinsfile.groovy diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml deleted file mode 100644 index 59d963cf..00000000 --- a/.github/actions/setup/action.yml +++ /dev/null @@ -1,30 +0,0 @@ -name: "Setup action" -description: "Prepares for execution - set up Java, Kotlin, Gradle" - -inputs: - jdkVersion: - description: "JDK version" - required: false - default: "17" - -runs: - using: "composite" - steps: - - name: Set up JDK ${{ inputs.jdkVersion }} - uses: actions/setup-java@v2 - with: - distribution: 'zulu' - java-version: ${{ inputs.jdkVersion }} - - - name: Setup Gradle - uses: gradle/gradle-build-action@v2 - with: - gradle-version: 7.6.1 - - - name: Grant execute permission for gradlew - run: chmod +x gradlew - shell: bash - -# - name: Bootstrap gradlew -# run: ./gradle/bootstrap/bootstrap_gradlew.sh -# shell: bash \ No newline at end of file diff --git a/.github/actions/sonar/action.yml b/.github/actions/sonar/action.yml index 0308de90..73780216 100644 --- a/.github/actions/sonar/action.yml +++ b/.github/actions/sonar/action.yml @@ -6,7 +6,7 @@ runs: using: composite steps: - name: Cache SonarCloud packages - uses: actions/cache@v1 + uses: actions/cache@v4 with: path: ~/.sonar/caches key: ${{ runner.os }}-sonar @@ -15,8 +15,8 @@ runs: - name: Code coverage and publish results shell: bash run: > - ./gradlew --info sonarqube + ./gradlew --info sonar -Dorg.gradle.jvmargs="-XX:MaxMetaspaceSize=512m" - -Dresults="build/reports/tests/test,build/test-results/test,build/reports/jacoco/test/html" - -Psonar.host.url=$SONAR_HOST_URL -Dsonar.login=$SONAR_TOKEN - -Dsonar.coverage.jacoco.xmlReportPaths="build/reports/jacoco.xml" \ No newline at end of file + -Dresults="build/reports/tests/test,build/test-results/test,build/reports/kover/html" + -Psonar.host.url=$SONAR_HOST_URL -Dsonar.token=$SONAR_TOKEN + -Dsonar.coverage.jacoco.xmlReportPaths="build/reports/kover/xml/report.xml" diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..bac65558 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,165 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Build + Test&Sonar + Verify + +on: [push, workflow_dispatch] + +permissions: + contents: read + +concurrency: + group: "${{ github.workflow }}-${{ github.ref }}" + cancel-in-progress: true + +jobs: + build: + runs-on: ubuntu-latest + outputs: + pluginVerifierHomeDir: ${{ steps.properties.outputs.pluginVerifierHomeDir }} + steps: + + - name: Checkout the plugin GitHub repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v2 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 11 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + + - name: Check repository content + shell: bash + run: pwd && ls -la + + - name: Fetch Gradle properties + id: properties + env: + AUTO_SNAPSHOT_VERSION: false + shell: bash + run: | + PROPERTIES="$(./gradlew properties --console=plain -q)" + + echo "pluginVerifierHomeDir=~/.pluginVerifier" >> $GITHUB_OUTPUT + + # prepare list of IDEs to use by plugin verifier: + ./gradlew listProductsReleases + + - name: Build plugin + shell: bash + run: ./gradlew buildPlugin + + - name: Prepare Plugin Artifact + id: artifact + shell: bash + run: | + cd ${{ github.workspace }}/build/distributions + FILENAME=`ls *.zip` + unzip "$FILENAME" -d content + echo "filename=${FILENAME:0:-4}" >> $GITHUB_OUTPUT + echo "zip artifact name:" + echo "$FILENAME" + + - name: Publish built plugin to artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ steps.artifact.outputs.filename }} + path: ./build/distributions/content/*/* + + test_and_sonar: + needs: [build] + runs-on: ubuntu-latest + steps: + + - name: Checkout the plugin GitHub repository + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 11 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + + - name: Run tests + shell: bash + run: ./gradlew test + + - name: Publish tests result to artifacts + uses: actions/upload-artifact@v4 + with: + name: tests-report + path: ${{ github.workspace }}/build/reports/tests + + - name: Publish code coverage report to artifacts + uses: actions/upload-artifact@v4 + with: + name: code-coverage-report + path: ${{ github.workspace }}/build/reports/kover/html + + - name: SonarCloud scans + continue-on-error: true + uses: ./.github/actions/sonar + env: + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} + + verify: + if: ${{ contains(github.ref, 'refs/heads/release/') }} + needs: [build] + runs-on: ubuntu-latest + steps: + + - name: Maximize Build Space + uses: jlumbroso/free-disk-space@main + with: + tool-cache: false + large-packages: false + + - name: Checkout the plugin GitHub repository + uses: actions/checkout@v4 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 11 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + + - name: Setup Plugin Verifier IDEs Cache + uses: actions/cache@v4 + with: + path: ${{ needs.build.outputs.pluginVerifierHomeDir }}/ides + key: plugin-verifier-${{ hashFiles('build/listProductsReleases.txt') }} + + - name: Verify plugin against IntelliJ IDEA IDE's + continue-on-error: true + shell: bash + run: ./gradlew runPluginVerifier -Dplugin.verifier.home.dir=${{ needs.build.outputs.pluginVerifierHomeDir }} + + - name: Collect Plugin Verifier Result + uses: actions/upload-artifact@v4 + with: + name: plugin-verifier-report + path: ${{ github.workspace }}/build/reports/pluginVerifier diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml deleted file mode 100644 index 8f96545b..00000000 --- a/.github/workflows/gradle.yml +++ /dev/null @@ -1,132 +0,0 @@ -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. -# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle - -name: Java CI with Gradle - -on: - workflow_dispatch: - -permissions: - contents: read - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout of github repository - uses: actions/checkout@v3 - - - name: Setup of environment - uses: ./.github/actions/setup - - - name: Check repository content - shell: bash - run: pwd && ls -la - - - name: Cache Gradle packages - uses: actions/cache@v1 - with: - path: ~/.gradle/caches - key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }} - restore-keys: ${{ runner.os }}-gradle - - - name: Build with Gradle - run: gradle wrapper && ./gradlew buildPlugin - shell: bash - - - name: Run tests - run: ./gradlew test - shell: bash - - - name: Sonarcloud scans - uses: ./.github/actions/sonar - env: - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - GITHUB_TOKEN: ${{ secrets.GIT_TOKEN }} - - - name: Publish built plugin - uses: actions/upload-artifact@v3 - with: - name: builtPlugin - path: ./build/distributions/ - - - deploy: - needs: build - - runs-on: XBY_IJMP_machine - - concurrency: test - environment: - name: test - url: http://178.172.233.157/plugin-builds/${{steps.extract_branch.outputs.BRANCH_NAME_FOR_DEPLOY}}/${{ steps.generate_file_name.outputs.NEW_FILE_NAME_FOR_DEPLOY }} - - steps: - - name: Extract branch name - id: extract_branch - shell: bash - run: > - echo "BRANCH_NAME_FOR_DEPLOY=${GITHUB_REF#refs/heads/}" >> $GITHUB_OUTPUT && - echo "BRANCH_NAME_LOCAL=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV && - echo "Github branch name is: $BRANCH_NAME_LOCAL" - - - name: Check current directory - shell: bash - run: pwd && ls -la - - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: builtPlugin - path: ./build/distributions/ - - - name: Check plugin built availability - shell: bash - run: ls -la ./build/distributions - - - name: Get name of build plugin archive - id: getting_file_name - shell: bash - run: > - CURRENT_FILE_PATH=$(echo $(find build -name "for-mainframe*")) && - echo "CURRENT_FILE_PATH=$CURRENT_FILE_PATH" >> $GITHUB_ENV && - echo "Name of current file: $CURRENT_FILE_PATH" - - - name: Generate new name for built plugin - id: generate_file_name - shell: bash - run: > - TEMP_VAR=$CURRENT_FILE_PATH - NEW_FILE_NAME_LOCAL="$(echo ${TEMP_VAR%.zip*})."$(date +"%Y-%m-%dT%H:%M:%S%:z" | tr ':' _)".zip" && - NEW_FILE_NAME_LOCAL=${NEW_FILE_NAME_LOCAL##*/} && - echo "NEW_FILE_NAME_LOCAL=$NEW_FILE_NAME_LOCAL" >> $GITHUB_ENV && - echo "Name of new file: $NEW_FILE_NAME_LOCAL" && - echo "NEW_FILE_NAME_FOR_DEPLOY=$NEW_FILE_NAME_LOCAL" >> $GITHUB_OUTPUT && - NEW_FILE_PATH="/var/www/plugin-builds/$BRANCH_NAME_LOCAL/$NEW_FILE_NAME_LOCAL" && - echo "NEW_FILE_PATH=$NEW_FILE_PATH" >> $GITHUB_ENV && - echo "Path to new file: $NEW_FILE_PATH" - - - name: Move built plugin to destination folder - shell: bash - run: > - mkdir -p /var/www/plugin-builds/$BRANCH_NAME_LOCAL && - mv $CURRENT_FILE_PATH $NEW_FILE_PATH - - - name: Sign archives - shell: bash - run: > - echo "use-agent" >> ~/.gnupg/gpg.conf && - echo "agent-write-to-file passed" && - echo "pinentry-mode loopback" >> ~/.gnupg/gpg.conf && - echo "pinentry-mode write to file passed" && - export GPG_TTY=$(tty) && - echo "export GPG tty variable passed" && - eval $(gpg-agent --daemon) && - echo "starting gpg-agent passed" && - gpg --batch --passphrase "${{ secrets.GPG_PASSPHRASE }}" --detach-sign --armor --output $NEW_FILE_PATH.asc $NEW_FILE_PATH \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..21ad5d92 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,120 @@ +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. +# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time. +# After the build stage is finished, it is ready to be published to the respective public repositories +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle + +name: Release + +on: + workflow_dispatch: + +jobs: + release: + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + steps: + + - name: Checkout the plugin GitHub repository + uses: actions/checkout@v4 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v2 + + - name: Setup Java + uses: actions/setup-java@v4 + with: + distribution: zulu + java-version: 11 + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v3 + with: + gradle-home-cache-cleanup: true + + - name: Fetch Gradle properties + id: properties + shell: bash + run: | + PROPERTIES="$(./gradlew properties --console=plain -q)" + PLUGIN_VERSION_FULL="$(echo "$PROPERTIES" | grep "^pluginVersion:" | cut -f2- -d ' ')" + PLUGIN_VERSION_SEMVER="$(echo "$PLUGIN_VERSION_FULL" | grep -Po '\d{1,}\.\d{1,}\.\d{1,}')" + CURR_COMMIT="$(git rev-parse HEAD)" + + echo "pluginVersionFull: $PLUGIN_VERSION_FULL" + echo "pluginVersionSemVer: $PLUGIN_VERSION_SEMVER" + echo "currCommit: $CURR_COMMIT" + + echo "pluginVersionFull=$PLUGIN_VERSION_FULL" >> $GITHUB_OUTPUT + echo "pluginVersionSemVer=$PLUGIN_VERSION_SEMVER" >> $GITHUB_OUTPUT + echo "currCommit=$CURR_COMMIT" >> $GITHUB_OUTPUT + + - name: Publish Plugin + env: + INTELLIJ_SIGNING_PUBLISH_TOKEN: ${{ secrets.INTELLIJ_SIGNING_PUBLISH_TOKEN }} + INTELLIJ_SIGNING_CERTIFICATE_CHAIN: ${{ secrets.INTELLIJ_SIGNING_CERTIFICATE_CHAIN }} + INTELLIJ_SIGNING_PRIVATE_KEY: ${{ secrets.INTELLIJ_SIGNING_PRIVATE_KEY }} + INTELLIJ_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.INTELLIJ_SIGNING_PRIVATE_KEY_PASSWORD }} + run: ./gradlew publishPlugin + + - name: Prepare release notes + id: release_notes + shell: bash + run: | + CHANGELOG="$(./gradlew getChangelog -q)" + + echo 'version_release_notes<> $GITHUB_OUTPUT + echo "$CHANGELOG" >> $GITHUB_OUTPUT + echo 'EOF' >> $GITHUB_OUTPUT + + echo "Release notes to be added:" + echo "$CHANGELOG" + + - name: Create new tag and release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + git tag ${{ steps.properties.outputs.pluginVersionFull }} + git push origin ${{ steps.properties.outputs.pluginVersionFull }} + gh release create ${{ steps.properties.outputs.pluginVersionFull }} --title ${{ steps.properties.outputs.pluginVersionFull }} --target ${{ steps.properties.outputs.currCommit }} -F- <() - val str = text.substring(pointer) - val pos = str.indexOfFirst { it !in 'A'..'z' } - if (pos != -1) { - decoderResultIsError = true - pointer += pos - back.position(pointer) - pointer++ - } else { - decoderResultIsError = false - back.put(str) - } - decoderResultMock - } - every { decoderResultMock.isError } answers { decoderResultIsError } - - val descriptors = lossyEncodingInspection.checkFile(psiFileMock, inspectionManagerMock, isOnTheFly) - - assertSoftly { descriptors?.size shouldBe 1 } - assertSoftly { descriptors?.get(0)?.textRangeInElement shouldBe TextRange(3, 5) } - } should("check file where not all characters are decoded back") { text = "qwerty."