Skip to content

Commit 710a20d

Browse files
authored
Merge branch 'master' into sharmila/fix-version
2 parents b1e6072 + b1c0873 commit 710a20d

9 files changed

Lines changed: 128 additions & 38 deletions

File tree

.github/workflows/publish.yaml

Lines changed: 0 additions & 28 deletions
This file was deleted.

.github/workflows/release.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Cut a release whenever a new tag is pushed or via workflow_dispatch.
2+
# Uses bazel-contrib release ruleset: build, attest, and publish to GitHub Releases.
3+
name: Release
4+
on:
5+
workflow_dispatch:
6+
inputs:
7+
tag_name:
8+
description: Git tag being released
9+
required: true
10+
type: string
11+
push:
12+
tags:
13+
- "v*.*.*"
14+
permissions:
15+
id-token: write
16+
attestations: write
17+
contents: write
18+
jobs:
19+
release:
20+
uses: bazel-contrib/.github/.github/workflows/release_ruleset.yaml@v7.2.2
21+
with:
22+
release_files: archives/release.tar.gz
23+
prerelease: false
24+
tag_name: ${{ inputs.tag_name || github.ref_name }}
25+
permissions:
26+
id-token: write # Needed to attest provenance
27+
attestations: write # Needed to attest provenance
28+
contents: write # Needed to upload release files
29+
secrets: {}

.github/workflows/release_prep.sh

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
2+
3+
set -o errexit -o nounset -o pipefail
4+
5+
# Argument provided by reusable workflow caller, see
6+
# https://github.com/bazel-contrib/.github/blob/master/.github/workflows/release_ruleset.yaml
7+
TAG=$1
8+
9+
mkdir -p archives
10+
tar --exclude-vcs \
11+
--exclude=bazel-* \
12+
--exclude=.github \
13+
--exclude=archives \
14+
--exclude=cli/src/test \
15+
-zcf "archives/release.tar.gz" .
16+
17+
SHA=$(shasum -a 256 archives/release.tar.gz | awk '{print $1}')
18+
19+
cat << EOF
20+
## Using Bzlmod (MODULE.bazel)
21+
22+
Add to your \`MODULE.bazel\` file:
23+
24+
\`\`\`starlark
25+
bazel_dep(name = "bazel-diff", version = "${TAG#v}")
26+
\`\`\`
27+
28+
## Using WORKSPACE
29+
30+
\`\`\`starlark
31+
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
32+
http_archive(
33+
name = "bazel-diff",
34+
sha256 = "${SHA}",
35+
strip_prefix = "",
36+
url = "https://github.com/Tinder/bazel-diff/releases/download/${TAG}/release.tar.gz",
37+
)
38+
\`\`\`
39+
EOF

MODULE.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module(
22
name = "bazel-diff",
3-
version = "17.0.3",
3+
version = "17.1.4",
44
compatibility_level = 0,
55
)
66

MODULE.bazel.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ release_source_archive:
55
--exclude=bazel-* \
66
--exclude=.github \
77
--exclude=archives \
8-
--exclude=cli/src/test \
98
-zcf "archives/release.tar.gz" .
109

1110
.PHONY: release_deploy_jar

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ First, add the following snippet to your project:
341341
#### Bzlmod snippet
342342

343343
```bazel
344-
bazel_dep(name = "bazel-diff", version = "15.0.5")
344+
bazel_dep(name = "bazel-diff", version = "17.1.0")
345345
```
346346

347347
You can now run the tool with:

cli/src/main/kotlin/com/bazel_diff/bazel/BazelQueryService.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BazelQueryService(
3030

3131
@OptIn(ExperimentalCoroutinesApi::class)
3232
private suspend fun determineBazelVersion(): Triple<Int, Int, Int> {
33-
val cmd = arrayOf(bazelPath.toString(), "--version")
33+
val cmd = arrayOf(bazelPath.toString(), "version")
3434
logger.i { "Executing Bazel version command: ${cmd.joinToString()}" }
3535
val result =
3636
process(
@@ -45,12 +45,19 @@ class BazelQueryService(
4545
throw RuntimeException("Bazel version command failed, exit code ${result.resultCode}")
4646
}
4747

48-
if (result.output.size != 1 || !result.output.first().startsWith("bazel ")) {
49-
throw RuntimeException("Bazel version command returned unexpected output: ${result.output}")
50-
}
48+
// "bazel version" outputs "Build label: X.Y.Z" on one of the lines; accept that or legacy "bazel X.Y.Z".
49+
val versionString =
50+
result.output
51+
.firstOrNull { it.startsWith("Build label: ") }
52+
?.removePrefix("Build label: ")?.trim()
53+
?: result.output
54+
.firstOrNull { it.startsWith("bazel ") }
55+
?.removePrefix("bazel ")?.trim()
56+
?: throw RuntimeException(
57+
"Bazel version command returned unexpected output: ${result.output}")
5158
// Trim off any prerelease suffixes (e.g., 8.6.0-rc1 or 8.6.0rc1).
52-
val versionString = result.output.first().removePrefix("bazel ").trim().split('-')[0]
53-
val version = versionString.split('.').map { it.takeWhile { c -> c.isDigit() }.toInt() }.toTypedArray()
59+
val version =
60+
versionString.split('-')[0].split('.').map { it.takeWhile { c -> c.isDigit() }.toInt() }.toTypedArray()
5461
return Triple(version[0], version[1], version[2])
5562
}
5663

cli/src/test/kotlin/com/bazel_diff/e2e/E2ETest.kt

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,37 @@ class E2ETest {
136136
testE2E(emptyList(), emptyList(), "/fixture/impacted_targets-1-2.txt")
137137
}
138138

139+
@Test
140+
fun testDetermineBazelVersion() {
141+
// E2E coverage for BazelQueryService.determineBazelVersion(): version is resolved lazily
142+
// when the first query runs. Running generate-hashes to completion validates that
143+
// "bazel version" is executed and parsed successfully (e.g. "Build label: X.Y.Z").
144+
val projectA = extractFixtureProject("/fixture/integration-test-1.zip")
145+
val workingDirectory = File(projectA, "integration")
146+
val outputDir = temp.newFolder()
147+
val outputPath = File(outputDir, "hashes.json")
148+
149+
val cli = CommandLine(BazelDiff())
150+
val exitCode = cli.execute(
151+
"generate-hashes",
152+
"-w",
153+
workingDirectory.absolutePath,
154+
"-b",
155+
"bazel",
156+
outputPath.absolutePath)
157+
158+
assertThat(exitCode).isEqualTo(0)
159+
assertThat(outputPath.readText().isNotEmpty()).isEqualTo(true)
160+
}
161+
162+
@Test
163+
fun testE2EWithNoKeepGoing() {
164+
testE2E(
165+
listOf("--no-keep_going"),
166+
emptyList(),
167+
"/fixture/impacted_targets-1-2.txt")
168+
}
169+
139170
@Test
140171
fun testE2EIncludingTargetType() {
141172
testE2E(
@@ -996,6 +1027,19 @@ class E2ETest {
9961027
// which is designed to fail during analysis
9971028
assertThat(exitCodeWithCquery).isEqualTo(1)
9981029

1030+
// Test with --no-keep_going: cquery should fail (no partial results, immediate failure)
1031+
val outputNoKeepGoing = File(outputDir, "hashes_no_keep_going.json")
1032+
val exitCodeWithNoKeepGoing = cli.execute(
1033+
"generate-hashes",
1034+
"-w",
1035+
workspace.absolutePath,
1036+
"-b",
1037+
"bazel",
1038+
"--useCquery",
1039+
"--no-keep_going",
1040+
outputNoKeepGoing.absolutePath)
1041+
assertThat(exitCodeWithNoKeepGoing).isEqualTo(1)
1042+
9991043
// Test with --keep_going enabled (default behavior)
10001044
// With keep_going, cquery returns partial results but still exits with code 1
10011045
// The current implementation allows exit codes 0 and 3, but cquery with keep_going

0 commit comments

Comments
 (0)