Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/frontend-move-dir' into playing-…
Browse files Browse the repository at this point in the history
…with-css
  • Loading branch information
Unknown committed Oct 27, 2017
2 parents 79c97b1 + da5f8f3 commit 326ec26
Show file tree
Hide file tree
Showing 585 changed files with 577 additions and 735 deletions.
46 changes: 23 additions & 23 deletions Jenkinsfile
Expand Up @@ -4,16 +4,21 @@
* Jenkinsfile for zanata-platform
*/

@Field
public static final String PROJ_URL = 'https://github.com/zanata/zanata-platform'

// Import pipeline library for utility methods & classes:
// ansicolor(), Notifier, PullRequests, Strings
@Field
public static final String PIPELINE_LIBRARY_BRANCH = 'master'
public static final String PIPELINE_LIBRARY_BRANCH = 'v0.3.0'

// GROOVY-3278:
// Using referenced String constant as value of Annotation causes compile error
@Library('zanata-pipeline-library@master')
@Library('zanata-pipeline-library@v0.3.0')
import org.zanata.jenkins.Notifier
import org.zanata.jenkins.PullRequests
import org.zanata.jenkins.ScmGit
import static org.zanata.jenkins.Reporting.codecov
import static org.zanata.jenkins.StackTraces.getStackTrace

import groovy.transform.Field
Expand All @@ -23,13 +28,15 @@ milestone()

PullRequests.ensureJobDescription(env, manager, steps)

// initialiser must be run separately (bindings not available during compilation phase)
@Field
def pipelineLibraryScmGit

@Field
def mainScmGit

@Field
def notify
// initialiser must be run separately (bindings not available during compilation phase)
notify = new Notifier(env, steps, currentBuild,
'https://github.com/zanata/zanata-platform.git',
'Jenkinsfile', PIPELINE_LIBRARY_BRANCH,
)

// we can't set these values yet, because we need a node to look at the environment
@Field
Expand All @@ -45,6 +52,13 @@ def jobName
// we need a node to access env.DEFAULT_NODE.
node {
echo "running on node ${env.NODE_NAME}"
pipelineLibraryScmGit = new ScmGit(env, steps, 'https://github.com/zanata/zanata-pipeline-library')
pipelineLibraryScmGit.init(PIPELINE_LIBRARY_BRANCH)
mainScmGit = new ScmGit(env, steps, PROJ_URL)
mainScmGit.init(env.BRANCH_NAME)
notify = new Notifier(env, steps, currentBuild,
pipelineLibraryScmGit, mainScmGit, 'Jenkinsfile',
)
defaultNodeLabel = env.DEFAULT_NODE ?: 'master || !master'
// eg github-zanata-org/zanata-platform/update-Jenkinsfile
jobName = env.JOB_NAME
Expand All @@ -59,7 +73,7 @@ node {
],
[
$class: 'GithubProjectProperty',
projectUrlStr: 'https://github.com/zanata/zanata-platform'
projectUrlStr: PROJ_URL
],
[
$class: 'ParametersDefinitionProperty',
Expand Down Expand Up @@ -231,21 +245,7 @@ timestamps {
// TODO try https://github.com/jenkinsci/github-pr-coverage-status-plugin

// send test coverage data to codecov.io
try {
withCredentials(
[[$class: 'StringBinding',
credentialsId: 'codecov_zanata-platform',
variable: 'CODECOV_TOKEN']]) {
// NB the codecov script uses CODECOV_TOKEN
sh "curl -s https://codecov.io/bash | bash -s - -K"
}
} catch (InterruptedException e) {
throw e
} catch (hudson.AbortException e) {
throw e
} catch (e) {
echo "[WARNING] Ignoring codecov error: $e"
}
codecov(env, steps, mainScmGit)

// notify if compile+unit test successful
// TODO update notify (in pipeline library) to support Rocket.Chat webhook integration
Expand Down
2 changes: 1 addition & 1 deletion api/zanata-common-api/pom.xml
Expand Up @@ -9,7 +9,7 @@
<artifactId>api</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
1 change: 0 additions & 1 deletion build
Expand Up @@ -71,7 +71,6 @@ General options:
-c, --clean (mvn clean)
-C, --clean-partial
removes various generated files from server without running a full mvn clean
(takari lifecycle handles this in jar modules)
-P, --skip-package
runs mvn test instead of mvn package
-i, --install (mvn install)
Expand Down
19 changes: 2 additions & 17 deletions build-tools/pom.xml
Expand Up @@ -6,7 +6,7 @@
<name>Build Tools</name>
<description>Build tools for Zanata modules</description>
<url>http://zanata.org/</url>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<distributionManagement>
<snapshotRepository>
Expand Down Expand Up @@ -59,26 +59,11 @@
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<build>
<plugins>
<plugin>
<groupId>io.takari.maven.plugins</groupId>
<artifactId>takari-lifecycle-plugin</artifactId>
<!-- Unfortunately, we can't inherit this version from parent: -->
<version>1.12.4</version>
<extensions>true</extensions>
<configuration>
<proc>proc</proc>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>com.lesfurets</groupId>
<artifactId>jenkins-pipeline-unit</artifactId>
<version>0.12</version>
<version>1.1</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
101 changes: 70 additions & 31 deletions build-tools/src/test/java/TestJenkinsfile.java
@@ -1,22 +1,23 @@
import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.codehaus.groovy.runtime.MethodClosure;
import org.junit.Before;
import org.junit.Test;
import com.cloudbees.groovy.cps.impl.CpsCallableInvocation;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.lesfurets.jenkins.unit.cps.BasePipelineTestCPS;
import com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration;
import groovy.lang.Closure;
import org.codehaus.groovy.runtime.MethodClosure;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static com.lesfurets.jenkins.unit.MethodSignature.method;
import static com.lesfurets.jenkins.unit.global.lib.GitSource.gitSource;
import static com.lesfurets.jenkins.unit.global.lib.LibraryConfiguration.library;
import static java.lang.Boolean.TRUE;
import static org.assertj.core.api.Assertions.assertThat;

// try 'extends BasePipelineTest' for debugging in case of weird Groovy exceptions
public class TestJenkinsfile extends BasePipelineTestCPS {
Expand Down Expand Up @@ -66,24 +67,8 @@ public void setUp() throws Exception {
throw new RuntimeException("Unmocked invocation");
});
getHelper().registerAllowedMethod(method("sh", Map.class),
args -> {
@SuppressWarnings("unchecked")
Map<String, ?> a = (Map<String, ?>) args;
if (TRUE.equals(a.get("returnStdout"))) {
String script = a.get("script").toString();
if (script.contains("allocate-jboss-ports")) {
return "JBOSS_HTTP_PORT=51081\nSMTP_PORT=34765\n";
}
// Notifier.groovy in zanata-pipeline-library uses this:
if (script.contains("git ls-remote")) {
return "1234567890 abcdef\n";
}
}
if (TRUE.equals(a.get("returnStatus"))) {
return 0;
}
return 0;
});
SH.INSTANCE);

// PipelineUnit(withCredentialsInterceptor) can't handle a List<Map>
// TODO for some reason the steps inside closure.call() are not shown as nested
getHelper().registerAllowedMethod("withCredentials",
Expand All @@ -100,7 +85,7 @@ public Object call(Object... args) {
Map<String, String> env = new HashMap<>();
env.put("BUILD_URL", "http://example.com/job/JobName/123");
env.put("JOB_NAME", "JobName");
env.put("BRANCH_NAME", "PR-456");
env.put("BRANCH_NAME", "master");
env.put("BUILD_NUMBER", "123");
env.put("EXECUTOR_NUMBER", "1");
env.put("DEFAULT_NODE", "master");
Expand All @@ -113,7 +98,7 @@ public Object call(Object... args) {
steps.put("emailext", Closure.IDENTITY);
steps.put("emailextrecipients", Closure.IDENTITY);
steps.put("library", Closure.IDENTITY);
steps.put("sh", Closure.IDENTITY);
steps.put("sh", SH.INSTANCE);
steps.put("step", Closure.IDENTITY);
// we need this for CPS mode
MethodClosure.ALLOW_RESOLVE = true;
Expand All @@ -129,15 +114,69 @@ public Object call(Object... args) {
getBinding().setProperty("manager", ImmutableMap.of());
}

static class SH<T, R> extends Closure<R> {
static final Closure INSTANCE = new SH();
SH() {
super(null);
}

@SuppressWarnings("unused")
protected Object doCall(T args) {
if (args instanceof String) return 0;

@SuppressWarnings("unchecked")
Map<String, ?> a = (Map<String, ?>) args;
if (TRUE.equals(a.get("returnStdout"))) {
String script = a.get("script").toString();
if (script.endsWith("allocate-jboss-ports")) {
return "JBOSS_HTTP_PORT=51081\nSMTP_PORT=34765\n";
}
if (script.startsWith("git ls-remote")) {
// ScmGit.init in zanata-pipeline-library uses these:
if (script.endsWith("refs/pull/*/head")) {
return "1234567890123456789012345678901234567890 refs/pull/123/head\n" +
"6543516846846146541645265465464654264641 refs/pull/234/head";
} else if (script.endsWith("refs/heads/*")) {
return "fc2b7c527e4401c03bcaf2833739d16e77698ab6 refs/heads/master\n" +
"b0d3e2ff4696f2702f4b4fbac3b59b6cf9a76790 refs/heads/feature-branch";
} else if (script.contains("refs/tags/")) {
// TODO extract the requested tag and return it
return "b0d3e2ff4696f2702f4b4fbac3b59b6cf9a76790 refs/tags/v0.3.0";
} else if (script.matches("refs/pull/.*/head")) {
return "b0d3e2ff4696f2702f4b4fbac3b59b6cf9a76790 refs/pull/123/head";
} else {
// Notifier.groovy in zanata-pipeline-library uses this:
return "fc2b7c527e4401c03bcaf2833739d16e77698ab6 refs/heads/master\n" +
"b0d3e2ff4696f2702f4b4fbac3b59b6cf9a76790 refs/heads/feature-branch\n" +
"1234567890123456789012345678901234567890 refs/tags/v0.1.0";
}
}
}
if (TRUE.equals(a.get("returnStatus"))) {
return 0;
}
return 0;
}
}

@Test
public void shouldExecuteWithoutErrors() throws Exception {

try {
// load and execute the Jenkinsfile
loadScript("../Jenkinsfile");
runScript("../Jenkinsfile");
printCallStack();
assertJobStatusSuccess();
// TODO add assertions about call stack (but not too fragile)

boolean verified = getHelper().getCallStack()
.stream()
.filter(it -> it.getMethodName().equals("sh") && it.argsToString().contains("mvn"))
// snoop on mvn commands in the stream
// .peek(it -> System.out.printf("%s\n\n", it.argsToString()))
.anyMatch(it -> {
String args = it.argsToString();
return args.contains("-Dappserver=") && args.contains("install");
});
assertThat(verified).isTrue();
} catch (CpsCallableInvocation e) {
// if the script fails, we need the call stack to tell us where the problem is
// (CpsCallableInvocation tells us very little)
Expand Down
2 changes: 1 addition & 1 deletion client/stub-server/pom.xml
Expand Up @@ -8,7 +8,7 @@
</parent>
<artifactId>stub-server</artifactId>
<name>stub-server</name>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion client/zanata-cli/pom.xml
Expand Up @@ -8,7 +8,7 @@
</parent>
<artifactId>zanata-cli</artifactId>
<name>Zanata command-line client</name>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion client/zanata-client-commands/pom.xml
Expand Up @@ -8,7 +8,7 @@
</parent>
<artifactId>zanata-client-commands</artifactId>
<name>Zanata client commands</name>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
3 changes: 0 additions & 3 deletions client/zanata-maven-plugin/pom.xml
Expand Up @@ -9,9 +9,6 @@
<artifactId>zanata-maven-plugin</artifactId>

<packaging>maven-plugin</packaging>
<!-- TODO try this again after https://github.com/takari/takari-lifecycle/issues/43 -->
<!-- May need to bind maven-plugin-plugin:helpmojo to lifecycle phase -->
<!--<packaging>takari-maven-plugin</packaging>-->

<name>Zanata Maven Plugin</name>

Expand Down
2 changes: 1 addition & 1 deletion client/zanata-rest-client/pom.xml
Expand Up @@ -8,7 +8,7 @@
<artifactId>client</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion common/zanata-adapter-glossary/pom.xml
Expand Up @@ -8,7 +8,7 @@
<artifactId>common</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion common/zanata-adapter-po/pom.xml
Expand Up @@ -8,7 +8,7 @@
<artifactId>common</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion common/zanata-adapter-properties/pom.xml
Expand Up @@ -8,7 +8,7 @@
<artifactId>common</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion common/zanata-adapter-xliff/pom.xml
Expand Up @@ -8,7 +8,7 @@
<artifactId>common</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down
2 changes: 1 addition & 1 deletion common/zanata-common-util/pom.xml
Expand Up @@ -8,7 +8,7 @@
<artifactId>common</artifactId>
<version>4.4.0-SNAPSHOT</version>
</parent>
<packaging>takari-jar</packaging>
<packaging>jar</packaging>

<!-- Connection URLs repeated as workaround for https://issues.apache.org/jira/browse/MPIR-234 -->
<scm>
Expand Down

0 comments on commit 326ec26

Please sign in to comment.