generated from actions/typescript-action
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #304 from gradle/dd/test-init-scripts
Improve init scripts and add test coverage The build-scan-capture init script will now capture results from builds that do not publish a build-scan, with and without the configuration-cache. Fixes #292
- Loading branch information
Showing
24 changed files
with
982 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: CI-init-script-check | ||
|
||
on: | ||
push: | ||
|
||
jobs: | ||
test-init-scripts: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
- name: Setup Java | ||
uses: actions/setup-java@v3 | ||
with: | ||
distribution: temurin | ||
java-version: 8 | ||
- name: Setup Gradle | ||
uses: ./ | ||
with: | ||
cache-read-only: false # For testing, allow writing cache entries on non-default branches | ||
- name: Run integration tests | ||
working-directory: test/test-init-scripts | ||
run: ./gradlew check |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import org.gradle.tooling.events.* | ||
import org.gradle.tooling.events.task.* | ||
import org.gradle.util.GradleVersion | ||
|
||
// Can't use settingsEvaluated since this script is applied inside a settingsEvaluated handler | ||
// But projectsEvaluated is good enough, since the build service won't catch configuration failures anyway | ||
projectsEvaluated { | ||
def projectTracker = gradle.sharedServices.registerIfAbsent("gradle-build-action-buildResultsRecorder", BuildResultsRecorder, { spec -> | ||
spec.getParameters().getRootProject().set(gradle.rootProject.name) | ||
spec.getParameters().getRequestedTasks().set(gradle.startParameter.taskNames.join(" ")) | ||
spec.getParameters().getInvocationId().set(gradle.ext.invocationId) | ||
}) | ||
|
||
gradle.services.get(BuildEventsListenerRegistry).onTaskCompletion(projectTracker) | ||
} | ||
|
||
abstract class BuildResultsRecorder implements BuildService<BuildResultsRecorder.Params>, OperationCompletionListener, AutoCloseable { | ||
private boolean buildFailed = false | ||
interface Params extends BuildServiceParameters { | ||
Property<String> getRootProject() | ||
Property<String> getRequestedTasks() | ||
Property<String> getInvocationId() | ||
} | ||
|
||
public void onFinish(FinishEvent finishEvent) { | ||
if (finishEvent instanceof TaskFinishEvent && finishEvent.result instanceof TaskFailureResult) { | ||
buildFailed = true | ||
} | ||
} | ||
|
||
@Override | ||
public void close() { | ||
def buildResults = [ | ||
rootProject: getParameters().getRootProject().get(), | ||
requestedTasks: getParameters().getRequestedTasks().get(), | ||
gradleVersion: GradleVersion.current().version, | ||
buildFailed: buildFailed, | ||
buildScanUri: null | ||
] | ||
|
||
def buildResultsDir = new File(System.getenv("RUNNER_TEMP"), ".build-results") | ||
buildResultsDir.mkdirs() | ||
def buildResultsFile = new File(buildResultsDir, System.getenv("GITHUB_ACTION") + getParameters().getInvocationId().get() + ".json") | ||
buildResultsFile << groovy.json.JsonOutput.toJson(buildResults) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
build | ||
.gradle |
Oops, something went wrong.