Skip to content

Commit

Permalink
Merge branch 'main' into add_repo_admin
Browse files Browse the repository at this point in the history
  • Loading branch information
minwoox committed Dec 16, 2024
2 parents 85cca89 + 7d75b79 commit ef403a9
Show file tree
Hide file tree
Showing 157 changed files with 3,906 additions and 1,546 deletions.
32 changes: 25 additions & 7 deletions .github/workflows/actions_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-12, windows-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
java: [21]
include:
- java: 8
Expand Down Expand Up @@ -75,11 +75,34 @@ jobs:
-Porg.gradle.java.installations.paths=${{ steps.setup-build-jdk.outputs.path }},${{ steps.setup-test-jdk.outputs.path }}
shell: bash

- name: Summarize the failed tests
if: failure()
run: |
./gradlew --no-daemon --stacktrace --max-workers=1 reportFailedTests \
-PnoLint \
-PflakyTests=false \
-PbuildJdkVersion=${{ env.BUILD_JDK_VERSION }} \
-PtestJavaVersion=${{ matrix.java }} \
${{ matrix.min-java && format('-PminimumJavaVersion={0}', matrix.min-java) || '' }} \
-Porg.gradle.java.installations.paths=${{ steps.setup-build-jdk.outputs.path }},${{ steps.setup-jdk.outputs.path }}
SUMMARY_FILE="build/failed-tests-result.txt"
if test -f "$SUMMARY_FILE"; then
echo '### 🔴 Failed tests' >> $GITHUB_STEP_SUMMARY
cat $SUMMARY_FILE >> $GITHUB_STEP_SUMMARY
fi
shell: bash

- name: Dump stuck threads
if: always()
run: jps | grep -vi "jps" | awk '{ print $1 }' | xargs -I'{}' jstack -l {} || true
shell: bash

- name: Upload coverage to Codecov
if: ${{ matrix.coverage }}
uses: codecov/codecov-action@v3

- name: Collecting the test reports ..
- name: Collect the test reports ..
if: failure()
run: |
find . '(' \
Expand All @@ -96,11 +119,6 @@ jobs:
path: reports-JVM-${{ matrix.java }}.tar
retention-days: 3

- name: Dump stuck threads
if: always()
run: jps | grep -vi "jps" | awk '{ print $1 }' | xargs -I'{}' jstack -l {} || true
shell: bash

lint:
if: github.repository == 'line/centraldogma'
runs-on: ubuntu-latest
Expand Down
91 changes: 91 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
import org.jsoup.Jsoup
import org.jsoup.nodes.Element
import org.jsoup.select.Elements

import static java.lang.Math.min

buildscript {
dependencies {
classpath libs.jsoup
}
}

plugins {
alias libs.plugins.nexus.publish
alias libs.plugins.osdetector apply false
Expand Down Expand Up @@ -127,6 +139,85 @@ configure(projectsWithFlags('java')) {
tasks.processResources.duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

tasks.register("reportFailedTests", TestsReportTask)

/**
* Summarizes the failed tests and reports as a file with the Markdown syntax.
*/
class TestsReportTask extends DefaultTask {
@OutputFile
final def reportFile = project.file("${project.buildDir}/failed-tests-result.txt")

@TaskAction
def run() {
// Collect up to 20 error results
int maxErrorSize = 20
List<Map> failedTests = []
Set<String> handledFiles = []

project.allprojects {
tasks.withType(Test) { testTask ->

def xmlFiles = testTask.reports.junitXml.outputLocation.asFileTree.files
if (xmlFiles.isEmpty()) {
return
}
xmlFiles.each { file ->
if (!handledFiles.add(file.name)) {
return
}

Elements failures = Jsoup.parse(file, 'UTF-8').select("testsuite failure")
if (failures.isEmpty() || failedTests.size() > maxErrorSize) {
return
}
failures.each { failure ->
Element parent = failure.parent()
String fullMethodName = "${parent.attr("classname")}.${parent.attr("name")}"
String detail = failure.wholeText()
failedTests += [method: fullMethodName, detail: detail]
}
}
}
}

if (failedTests.isEmpty()) {
return
}

reportFile.withPrintWriter('UTF-8') { writer ->
failedTests.each { it ->
String method = it.method
String detail = it.detail

// Create an link to directly create an issue from the error message
String ghIssueTitle = URLEncoder.encode("Test failure: `$method`", "UTF-8")
// 8k is the maximum allowed URL length for GitHub
String ghIssueBody = URLEncoder.encode(
"```\n${detail.substring(0, min(6000, detail.length()))}\n```\n", "UTF-8")
String ghIssueLink =
"https://github.com/line/centraldogma/issues/new?title=$ghIssueTitle&body=$ghIssueBody"
String ghSearchQuery = URLEncoder.encode("is:issue $method", "UTF-8")
String ghSearchLink = "https://github.com/line/centraldogma/issues?q=$ghSearchQuery"
writer.print("- $it.method - [Search similar issues]($ghSearchLink) | ")
writer.println("[Create an issue?]($ghIssueLink)")

writer.println(" ```")
List<String> lines = detail.split("\n") as List
def summary = lines.take(8)
summary.each { line -> writer.println(" $line") }
writer.println(" ```")
if (lines.size() > 8) {
writer.println(" <details><summary>Full error messages</summary>")
writer.println(" <pre>")
lines.each { line -> writer.println(" $line") }
writer.println(" </pre></details>\n")
}
}
}
}
}

// Configure the Javadoc tasks of all projects.
allprojects {
tasks.withType(Javadoc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AuthUpstreamTest {

@Override
protected void configure(CentralDogmaBuilder builder) {
builder.administrators(TestAuthMessageUtil.USERNAME);
builder.systemAdministrators(TestAuthMessageUtil.USERNAME);
builder.authProviderFactory(new TestAuthProviderFactory());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,37 +16,33 @@

package com.linecorp.centraldogma.common;

import static java.util.Objects.requireNonNull;

import javax.annotation.Nullable;

/**
* A {@link CentralDogmaException} that is raised when attempted to push a commit without effective changes.
*/
public class RedundantChangeException extends CentralDogmaException {

private static final long serialVersionUID = 8739464985038079688L;

/**
* Creates a new instance.
*/
public RedundantChangeException() {}
@Nullable
private final Revision headRevision;

/**
* Creates a new instance.
*/
public RedundantChangeException(String message) {
super(message);
headRevision = null;
}

/**
* Creates a new instance.
*/
public RedundantChangeException(Throwable cause) {
super(cause);
}

/**
* Creates a new instance.
*/
public RedundantChangeException(String message, Throwable cause) {
super(message, cause);
public RedundantChangeException(Revision headRevision, String message) {
super(message);
this.headRevision = requireNonNull(headRevision, "headRevision");
}

/**
Expand All @@ -57,13 +53,14 @@ public RedundantChangeException(String message, Throwable cause) {
*/
public RedundantChangeException(String message, boolean writableStackTrace) {
super(message, writableStackTrace);
headRevision = null;
}

/**
* Creates a new instance.
* Returns the head revision of the repository when this exception was raised.
*/
protected RedundantChangeException(String message, Throwable cause, boolean enableSuppression,
boolean writableStackTrace) {
super(message, cause, enableSuppression, writableStackTrace);
@Nullable
public Revision headRevision() {
return headRevision;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ public final class MirrorDto {
@Nullable
private final String gitignore;
private final String credentialId;
@Nullable
private final String zone;

@JsonCreator
public MirrorDto(@JsonProperty("id") String id,
Expand All @@ -62,7 +64,8 @@ public MirrorDto(@JsonProperty("id") String id,
@JsonProperty("remotePath") String remotePath,
@JsonProperty("remoteBranch") String remoteBranch,
@JsonProperty("gitignore") @Nullable String gitignore,
@JsonProperty("credentialId") String credentialId) {
@JsonProperty("credentialId") String credentialId,
@JsonProperty("zone") @Nullable String zone) {
this.id = requireNonNull(id, "id");
this.enabled = firstNonNull(enabled, true);
this.projectName = requireNonNull(projectName, "projectName");
Expand All @@ -76,6 +79,7 @@ public MirrorDto(@JsonProperty("id") String id,
this.remoteBranch = requireNonNull(remoteBranch, "remoteBranch");
this.gitignore = gitignore;
this.credentialId = requireNonNull(credentialId, "credentialId");
this.zone = zone;
}

@JsonProperty("id")
Expand Down Expand Up @@ -145,6 +149,12 @@ public String credentialId() {
return credentialId;
}

@Nullable
@JsonProperty("zone")
public String zone() {
return zone;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand All @@ -166,13 +176,14 @@ public boolean equals(Object o) {
remotePath.equals(mirrorDto.remotePath) &&
remoteBranch.equals(mirrorDto.remoteBranch) &&
Objects.equals(gitignore, mirrorDto.gitignore) &&
credentialId.equals(mirrorDto.credentialId);
credentialId.equals(mirrorDto.credentialId) &&
Objects.equals(zone, mirrorDto.zone);
}

@Override
public int hashCode() {
return Objects.hash(id, projectName, schedule, direction, localRepo, localPath, remoteScheme,
remoteUrl, remotePath, remoteBranch, gitignore, credentialId, enabled);
remoteUrl, remotePath, remoteBranch, gitignore, credentialId, enabled, zone);
}

@Override
Expand All @@ -191,6 +202,7 @@ public String toString() {
.add("remotePath", remotePath)
.add("gitignore", gitignore)
.add("credentialId", credentialId)
.add("zone", zone)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
import com.fasterxml.jackson.databind.node.ObjectNode;

/**
* JSON Path {@code remove} operation.
* JSON Path {@code removeIfExists} operation.
*
* <p>This operation only takes one pointer ({@code path}) as an argument. It
* is an error condition if no JSON value exists at that pointer.</p>
* <p>This operation only takes one pointer ({@code path}) as an argument. Unlike, {@link RemoveOperation}, it
* does not throw an error if no JSON value exists at that pointer.</p>
*/
public final class RemoveIfExistsOperation extends JsonPatchOperation {

Expand Down
Loading

0 comments on commit ef403a9

Please sign in to comment.