Skip to content

Commit a46547c

Browse files
authored
[CI] Pull in the latest mutes from base branch for PRs at runtime (#117587)
1 parent 807d994 commit a46547c

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

.buildkite/hooks/pre-command

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ export GRADLE_BUILD_CACHE_PASSWORD
4747
BUILDKITE_API_TOKEN=$(vault read -field=token secret/ci/elastic-elasticsearch/buildkite-api-token)
4848
export BUILDKITE_API_TOKEN
4949

50+
export GH_TOKEN="$VAULT_GITHUB_TOKEN"
51+
5052
if [[ "${USE_LUCENE_SNAPSHOT_CREDS:-}" == "true" ]]; then
5153
data=$(.buildkite/scripts/get-legacy-secret.sh aws-elastic/creds/lucene-snapshots)
5254

@@ -117,3 +119,5 @@ if [[ -f /etc/os-release ]] && grep -q '"Amazon Linux 2"' /etc/os-release; then
117119
echo "$(hostname -i | cut -d' ' -f 2) $(hostname -f)." | sudo tee /etc/dnsmasq.hosts
118120
sudo systemctl restart dnsmasq.service
119121
fi
122+
123+
.buildkite/scripts/get-latest-test-mutes.sh

.buildkite/hooks/pre-command.bat

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ set BUILD_NUMBER=%BUILDKITE_BUILD_NUMBER%
1515
set COMPOSE_HTTP_TIMEOUT=120
1616
set JOB_BRANCH=%BUILDKITE_BRANCH%
1717

18+
set GH_TOKEN=%VAULT_GITHUB_TOKEN%
19+
1820
set GRADLE_BUILD_CACHE_USERNAME=vault read -field=username secret/ci/elastic-elasticsearch/migrated/gradle-build-cache
1921
set GRADLE_BUILD_CACHE_PASSWORD=vault read -field=password secret/ci/elastic-elasticsearch/migrated/gradle-build-cache
2022

2123
bash.exe -c "nohup bash .buildkite/scripts/setup-monitoring.sh </dev/null >/dev/null 2>&1 &"
24+
bash.exe -c "bash .buildkite/scripts/get-latest-test-mutes.sh"
2225

2326
exit /b 0
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
if [[ ! "${BUILDKITE_PULL_REQUEST:-}" || "${BUILDKITE_AGENT_META_DATA_PROVIDER:-}" == "k8s" ]]; then
4+
exit 0
5+
fi
6+
7+
testMuteBranch="${BUILDKITE_PULL_REQUEST_BASE_BRANCH:-main}"
8+
testMuteFile="$(mktemp)"
9+
10+
# If this PR contains changes to muted-tests.yml, we disable this functionality
11+
# Otherwise, we wouldn't be able to test unmutes
12+
if [[ ! $(gh pr diff "$BUILDKITE_PULL_REQUEST" --name-only | grep 'muted-tests.yml') ]]; then
13+
gh api -H 'Accept: application/vnd.github.v3.raw' "repos/elastic/elasticsearch/contents/muted-tests.yml?ref=$testMuteBranch" > "$testMuteFile"
14+
15+
if [[ -s "$testMuteFile" ]]; then
16+
mkdir -p ~/.gradle
17+
# This is using gradle.properties instead of an env var so that it's easily compatible with the Windows pre-command hook
18+
echo "org.gradle.project.org.elasticsearch.additional.muted.tests=$testMuteFile" >> ~/.gradle/gradle.properties
19+
fi
20+
fi

build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/test/MutedTestsBuildService.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@
2828
import java.io.UncheckedIOException;
2929
import java.util.ArrayList;
3030
import java.util.Collections;
31+
import java.util.LinkedHashSet;
3132
import java.util.List;
33+
import java.util.Set;
3234

3335
public abstract class MutedTestsBuildService implements BuildService<MutedTestsBuildService.Params> {
34-
private final List<String> excludePatterns = new ArrayList<>();
36+
private final Set<String> excludePatterns = new LinkedHashSet<>();
3537
private final ObjectMapper objectMapper = new ObjectMapper(new YAMLFactory());
3638

3739
public MutedTestsBuildService() {
@@ -43,23 +45,23 @@ public MutedTestsBuildService() {
4345
}
4446
}
4547

46-
public List<String> getExcludePatterns() {
48+
public Set<String> getExcludePatterns() {
4749
return excludePatterns;
4850
}
4951

50-
private List<String> buildExcludePatterns(File file) {
52+
private Set<String> buildExcludePatterns(File file) {
5153
List<MutedTest> mutedTests;
5254

5355
try (InputStream is = new BufferedInputStream(new FileInputStream(file))) {
5456
mutedTests = objectMapper.readValue(is, MutedTests.class).getTests();
5557
if (mutedTests == null) {
56-
return Collections.emptyList();
58+
return Collections.emptySet();
5759
}
5860
} catch (IOException e) {
5961
throw new UncheckedIOException(e);
6062
}
6163

62-
List<String> excludes = new ArrayList<>();
64+
Set<String> excludes = new LinkedHashSet<>();
6365
if (mutedTests.isEmpty() == false) {
6466
for (MutedTestsBuildService.MutedTest mutedTest : mutedTests) {
6567
if (mutedTest.getClassName() != null && mutedTest.getMethods().isEmpty() == false) {

0 commit comments

Comments
 (0)