Skip to content

Commit 6535f76

Browse files
Merge pull request #11 from Tinder/integration_test
Add Integration Test
2 parents 4dfc9e2 + 6d9ee66 commit 6535f76

File tree

14 files changed

+154
-49
lines changed

14 files changed

+154
-49
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ jobs:
2525
run: go get github.com/bazelbuild/bazelisk
2626
- uses: actions/checkout@v2
2727
- name: Run bazel-diff tests
28-
run: ~/go/bin/bazelisk test //test/...
28+
run: USE_BAZEL_VERSION=last_rc ~/go/bin/bazelisk test //test/...

.github/workflows/integration.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Integration
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
- cron: "0 */2 * * *"
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Setup Java JDK
17+
uses: actions/[email protected]
18+
with:
19+
java-version: 1.8
20+
id: java
21+
- name: Setup Go environment
22+
uses: actions/[email protected]
23+
with:
24+
go-version: ^1.14
25+
id: go
26+
- name: Setup Bazelisk
27+
run: go get github.com/bazelbuild/bazelisk
28+
- uses: actions/checkout@v2
29+
- name: Run integration test
30+
run: ./integration/integration_test.sh -e

README.md

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ This approach was inspired by the [following BazelConf talk](https://www.youtube
2020

2121
* Git
2222
* Bazel 3.3.0 or higher
23-
* `bazel_skylib` version 1.0.2 or higher
2423
* Java 8 JDK or higher (Bazel requires this)
2524

2625
## Getting Started
@@ -165,7 +164,7 @@ java -jar bazel-bin/src/main/java/com/bazel-diff/bazel-diff_deploy.jar # This JA
165164

166165
Add the following to your `WORKSPACE` file to add the external repositories, replacing the `RELEASE_ARCHIVE_URL` with the archive url of the bazel-diff release you wish to depend on:
167166

168-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive", "http_file")
167+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
169168

170169
http_archive(
171170
name = "bazel_diff",
@@ -175,25 +174,10 @@ Add the following to your `WORKSPACE` file to add the external repositories, rep
175174
sha256 = "UPDATE_ME",
176175
)
177176

178-
http_archive(
179-
name = "bazel_skylib",
180-
urls = [
181-
"ARCHIVE_URL_VERSION_ABOVE_1.0.2",
182-
],
183-
sha256 = "UPDATE_ME",
184-
)
185-
186-
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
187-
188-
bazel_skylib_workspace()
189-
190-
load("@bazel_skylib//lib:versions.bzl", "versions")
191-
192177
load("@bazel_diff//:repositories.bzl", "bazel_diff_dependencies")
193178
load("@bazel_diff//:constants.bzl", "BAZEL_DIFF_MAVEN_ARTIFACTS")
194179

195-
# Allows bazel-diff to run based on your projects' version of Bazel
196-
bazel_diff_dependencies(versions.get())
180+
bazel_diff_dependencies()
197181

198182
load("@rules_jvm_external//:defs.bzl", "maven_install")
199183

WORKSPACE

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,9 @@
11
workspace(name = "bazel_diff")
22

3-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
43
load("//:repositories.bzl", "bazel_diff_dependencies")
54
load("//:constants.bzl", "BAZEL_DIFF_MAVEN_ARTIFACTS")
65

7-
http_archive(
8-
name = "bazel_skylib",
9-
urls = [
10-
"https://mirror.bazel.build/github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
11-
"https://github.com/bazelbuild/bazel-skylib/releases/download/1.0.2/bazel-skylib-1.0.2.tar.gz",
12-
],
13-
sha256 = "97e70364e9249702246c0e9444bccdc4b847bed1eb03c5a3ece4f83dfe6abc44",
14-
)
15-
16-
load("@bazel_skylib//:workspace.bzl", "bazel_skylib_workspace")
17-
18-
bazel_skylib_workspace()
19-
20-
load("@bazel_skylib//lib:versions.bzl", "versions")
21-
22-
bazel_diff_dependencies(versions.get())
6+
bazel_diff_dependencies()
237

248
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")
259

integration/WORKSPACE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
workspace(name = "bazel_diff_integration")
2+
3+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
4+
5+
http_archive(
6+
name = "rules_jvm_external",
7+
strip_prefix = "rules_jvm_external-%s" % "3.3",
8+
sha256 = "d85951a92c0908c80bd8551002d66cb23c3434409c814179c0ff026b53544dab",
9+
url = "https://github.com/bazelbuild/rules_jvm_external/archive/%s.zip" % "3.3"
10+
)
11+
12+
load("@rules_jvm_external//:defs.bzl", "maven_install")
13+
14+
maven_install(
15+
name = "bazel_diff_maven",
16+
artifacts = ["junit:junit:4.12"],
17+
repositories = [
18+
"http://uk.maven.org/maven2",
19+
"https://jcenter.bintray.com/",
20+
]
21+
)

integration/integration_test.sh

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/bin/bash
2+
3+
workspace_path="$PWD/integration"
4+
bazel_path=$(which bazelisk)
5+
6+
previous_revision="HEAD^"
7+
final_revision="HEAD"
8+
modified_filepaths_output="$PWD/integration/modified_filepaths.txt"
9+
starting_hashes_json="/tmp/starting_hashes.json"
10+
final_hashes_json="/tmp/final_hashes_json.json"
11+
impacted_targets_path="/tmp/impacted_targets.txt"
12+
impacted_test_targets_path="/tmp/impacted_test_targets.txt"
13+
14+
export USE_BAZEL_VERSION=last_rc
15+
16+
containsElement () {
17+
local e match="$1"
18+
shift
19+
for e; do [[ "$e" == "$match" ]] && return 0; done
20+
return 1
21+
}
22+
23+
$bazel_path run :bazel-diff -- generate-hashes -w $workspace_path -b $bazel_path $starting_hashes_json
24+
25+
$bazel_path run :bazel-diff -- generate-hashes -w $workspace_path -b $bazel_path -m $modified_filepaths_output $final_hashes_json
26+
27+
ruby ./integration/update_final_hashes.rb
28+
29+
$bazel_path run :bazel-diff -- -sh $starting_hashes_json -fh $final_hashes_json -w $workspace_path -b $bazel_path -o $impacted_targets_path
30+
31+
$bazel_path run :bazel-diff -- impacted-tests -w $workspace_path -b $bazel_path $impacted_targets_path $impacted_test_targets_path
32+
33+
IFS=$'\n' read -d '' -r -a impacted_targets < $impacted_targets_path
34+
target="//src/main/java/com/integration:StringGenerator.java"
35+
if containsElement $target "${impacted_targets[@]}";
36+
then
37+
echo "Correct first impacted target"
38+
else
39+
echo "Impacted Targets: ${impacted_targets[@]}"
40+
echo "Incorrect first impacted target: ${target}"
41+
exit 1
42+
fi
43+
44+
IFS=$'\n' read -d '' -r -a impacted_test_targets < $impacted_test_targets_path
45+
target="//test/java/com/integration:bazel-diff-integration-tests"
46+
if containsElement $target "${impacted_test_targets[@]}";
47+
then
48+
echo "Correct first impacted test target"
49+
else
50+
echo "Impacted test targets: ${impacted_test_targets[@]}"
51+
echo "Incorrect first impacted test target: ${target}"
52+
exit 1
53+
fi

integration/modified_filepaths.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
README.md
2+
src/main/java/com/integration/StringGenerator.java
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
load("@rules_java//java:defs.bzl", "java_library")
2+
3+
java_library(
4+
name = "bazel-diff-integration-lib",
5+
srcs = glob(["*.java"]),
6+
visibility = ["//visibility:public"]
7+
)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
public class StringGenerator {
2+
public String createString() {
3+
return "AString";
4+
}
5+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("@rules_java//java:defs.bzl", "java_library", "java_test")
2+
3+
java_test(
4+
name = "bazel-diff-integration-tests",
5+
runtime_deps = [":bazel-diff-integration-test-lib"],
6+
test_class = "TestStringGenerator"
7+
)
8+
9+
java_library(
10+
name = "bazel-diff-integration-test-lib",
11+
srcs = glob(["*.java"]),
12+
deps = [
13+
"//src/main/java/com/integration:bazel-diff-integration-lib",
14+
"@bazel_diff_maven//:junit_junit"
15+
]
16+
)

0 commit comments

Comments
 (0)