Skip to content

Commit 8e46ac4

Browse files
authored
Switch to mineunit/mineunit docker image (#15)
* Upgrade mineunit runner to use mineunit/mineunit docker image * Explicit error handling / fail fast where appropriate
1 parent c579ef8 commit 8e46ac4

File tree

6 files changed

+97
-74
lines changed

6 files changed

+97
-74
lines changed

Dockerfile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
FROM mineunit/mineunit:latest
2+
3+
USER root
4+
ENV USER=root
5+
6+
RUN apk add --no-cache bash
7+
8+
COPY scripts /scripts
9+
RUN chmod -R +x /scripts
10+
11+
ENTRYPOINT ["/scripts/entrypoint.sh"]

README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# mineunit-actions
2+
23
GitHub actions for mt-mods/mineunit
34

4-
Executes Lua unit tests with `busted` in `spec` directory with code coverage analysis using `cluacov` and generates badge for coverage.
5+
Executes Lua unit/integration tests with `mineunit` in `spec` directory with code coverage analysis using `cluacov`.
6+
Additionally generates badge parameters for coverage badges as well as plain text coverage reports.
57

68
Example badges:
79
* ![](https://byob.yarr.is/S-S-X/metatool/metatool-coverage)
@@ -19,15 +21,15 @@ name: mineunit
1921
on: [push, pull_request]
2022

2123
jobs:
22-
build:
24+
mineunit:
2325
runs-on: ubuntu-latest
2426
steps:
25-
- uses: actions/checkout@v2
27+
- uses: actions/checkout@v3
2628
- id: mineunit
2729
uses: mt-mods/mineunit-actions@master
2830
with:
2931
badge-color: "CC9909"
30-
- uses: RubbaBoy/BYOB@v1.2.0
32+
- uses: RubbaBoy/BYOB@v1.3.0
3133
with:
3234
NAME: "${{ steps.mineunit.outputs.badge-name }}"
3335
LABEL: "${{ steps.mineunit.outputs.badge-label }}"
@@ -38,21 +40,24 @@ jobs:
3840
3941
Optional parameters for `mt-mods/mineunit-actions`:
4042

41-
* **`working-directory`** Working directory for unit tests
42-
* **`badge-name`** Code coverage badge name
43-
* **`badge-label`** Code coverage badge label
44-
* **`badge-color`** Code coverage badge color
45-
* **`mineunit-version`** Mineunit version
43+
* **`working-directory`** Working directory for unit tests, can be used when testing modpacks or multiple mods.
44+
* **`badge-name`** Code coverage badge name.
45+
* **`badge-label`** Code coverage badge label.
46+
* **`badge-color`** Code coverage badge color.
47+
* **`mineunit-args`** Mineunit extra arguments, for example to specify `--engine-version 5.7.0`.
48+
* **`mineunit-version`** Mineunit version.
4649

4750
Outputs:
4851

49-
* **`steps.mineunit.outputs.badge-name`** Code coverage badge name waiting for issues/#1
50-
* **`steps.mineunit.outputs.badge-label`** Code coverage badge label waiting for issues/#1
51-
* **`steps.mineunit.outputs.badge-status`** Code coverage badge status waiting for issues/#1
52-
* **`steps.mineunit.outputs.badge-color`** Code coverage badge color waiting for issues/#1
53-
* **`steps.mineunit.outputs.mineunit-stdout`** Stdout produced during busted run
54-
* **`steps.mineunit.outputs.mineunit-spec-missing`** Set to true if no spec files found for busted
55-
* **`steps.mineunit.outputs.mineunit-report`** Mineunit detailed test report
56-
* **`steps.mineunit.outputs.coverage-total`** Total test coverage percentage
57-
* **`steps.mineunit.outputs.coverage-files`** Number of files tested and total number of source files
58-
* **`steps.mineunit.outputs.help-busted-spec-missing`** Help for situation where spec files could not be loaded
52+
* **`steps.mineunit.outputs.badge-name`** Code coverage badge name.
53+
* **`steps.mineunit.outputs.badge-label`** Code coverage badge label.
54+
* **`steps.mineunit.outputs.badge-status`** Code coverage badge status.
55+
* **`steps.mineunit.outputs.badge-color`** Code coverage badge color.
56+
* **`steps.mineunit.outputs.mineunit-stdout`** Stdout produced during mineunit run.
57+
* **`steps.mineunit.outputs.mineunit-spec-missing`** Set to true if no spec files found for busted.
58+
* **`steps.mineunit.outputs.mineunit-report`** Mineunit code coverage summary report.
59+
* **`steps.mineunit.outputs.coverage-total`** Total test coverage percentage.
60+
* **`steps.mineunit.outputs.coverage-files`** Number of files tested and total number of source files.
61+
* **`steps.mineunit.outputs.help-busted-spec-missing`** Help for situation where spec files could not be loaded.
62+
63+
Based on Docker image https://hub.docker.com/r/mineunit/mineunit

action.yml

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,26 @@ outputs:
3333
# Generated or supplied badge properties
3434
badge-name:
3535
description: "Code coverage badge name waiting for issues/#1"
36-
value: ${{ steps.badge-wrapper-actions-issue-1.outputs.badge-name }}
3736
badge-label:
3837
description: "Code coverage badge label waiting for issues/#1"
39-
value: ${{ steps.badge-wrapper-actions-issue-1.outputs.badge-label }}
4038
badge-status:
4139
description: "Code coverage badge status waiting for issues/#1"
42-
value: "${{ steps.mineunit-coverage.outputs.total }} in ${{ steps.mineunit-coverage.outputs.files }} files"
4340
badge-color:
4441
description: "Code coverage badge color waiting for issues/#1"
45-
value: ${{ steps.badge-wrapper-actions-issue-1.outputs.badge-color }}
4642

4743
# Mineunit test framework output
4844
mineunit-stdout:
4945
description: "Stdout produced during busted run"
50-
value: ${{ steps.mineunit-tests.outputs.stdout }}
5146
mineunit-spec-missing:
5247
description: "Set to true if no spec files found for busted"
53-
value: ${{ steps.mineunit-tests.outputs.spec-missing }}
5448

5549
mineunit-report:
5650
description: "Mineunit detailed test report"
57-
value: ${{ steps.mineunit-report.outputs.report }}
5851

5952
coverage-total:
6053
description: "Total test coverage percentage"
61-
value: ${{ steps.mineunit-coverage.outputs.total }}
6254
coverage-files:
6355
description: "Number of files tested and total number of source files"
64-
value: ${{ steps.mineunit-coverage.outputs.files }}
6556

6657
# Help content / on demand documentation
6758
help-busted-spec-missing:
@@ -79,49 +70,5 @@ outputs:
7970
```
8071
8172
runs:
82-
using: composite
83-
steps:
84-
- name: install mineunit
85-
shell: bash
86-
run: |
87-
sudo apt-get install -y luarocks > /dev/null
88-
luarocks install --server=https://luarocks.org/dev --local mineunit ${{ inputs.mineunit-version }}
89-
- id: mineunit-tests
90-
name: mineunit runner
91-
working-directory: "${{ inputs.working-directory }}"
92-
shell: bash
93-
run: |
94-
set +eo pipefail
95-
exec 3>&1
96-
OUT="$($HOME/.luarocks/bin/mineunit -c ${{ inputs.mineunit-args }} | tee >(cat - >&3); exit ${PIPESTATUS[0]})"
97-
ERR=$?
98-
exec 3>&-
99-
grep_eronly=(grep '0 successes / 0 failures / [1-9] error.\? / 0 pending')
100-
grep_nospec=(grep 'No test files found')
101-
("${grep_eronly[@]}"<<<"$OUT" && "${grep_nospec[@]}"<<<"$OUT")&>/dev/null && echo "spec-missing=true" >> $GITHUB_OUTPUT
102-
OUT="$(sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g'<<<"$OUT")"
103-
printf 'stdout<<END-OF-MINEUNIT-CONTENT\n%s\nEND-OF-MINEUNIT-CONTENT' "${OUT}" >> $GITHUB_OUTPUT
104-
exit $ERR
105-
- id: mineunit-report
106-
name: mineunit coverage report
107-
working-directory: "${{ inputs.working-directory }}"
108-
shell: bash
109-
run: |
110-
$HOME/.luarocks/bin/mineunit -r
111-
OUT="$(awk -v p=0 '/^----/{p++;next}p==2{exit}p' luacov.report.out | sort -hrk4)"
112-
printf 'report<<END-OF-MINEUNIT-CONTENT\n%s\nEND-OF-MINEUNIT-CONTENT' "${OUT}" >> $GITHUB_OUTPUT
113-
- id: mineunit-coverage
114-
name: collect coverage data
115-
working-directory: "${{ inputs.working-directory }}"
116-
shell: bash
117-
run: |
118-
echo "total=$(tail -n 2 luacov.report.out | grep ^Total | grep -o '[0-9.]\+%$')" >> $GITHUB_OUTPUT
119-
awk -v p=0 '/^----/{p++;next}p==2{exit}p' luacov.report.out | sort -hrk4 > luacov.report.sum
120-
echo "files=$(grep -cv '\s0\.00%' luacov.report.sum)/$(wc -l<luacov.report.sum)" >> $GITHUB_OUTPUT
121-
- id: badge-wrapper-actions-issue-1
122-
name: Input wrapper while waiting for actions in actions feature
123-
shell: bash
124-
run: |
125-
echo "badge-name=${{ inputs.badge-name }}" >> $GITHUB_OUTPUT
126-
echo "badge-label=${{ inputs.badge-label }}" >> $GITHUB_OUTPUT
127-
echo "badge-color=${{ inputs.badge-color }}" >> $GITHUB_OUTPUT
73+
using: docker
74+
image: Dockerfile

scripts/entrypoint.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
while read -r ENV; do export -- "$ENV"; done < <(env | grep -- '-[^=]*=' | sed -r ':ape s/^([^-=]*)-/\1_/;tape')
5+
6+
cd "${INPUT_WORKING_DIRECTORY}"
7+
8+
echo "Running tests in $(pwd)"
9+
/scripts/run-tests.sh
10+
ERR=$?
11+
12+
if (($ERR != 0)); then
13+
exit $ERR
14+
fi
15+
16+
echo "Generating report in $(pwd)"
17+
/scripts/run-report.sh
18+
ERR=$?
19+
20+
exit $ERR

scripts/run-report.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set -eo pipefail
3+
4+
# Generate luacov report and write it to output
5+
mineunit -r
6+
OUT="$(awk -v p=0 '/^----/{p++;next}p==2{exit}p' luacov.report.out | sort -hrk4)"
7+
printf 'mineunit-report<<END-OF-MINEUNIT-CONTENT\n%s\nEND-OF-MINEUNIT-CONTENT\n' "${OUT}" >> "${GITHUB_OUTPUT}"
8+
9+
# Read and sort coverage information from luacov report
10+
COVERAGE_TOTAL="$(tail -n 2 luacov.report.out | grep ^Total | grep -o '[0-9.]\+%$')"
11+
echo "coverage-total=${COVERAGE_TOTAL}" >> "${GITHUB_OUTPUT}"
12+
awk -v p=0 '/^----/{p++;next}p==2{exit}p' luacov.report.out | sort -hrk4 > luacov.report.sum
13+
COVERAGE_FILES="$(grep -cv '\s0\.00%' luacov.report.sum)/$(wc -l<luacov.report.sum)"
14+
echo "coverage-files=${COVERAGE_FILES}" >> "${GITHUB_OUTPUT}"
15+
16+
# badge-wrapper-actions-issue-1
17+
echo "badge-name=${INPUT_BADGE_NAME}" >> "${GITHUB_OUTPUT}"
18+
echo "badge-label=${INPUT_BADGE_LABEL}" >> "${GITHUB_OUTPUT}"
19+
echo "badge-color=${INPUT_BADGE_COLOR}" >> "${GITHUB_OUTPUT}"
20+
echo "badge-status=${COVERAGE_TOTAL} in ${COVERAGE_FILES} files" >> "${GITHUB_OUTPUT}"

scripts/run-tests.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
set +eo pipefail
3+
4+
# Run tests, collect output and save return code
5+
exec 3>&1
6+
OUT="$(mineunit -c ${INPUT_MINEUNIT_ARGS} | tee >(cat - >&3); exit ${PIPESTATUS[0]})"
7+
ERR=$?
8+
exec 3>&-
9+
10+
# Check for some hard errors
11+
grep_eronly=(grep '0 successes / 0 failures / [1-9] error.\? / 0 pending')
12+
grep_nospec=(grep 'No test files found')
13+
("${grep_eronly[@]}"<<<"$OUT" && "${grep_nospec[@]}"<<<"$OUT")&>/dev/null && echo "mineunit-spec-missing=true" >> "${GITHUB_OUTPUT}"
14+
15+
# Remove some shell stuff and write output
16+
OUT="$(sed 's/\x1B\[[0-9;]\{1,\}[A-Za-z]//g'<<<"$OUT")"
17+
printf 'mineunit-stdout<<END-OF-MINEUNIT-CONTENT\n%s\nEND-OF-MINEUNIT-CONTENT\n' "${OUT}" >> "${GITHUB_OUTPUT}"
18+
19+
# Return original error code
20+
exit $ERR

0 commit comments

Comments
 (0)