Extract build to separate file for consistency #1
Workflow file for this run
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
name: "🔨 Build & Verify" | ||
on: | ||
workflow_call: | ||
jobs: | ||
runs-on: ubuntu-latest | ||
# A local build took 20 seconds, CI takes 3 minutes with setup. | ||
# Because it's cloud, give it a bit of a buffer and constrain. | ||
timeout-minutes: 15 | ||
steps: | ||
- name: "Set up JDK 17." | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: zulu | ||
- name: "Checkout ${{ github.ref }} branch in ${{ github.repository }} repository." | ||
uses: actions/checkout@v3 | ||
- name: "Build & Verify project." | ||
id: gradle | ||
run: > | ||
./gradlew | ||
--no-daemon | ||
--no-build-cache | ||
--continue | ||
--stacktrace | ||
--scan | ||
assemble | ||
lint | ||
detekt | ||
test | ||
check | ||
violationReportHtml | ||
violationCountFile | ||
- name: "Publish 'Gradle' result and Build Scan URL." | ||
if: (success() || failure()) && steps.gradle != null && steps.gradle.outputs.result-success != null | ||
uses: actions/github-script@v6 | ||
with: | ||
debug: ${{ secrets.ACTIONS_STEP_DEBUG || false }} | ||
script: | | ||
const description = ${{ toJSON(fromJSON(steps.gradle.outputs.result-text)) }} | ||
await github.rest.repos.createCommitStatus({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
sha: context.sha, | ||
state: ${{ toJSON(fromJSON(steps.gradle.outputs.result-success)) }} === true ? "success" : "failure", | ||
context: "CI / Build & Verify / Gradle", | ||
// Truncate to be sure it fits: | ||
// > HttpError: Validation Failed: {"resource":"Status","code":"custom", | ||
// > "field":"description","message":"description is too long (maximum is 140 characters)"} | ||
// Max length is 140, give some space for potential Unicode. | ||
description: description.length > 130 | ||
? `${description.substring(0, 130)}…` | ||
: description, | ||
target_url: ${{ steps.gradle.outputs.build-scan-url && toJSON(fromJSON(steps.gradle.outputs.build-scan-url)) || 'undefined' }} | ||
}); | ||
- name: "Upload 'Lint Results HTMLs' artifact." | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: 'Lint Results HTMLs' | ||
path: ${{ github.workspace }}/**/build/reports/lint-results*.html | ||
- name: "Upload 'Lint Merged Results' artifact." | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: 'Lint Merged Results' | ||
path: ${{ github.workspace }}/build/reports/violations.* | ||
- name: "Fail if there are lint violations." | ||
if: success() || failure() | ||
run: | | ||
count=$(cat "${{ github.workspace }}/build/reports/violations.count") | ||
if [[ "$count" != "0" ]]; then | ||
echo "There were $count violations" | ||
exit 1 | ||
else | ||
echo "No violations found." | ||
exit 0 | ||
fi | ||
- name: "Upload 'Unit Test Results' artifact." | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: 'Unit Test Results' | ||
path: ${{ github.workspace }}/**/build/reports/tests/*/ | ||
- name: "Publish 'Unit Results' check suite." | ||
if: success() || failure() | ||
uses: EnricoMi/publish-unit-test-result-action@v2 | ||
with: | ||
check_name: '🔔 Test: Unit Results' | ||
comment_mode: off | ||
report_individual_runs: true | ||
test_changes_limit: 0 | ||
junit_files: ${{ github.workspace }}/**/build/test-results/*/TEST-*.xml | ||
- name: "Upload 'Detekt Results' artifact." | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: 'Detekt Results' | ||
path: ${{ github.workspace }}/**/build/reports/detekt/detekt.* | ||
- name: "Upload 'Detekt Merged Results' artifact." | ||
if: success() || failure() | ||
uses: actions/upload-artifact@v3 | ||
with: | ||
name: 'Detekt Merged Results' | ||
path: ${{ github.workspace }}/build/reports/detekt/merge.* | ||
- name: "Publish 'detekt' GitHub Code Scanning analysis." | ||
uses: github/codeql-action/upload-sarif@v2 | ||
if: success() || failure() | ||
with: | ||
checkout_path: ${{ github.workspace }} | ||
sarif_file: ${{ github.workspace }}/build/reports/detekt/merge.sarif |