Skip to content

Commit 1134c89

Browse files
authored
Extend behavior of fail-on-error option to setup failures (#226)
* Technically an enhancement, these changes make the action behave as many customers already expect by ignoring any and all failures when the `fail-on-error` input is set to `false`. * Adds logic to handle any failures in "setup" tasks, including downloading the associated binary, verifying the binary, and finding the binary by its expected name after extraction. * The new logic checks these actions and exits with exit code `1` on failure, except if `fail-on-error` input is set to `true`, in which case it returns exit code `0`. * Adds a matrix workflow that tests the action for each `os` and each key binary command (`report` and `done`). Each of these scenarios implicitly tests our setup tasks since they run first in each scenario. * Extends the behavior of `debug: true` to flip the shell-specific debug flag for each `os` including `set -x` for `linux` and `macos` and `Set-PSDebug -Trace 1` for `windows`
1 parent 643bc37 commit 1134c89

File tree

2 files changed

+117
-11
lines changed

2 files changed

+117
-11
lines changed

.github/workflows/test.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Test GitHub Action
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
test-action:
13+
runs-on: ${{ matrix.os }}
14+
strategy:
15+
matrix:
16+
os: [ubuntu-latest, windows-latest, macos-latest]
17+
action: [report, done] # Note: We're also testing 'install' since it's implicitly in each of these two actions
18+
fail_on_error: [true, false]
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v3
22+
23+
- name: Set up environment (Linux)
24+
if: ${{ matrix.os == 'ubuntu-latest' }}
25+
shell: bash
26+
run: |
27+
echo "Running on Linux"
28+
- name: Set up environment (MacOS)
29+
if: ${{ matrix.os == 'macos-latest' }}
30+
shell: bash
31+
run: |
32+
echo "Running on macOS"
33+
- name: Set up environment (Windows)
34+
if: ${{ matrix.os == 'windows-latest' }}
35+
shell: pwsh
36+
run: |
37+
echo "Running on Windows"
38+
39+
- name: Run Test Action
40+
uses: ./
41+
with:
42+
github-token: ${{ secrets.GITHUB_TOKEN }}
43+
fail-on-error: ${{ matrix.fail_on_error }}
44+
debug: true
45+
parallel-finished: ${{ matrix.action == 'done' }} # Only set 'parallel-finished' to true when testing 'done'
46+
env:
47+
CI: true
48+
continue-on-error: ${{ matrix.fail_on_error }}

action.yml

+69-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# action.yml
22
name: 'Coveralls GitHub Action'
33
description: 'Send test coverage data to Coveralls.io for analysis, change tracking, and notifications.'
4-
author: 'Nick Merwin (Coveralls, Inc.)'
4+
author: Coveralls.io
55
inputs:
66
github-token:
77
description: 'Put secrets.GITHUB_TOKEN here'
@@ -80,14 +80,28 @@ runs:
8080
if: runner.os == 'macOS'
8181
shell: bash
8282
run: |
83+
# Enable debugging if 'debug' is true
84+
[ "${{ inputs.debug }}" == "true" ] && set -x
85+
86+
# Try to install coverage-reporter via Homebrew
8387
brew tap coverallsapp/coveralls --quiet
8488
brew install coveralls --quiet
8589
86-
- name: Report coverage-reporter-version information for macOS
90+
# Check if the binary exists in the possible locations
91+
if [ -f /usr/local/bin/coveralls ]; then
92+
echo "/usr/local/bin" >> $GITHUB_PATH
93+
elif [ -f /opt/homebrew/bin/coveralls ]; then
94+
echo "/opt/homebrew/bin" >> $GITHUB_PATH
95+
else
96+
echo "Coveralls binary not found after installation (MacOS)."
97+
exit 1
98+
fi
99+
100+
- name: Report coverage-reporter-version exception for macOS
87101
if: ${{ runner.os == 'macOS' && inputs.coverage-reporter-version != 'latest' }}
88102
shell: bash
89103
run: |
90-
echo "The coverage-reporter-version parameter is not available on macOS" >&2
104+
echo "The coverage-reporter-version parameter is not available on macOS." >&2
91105
exit 1
92106
93107
- name: Install coveralls reporter (Linux)
@@ -96,18 +110,43 @@ runs:
96110
COVERAGE_REPORTER_VERSION: ${{ inputs.coverage-reporter-version }}
97111
shell: bash
98112
run: |
113+
# Enable debugging if 'debug' is true
114+
[ "${{ inputs.debug }}" == "true" ] && set -x
115+
99116
mkdir -p ~/bin/
100117
cd ~/bin/
101-
if [ $COVERAGE_REPORTER_VERSION == "latest" ]
102-
then
103-
asset_path=latest/download
118+
119+
# Determine which version of coverage-reporter to download
120+
if [ "$COVERAGE_REPORTER_VERSION" == "latest" ]; then
121+
asset_path="latest/download"
104122
else
105123
asset_path="download/${COVERAGE_REPORTER_VERSION}"
106124
fi
107-
curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-linux.tar.gz"
108-
curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-checksums.txt"
109-
cat coveralls-checksums.txt | grep coveralls-linux.tar.gz | sha256sum --check
125+
126+
# Try to download the binary and checksum file
127+
if ! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-linux.tar.gz" ||
128+
! curl -sLO "https://github.com/coverallsapp/coverage-reporter/releases/${asset_path}/coveralls-checksums.txt"; then
129+
echo "Failed to download coveralls binary or checksum (Linux)."
130+
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
131+
exit 1
132+
fi
133+
134+
# Try to verify the downloaded binary
135+
if ! grep coveralls-linux.tar.gz coveralls-checksums.txt | sha256sum --check; then
136+
echo "Checksum verification failed (Linux)."
137+
[ "${{ inputs.fail-on-error }}" == "false" ] && exit 0
138+
exit 1
139+
fi
140+
110141
tar -xzf coveralls-linux.tar.gz
142+
143+
# Check if the binary exists
144+
if [ ! -f ~/bin/coveralls ]; then
145+
echo "Coveralls binary not found after extraction (Linux)."
146+
exit 1
147+
fi
148+
149+
# Cleanup
111150
rm coveralls-checksums.txt
112151
echo ~/bin >> $GITHUB_PATH
113152
@@ -117,6 +156,12 @@ runs:
117156
COVERAGE_REPORTER_VERSION: ${{ inputs.coverage-reporter-version }}
118157
shell: pwsh
119158
run: |
159+
# Enable debugging if 'debug' is true
160+
if ("${{ inputs.debug }}" -eq "true") {
161+
Set-PSDebug -Trace 1
162+
}
163+
164+
# Try to download the binary and checksum file
120165
New-Item -Path $env:HOME\bin -ItemType directory -Force
121166
Push-Location $env:HOME\bin
122167
if($env:COVERAGE_REPORTER_VERSION -eq "latest") {
@@ -126,8 +171,21 @@ runs:
126171
Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releases/download/$env:COVERAGE_REPORTER_VERSION/coveralls-windows.exe" -OutFile "coveralls.exe"
127172
Invoke-WebRequest -Uri "https://github.com/coverallsapp/coverage-reporter/releases/download/$env:COVERAGE_REPORTER_VERSION/coveralls-checksums.txt" -OutFile "sha256sums.txt"
128173
}
129-
(Get-FileHash coveralls.exe).Hash -eq (Get-Content ./sha256sums.txt | Where-Object{$_ -match 'windows.exe'} | ForEach-Object{($_ -split "\s+")[0]})
130-
Remove-Item *.txt -Force
174+
175+
# Try to verify the downloaded binary
176+
if ((Get-FileHash coveralls.exe).Hash -ne (Get-Content sha256sums.txt | Select-String 'windows.exe' | ForEach-Object { ($_ -split "\s+")[0] })) {
177+
Write-Host "Checksum verification failed (Windows)."
178+
exit 1
179+
}
180+
181+
# Check if the binary exists
182+
if (!(Test-Path -Path "$env:HOME\bin\coveralls.exe")) {
183+
Write-Host "Coveralls binary not found after download and verification (Windows)."
184+
exit 1
185+
}
186+
187+
# Cleanup
188+
Remove-Item sha256sums.txt -Force
131189
echo $env:HOME\bin | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
132190
133191
- name: Done report

0 commit comments

Comments
 (0)