diff --git a/.github/release-drafter.yml b/.github/release-drafter.yml new file mode 100644 index 0000000..fbb00b4 --- /dev/null +++ b/.github/release-drafter.yml @@ -0,0 +1,19 @@ +name-template: 'v$NEXT_PATCH_VERSION' +# tag-template: 'v$NEXT_PATCH_VERSION' +categories: + - title: '🚀 Features' + labels: + - 'feature' + - 'enhancement' + - title: '🐛 Bug Fixes' + labels: + - 'fix' + - 'bugfix' + - 'bug' + - title: '🧰 Maintenance' + label: 'chore' +change-template: '- $TITLE @$AUTHOR (#$NUMBER)' +template: | + ## Changes + + $CHANGES diff --git a/.github/workflows/cd.yaml b/.github/workflows/cd.yaml new file mode 100644 index 0000000..1b35752 --- /dev/null +++ b/.github/workflows/cd.yaml @@ -0,0 +1,73 @@ +# Note: additional setup is required, see https://www.jenkins.io/redirect/continuous-delivery-of-plugins + +name: cd +on: + push: + branches: master + +jobs: + validate: + runs-on: ubuntu-latest + outputs: + should_release: ${{ steps.verify-ci-status.outputs.result == 'success' && steps.interesting-categories.outputs.interesting == 'true' }} + steps: + - name: Check out + uses: actions/checkout@v2.4.0 + with: + fetch-depth: 0 + + - name: Verify CI status + uses: jenkins-infra/verify-ci-status-action@v1.2.0 + id: verify-ci-status + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + output_result: true + + - name: Get Project Version from pom.xml + uses: entimaniac/read-pom-version-action@1.0.0 + id: getVersion + + - name: Release Drafter + uses: release-drafter/release-drafter@v5 +# if: steps.verify-ci-status.outputs.result == 'success' + with: + name: next + tag: ${{ steps.getVersion.outputs.version }} + version: ${{ steps.getVersion.outputs.version }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Check interesting categories + uses: jenkins-infra/interesting-category-action@v1.0.0 + id: interesting-categories +# if: steps.verify-ci-status.outputs.result == 'success' + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + release: + runs-on: ubuntu-latest + needs: [validate] +# if: needs.validate.outputs.should_release == 'true' + steps: + - name: Check out + uses: actions/checkout@v2.4.0 + with: + fetch-depth: 0 + - name: Set up JDK 8 + uses: actions/setup-java@v2.5.0 + with: + distribution: temurin + java-version: 8 + - name: Check Secrets + env: + DEBUG_USERNAME: ${{ secrets.MAVEN_USERNAME }} + DEBUG_TOKEN: ${{ secrets.MAVEN_TOKEN }} + run: | + echo $DEBUG_USERNAME + echo $DEBUG_TOKEN + - name: Release + uses: jenkins-infra/jenkins-maven-cd-action@v1.2.0 + with: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }} + MAVEN_TOKEN: ${{ secrets.MAVEN_TOKEN }} diff --git a/.gitignore b/.gitignore index 74dc619..83f2ba2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,9 @@ *.iml work target -config \ No newline at end of file +config +bin +.settings +.project +.classpath +.factorypath \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..e0f15db --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "automatic" +} \ No newline at end of file diff --git a/LICENSE b/LICENSE index aa42681..5998072 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018 Katalon Studio +Copyright (c) 2018-2022 Katalon Inc. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pom.xml b/pom.xml index 4719908..a21dcc1 100644 --- a/pom.xml +++ b/pom.xml @@ -11,10 +11,10 @@ org.jenkins-ci.plugins katalon - 1.0.36 + 1.0.37 hpi Katalon Plugin - https://github.com/jenkinsci/katalon-plugin + https://github.com/katalon-studio/katalon-studio-jenkins-plugin @@ -45,11 +45,6 @@ - - devalex88 - Alex - dev.alex.88@gmail.com - @@ -57,7 +52,7 @@ scm:git:git@github.com:jenkinsci/${project.artifactId}-plugin.git https://github.com/jenkinsci/${project.artifactId}-plugin HEAD - + diff --git a/src/main/java/com/katalon/jenkins/plugin/KatalonUtils.java b/src/main/java/com/katalon/jenkins/plugin/KatalonUtils.java deleted file mode 100644 index 87d04cf..0000000 --- a/src/main/java/com/katalon/jenkins/plugin/KatalonUtils.java +++ /dev/null @@ -1,207 +0,0 @@ -package com.katalon.jenkins.plugin; - -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.ObjectMapper; -import hudson.FilePath; -import hudson.model.BuildListener; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardCopyOption; -import java.util.Arrays; -import java.util.List; - -class KatalonUtils { - - private static final String RELEASES_LIST = - "https://raw.githubusercontent.com/katalon-studio/katalon-studio/master/releases.json"; - - private static KatalonVersion getVersionInfo(BuildListener buildListener, String versionNumber) throws IOException { - - URL url = new URL(RELEASES_LIST); - - String os = OsUtils.getOSVersion(buildListener); - - LogUtils.log(buildListener, "Retrieve Katalon Studio version: " + versionNumber + ", OS: " + os); - - ObjectMapper objectMapper = new ObjectMapper(); - List versions = objectMapper.readValue(url, new TypeReference>() { - }); - - LogUtils.log(buildListener, "Number of releases: " + versions.size()); - - for (KatalonVersion version : versions) { - if ((version.getVersion().equals(versionNumber)) && (version.getOs().equalsIgnoreCase(os))) { - String containingFolder = version.getContainingFolder(); - if (containingFolder == null) { - String fileName = version.getFilename(); - String fileExtension = ""; - if (fileName.endsWith(".zip")) { - fileExtension = ".zip"; - } else if (fileName.endsWith(".tar.gz")) { - fileExtension = ".tar.gz"; - } - containingFolder = fileName.replace(fileExtension, ""); - version.setContainingFolder(containingFolder); - } - LogUtils.log(buildListener, "Katalon Studio is hosted at " + version.getUrl() + "."); - return version; - } - } - return null; - } - - private static void downloadAndExtract( - BuildListener buildListener, String versionNumber, File targetDir) - throws IOException, InterruptedException { - - KatalonVersion version = KatalonUtils.getVersionInfo(buildListener, versionNumber); - - String versionUrl = version.getUrl(); - - LogUtils.log( - buildListener, - "Downloading Katalon Studio from " + versionUrl + ". It may take a few minutes."); - - URL url = new URL(versionUrl); - - try (InputStream inputStream = url.openStream()) { - Path temporaryFile = Files.createTempFile("Katalon-" + versionNumber, ""); - Files.copy( - inputStream, - temporaryFile, - StandardCopyOption.REPLACE_EXISTING); - FilePath temporaryFilePath = new FilePath(temporaryFile.toFile()); - FilePath targetDirPath = new FilePath(targetDir); - if (versionUrl.contains(".zip")) { - temporaryFilePath.unzip(targetDirPath); - } else if (versionUrl.contains(".tar.gz")) { - temporaryFilePath.untar(targetDirPath, FilePath.TarCompression.GZIP); - } else { - throw new IllegalStateException(); - } - } - } - - private static File getKatalonFolder(String version) { - String path = System.getProperty("user.home"); - - Path p = Paths.get(path, ".katalon", version); - return p.toFile(); - } - - static File getKatalonPackage( - BuildListener buildListener, String versionNumber) - throws IOException, InterruptedException { - - File katalonDir = getKatalonFolder(versionNumber); - - Path fileLog = Paths.get(katalonDir.toString(), ".katalon.done"); - - if (fileLog.toFile().exists()) { - LogUtils.log(buildListener, "Katalon Studio package has been downloaded already."); - } else { - FileUtils.deleteDirectory(katalonDir); - - boolean katalonDirCreated = katalonDir.mkdirs(); - if (!katalonDirCreated) { - throw new IllegalStateException("Cannot create directory to store Katalon Studio package."); - } - - KatalonUtils.downloadAndExtract(buildListener, versionNumber, katalonDir); - - boolean fileLogCreated = fileLog.toFile().createNewFile(); - if (fileLogCreated) { - LogUtils.log(buildListener, "Katalon Studio has been installed successfully."); - } - } - - String[] childrenNames = katalonDir.list((dir, name) -> { - File file = new File(dir, name); - return file.isDirectory() && name.contains("Katalon"); - }); - - String katalonContainingDirName = Arrays.stream(childrenNames).findFirst().get(); - - - File katalonContainingDir = new File(katalonDir, katalonContainingDirName); - - return katalonContainingDir; - } - - private static boolean executeKatalon( - BuildListener buildListener, - String katalonExecutableFile, - String projectPath, - String executeArgs, - String x11Display, - String xvfbConfiguration) - throws IOException, InterruptedException { - File file = new File(katalonExecutableFile); - if (!file.exists()) { - file = new File(katalonExecutableFile + ".exe"); - } - if (file.exists()) { - file.setExecutable(true); - } - if (katalonExecutableFile.contains(" ")) { - katalonExecutableFile = "\"" + katalonExecutableFile + "\""; - } - String command = katalonExecutableFile + - " -noSplash " + - " -runMode=console "; - if (!executeArgs.contains("-projectPath")) { - command += " -projectPath=\"" + projectPath + "\" "; - } - command += " " + executeArgs + " "; - - return OsUtils.runCommand(buildListener, command, x11Display, xvfbConfiguration); - } - - public static boolean executeKatalon( - BuildListener buildListener, - String version, - String location, - String projectPath, - String executeArgs, - String x11Display, - String xvfbConfiguration) - throws IOException, InterruptedException { - - String katalonDirPath; - - if (StringUtils.isBlank(location)) { - File katalonDir = KatalonUtils.getKatalonPackage(buildListener, version); - katalonDirPath = katalonDir.getAbsolutePath(); - } else { - katalonDirPath = location; - } - - LogUtils.log(buildListener, "Using Katalon Studio at " + katalonDirPath); - String katalonExecutableFile; - String os = OsUtils.getOSVersion(buildListener); - if (os.contains("macos")) { - katalonExecutableFile = Paths.get(katalonDirPath, "Contents", "MacOS", "katalon") - .toAbsolutePath() - .toString(); - } else { - katalonExecutableFile = Paths.get(katalonDirPath, "katalon") - .toAbsolutePath() - .toString(); - } - return executeKatalon( - buildListener, - katalonExecutableFile, - projectPath, - executeArgs, - x11Display, - xvfbConfiguration); - } -} diff --git a/src/main/java/com/katalon/jenkins/plugin/KatalonVersion.java b/src/main/java/com/katalon/jenkins/plugin/KatalonVersion.java deleted file mode 100644 index 8f3d99e..0000000 --- a/src/main/java/com/katalon/jenkins/plugin/KatalonVersion.java +++ /dev/null @@ -1,54 +0,0 @@ -package com.katalon.jenkins.plugin; - -public class KatalonVersion { - - private String version; - private String filename; - private String os; - private String url; - private String containingFolder; - - KatalonVersion() { - - } - - public String getOs() { - return os; - } - - public void setOs(String os) { - this.os = os; - } - - public String getFilename() { - return filename; - } - - public void setFilename(String filename) { - this.filename = filename; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public String getContainingFolder() { - return containingFolder; - } - - public void setContainingFolder(String containingFolder) { - this.containingFolder = containingFolder; - } -} diff --git a/src/main/java/com/katalon/jenkins/plugin/LogUtils.java b/src/main/java/com/katalon/jenkins/plugin/LogUtils.java deleted file mode 100644 index c3dc43c..0000000 --- a/src/main/java/com/katalon/jenkins/plugin/LogUtils.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.katalon.jenkins.plugin; - -import hudson.model.BuildListener; - -class LogUtils { - - static void log(BuildListener buildListener, String message) { - buildListener.getLogger().println(message); - } -} diff --git a/src/main/java/com/katalon/jenkins/plugin/OsUtils.java b/src/main/java/com/katalon/jenkins/plugin/OsUtils.java deleted file mode 100644 index 031e385..0000000 --- a/src/main/java/com/katalon/jenkins/plugin/OsUtils.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.katalon.jenkins.plugin; - -import hudson.model.BuildListener; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.SystemUtils; - -import java.io.*; -import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -class OsUtils { - - static String getOSVersion(BuildListener buildListener) { - - if (SystemUtils.IS_OS_WINDOWS) { - - try { - Process p = Runtime.getRuntime().exec("wmic os get osarchitecture"); - try (InputStream inputStream = p.getInputStream()) { - String output = IOUtils.toString(inputStream); - p.destroy(); - - if (output.contains("64")) { - return "windows 64"; - } else { - return "windows 32"; - } - } - } catch (Exception e) { - LogUtils.log(buildListener, "Cannot detect the OS architecture. Assume it is x64."); - LogUtils.log(buildListener, "Reason: " + e.getMessage() + "."); - return "windows 64"; - } - - } else if (SystemUtils.IS_OS_MAC) { - return "macos (app)"; - } else if (SystemUtils.IS_OS_LINUX) { - return "linux"; - } - return ""; - } - - static boolean runCommand( - BuildListener buildListener, - String command, - String x11Display, - String xvfbConfiguration) - throws IOException, InterruptedException { - - String[] cmdarray; - if (SystemUtils.IS_OS_WINDOWS) { - cmdarray = Arrays.asList("cmd", "/c", command).toArray(new String[]{}); - } else { - if (!StringUtils.isBlank(x11Display)) { - command = "DISPLAY=" + x11Display + " " + command; - } - if (!StringUtils.isBlank(xvfbConfiguration)) { - command = "xvfb-run " + xvfbConfiguration + " " + command; - } - List cmdlist = Arrays.asList("sh", "-c", command); - cmdarray = cmdlist.toArray(new String[]{}); - } - Path workingDirectory = Files.createTempDirectory("katalon-"); - LogUtils.log(buildListener, "Execute " + Arrays.toString(cmdarray) + " in " + workingDirectory); - Process cmdProc = Runtime.getRuntime().exec(cmdarray, null, workingDirectory.toFile()); - try ( - BufferedReader stdoutReader = new BufferedReader( - new InputStreamReader( - cmdProc.getInputStream(), StandardCharsets.UTF_8)); - BufferedReader stderrReader = new BufferedReader( - new InputStreamReader( - cmdProc.getErrorStream(), StandardCharsets.UTF_8)) - ) { - String line; - while ((line = stdoutReader.readLine()) != null || - (line = stderrReader.readLine()) != null) { - LogUtils.log(buildListener, line); - } - } - cmdProc.waitFor(); - return cmdProc.exitValue() == 0; - } -}