mirror of
https://github.com/gradle/gradle-build-action.git
synced 2024-11-22 17:12:51 +00:00
Fail action execution on unhandled errors
Without this, the error logs contain an "UnhandledPromiseRejectionError" but the action is reported as succeeding.
This commit is contained in:
parent
a802a3c0ce
commit
cca55d0890
3 changed files with 20 additions and 11 deletions
5
.github/workflows/failure-cases.yml
vendored
5
.github/workflows/failure-cases.yml
vendored
|
@ -11,26 +11,27 @@ env:
|
||||||
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
CACHE_KEY_PREFIX: ${{github.workflow}}#${{github.run_number}}-
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|
||||||
wrapper-missing:
|
wrapper-missing:
|
||||||
|
continue-on-error: true
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Test wrapper missing
|
- name: Test wrapper missing
|
||||||
uses: ./
|
uses: ./
|
||||||
continue-on-error: true
|
|
||||||
with:
|
with:
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help
|
arguments: help
|
||||||
|
|
||||||
bad-configuration:
|
bad-configuration:
|
||||||
|
continue-on-error: true
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout sources
|
- name: Checkout sources
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Test bad config value
|
- name: Test bad config value
|
||||||
uses: ./
|
uses: ./
|
||||||
continue-on-error: true
|
|
||||||
with:
|
with:
|
||||||
build-root-directory: __tests__/samples/no-wrapper
|
build-root-directory: __tests__/samples/no-wrapper
|
||||||
arguments: help
|
arguments: help
|
||||||
|
|
16
src/main.ts
16
src/main.ts
|
@ -9,12 +9,12 @@ import * as provision from './provision'
|
||||||
|
|
||||||
// Invoked by GitHub Actions
|
// Invoked by GitHub Actions
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
|
||||||
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
|
||||||
|
|
||||||
await caches.restore(buildRootDirectory)
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const workspaceDirectory = process.env[`GITHUB_WORKSPACE`] || ''
|
||||||
|
const buildRootDirectory = resolveBuildRootDirectory(workspaceDirectory)
|
||||||
|
|
||||||
|
await caches.restore(buildRootDirectory)
|
||||||
|
|
||||||
const args: string[] = parseCommandLineArguments()
|
const args: string[] = parseCommandLineArguments()
|
||||||
// TODO: instead of running with no-daemon, run `--stop` in post action.
|
// TODO: instead of running with no-daemon, run `--stop` in post action.
|
||||||
args.push('--no-daemon')
|
args.push('--no-daemon')
|
||||||
|
@ -39,10 +39,10 @@ export async function run(): Promise<void> {
|
||||||
core.setFailed(`Gradle process exited with status ${result.status}`)
|
core.setFailed(`Gradle process exited with status ${result.status}`)
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (!(error instanceof Error)) {
|
core.setFailed(String(error))
|
||||||
throw error
|
if (error instanceof Error && error.stack) {
|
||||||
|
core.info(error.stack)
|
||||||
}
|
}
|
||||||
core.setFailed(error.message)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
10
src/post.ts
10
src/post.ts
|
@ -1,8 +1,16 @@
|
||||||
|
import * as core from '@actions/core'
|
||||||
import * as caches from './caches'
|
import * as caches from './caches'
|
||||||
|
|
||||||
// Invoked by GitHub Actions
|
// Invoked by GitHub Actions
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
await caches.save()
|
try {
|
||||||
|
await caches.save()
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(String(error))
|
||||||
|
if (error instanceof Error && error.stack) {
|
||||||
|
core.info(error.stack)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
run()
|
run()
|
||||||
|
|
Loading…
Reference in a new issue