Skip to content

Commit fd66ffa

Browse files
Refactoring so that it works as a post-command (#1)
* Refactoring so that it works as a post-command * shellcheck
1 parent ed68025 commit fd66ffa

File tree

7 files changed

+81
-38
lines changed

7 files changed

+81
-38
lines changed

.buildkite/pipeline.yml

Lines changed: 0 additions & 17 deletions
This file was deleted.

.github/workflows/ci.yaml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Checks
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
9+
jobs:
10+
ruby-test:
11+
name: ruby test
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- uses: isbang/[email protected]
16+
with:
17+
compose-file: "./docker-compose.yml"
18+
services: ruby
19+
plugin-test:
20+
name: plugin test
21+
runs-on: ubuntu-latest
22+
steps:
23+
- uses: actions/checkout@v2
24+
- uses: isbang/[email protected]
25+
with:
26+
compose-file: "./docker-compose.yml"
27+
services: plugin
28+
plugin-lint:
29+
name: plugin test
30+
runs-on: ubuntu-latest
31+
steps:
32+
- uses: actions/checkout@v2
33+
- uses: isbang/[email protected]
34+
with:
35+
compose-file: "./docker-compose.yml"
36+
services: lint
37+
shellcheck:
38+
name: Shellcheck
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- name: Run ShellCheck
43+
uses: ludeeus/action-shellcheck@master
44+
with:
45+
scandir: './hooks'

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
/tests/tmp
1+
/tests/tmp
2+
.idea

docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
version: '2'
22
services:
3+
lint:
4+
image: buildkite/plugin-linter:latest
5+
command: ['--id', 'juandiegopalomino/junit-annotate-local']
6+
volumes:
7+
- ".:/plugin"
38
plugin:
49
image: buildkite/plugin-tester:latest@sha256:476a1024936901889147f53d2a3d8e71e99d76404972d583825514f5608083dc
510
volumes:

hooks/command renamed to hooks/post-command

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@ set -euo pipefail
55
PLUGIN_DIR="$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)/.."
66
MAX_SIZE=1024 # in KB
77

8-
echo "--- :junit: Download the junits"
8+
echo "--- :junit: Verify Directory"
9+
10+
if [ ! -d "$BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_DIRECTORY" ]; then
11+
echo "$BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_DIRECTORY does not exist."
12+
fi
913

10-
artifacts_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-artifacts-tmp.XXXXXXXXXX")"
1114
annotation_dir="$(pwd)/$(mktemp -d "junit-annotate-plugin-annotation-tmp.XXXXXXXXXX")"
1215
annotation_path="${annotation_dir}/annotation.md"
1316
annotation_style="info"
1417
fail_build=0
1518

1619
function cleanup {
17-
rm -rf "${artifacts_dir}"
1820
rm -rf "${annotation_dir}"
1921
}
2022

@@ -26,9 +28,7 @@ function check_size {
2628

2729
trap cleanup EXIT
2830

29-
buildkite-agent artifact download \
30-
"${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_ARTIFACTS}" \
31-
"$artifacts_dir"
31+
xmls_dir=$(readlink -f "$BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_DIRECTORY")
3232

3333
echo "--- :junit: Processing the junits"
3434

@@ -37,17 +37,17 @@ docker \
3737
--log-level "error" \
3838
run \
3939
--rm \
40-
--volume "$artifacts_dir:/junits" \
40+
--volume "$xmls_dir:/junits" \
4141
--volume "$PLUGIN_DIR/ruby:/src" \
42-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN:-}" \
43-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT:-}" \
44-
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST:-}" \
42+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_JOB_UUID_FILE_PATTERN=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_JOB_UUID_FILE_PATTERN:-}" \
43+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAILURE_FORMAT=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAILURE_FORMAT:-}" \
44+
--env "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_REPORT_SLOWEST=${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_REPORT_SLOWEST:-}" \
4545
ruby:2.7-alpine ruby /src/bin/annotate /junits \
4646
> "$annotation_path"
4747

4848
if [[ $? -eq 64 ]]; then # special exit code to signal test failures
4949
annotation_style="error"
50-
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then
50+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAIL_BUILD_ON_ERROR:-false}" =~ (true|on|1) ]]; then
5151
fail_build=1
5252
fi
5353
fi
@@ -63,8 +63,15 @@ if grep -q "<details>" "$annotation_path"; then
6363
echo "$msg"
6464
else
6565
echo "--- :buildkite: Creating annotation"
66+
args=(
67+
--context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_CONTEXT:-junit}"
68+
--style "$annotation_style"
69+
)
70+
if [[ "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_APPEND:-false}" =~ (true|on|1) ]]; then
71+
args+=( --append )
72+
fi
6673
# shellcheck disable=SC2002
67-
cat "$annotation_path" | buildkite-agent annotate --context "${BUILDKITE_PLUGIN_JUNIT_ANNOTATE_CONTEXT:-junit}" --style "$annotation_style"
74+
cat "$annotation_path" | buildkite-agent annotate "${args[@]}"
6875
fi
6976
fi
7077

plugin.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
name: Junit Annotate
2-
description: Annotates your build using JUnit XML reports
3-
author: https://github.com/buildkite
1+
name: Junit Annotate Local
2+
description: Annotates your build using JUnit XML reports from local files
3+
author: https://github.com/rippling
44
requirements:
55
- docker
66
configuration:
77
properties:
8-
artifacts:
8+
directory:
99
type: string
1010
job-uuid-file-pattern:
1111
type: string
@@ -20,6 +20,8 @@ configuration:
2020
type: string
2121
report-slowest:
2222
type: integer
23+
append:
24+
type: boolean
2325
required:
24-
- artifacts
26+
- directory
2527
additionalProperties: false

ruby/tests/annotate_test.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@
202202
end
203203

204204
it "accepts custom regex filename patterns for job id" do
205-
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_JOB_UUID_FILE_PATTERN=junit-(.*)-custom-pattern.xml", "#{__dir__}/../bin/annotate", "#{__dir__}/custom-job-uuid-pattern/")
205+
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_JOB_UUID_FILE_PATTERN=junit-(.*)-custom-pattern.xml", "#{__dir__}/../bin/annotate", "#{__dir__}/custom-job-uuid-pattern/")
206206

207207
assert_equal <<~OUTPUT, output
208208
Parsing junit-123-456-custom-pattern.xml
@@ -235,7 +235,7 @@
235235
end
236236

237237
it "uses the file path instead of classname for annotation content when specified" do
238-
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_FAILURE_FORMAT=file", "#{__dir__}/../bin/annotate", "#{__dir__}/test-failure-and-error/")
238+
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_FAILURE_FORMAT=file", "#{__dir__}/../bin/annotate", "#{__dir__}/test-failure-and-error/")
239239

240240
assert_equal <<~OUTPUT, output
241241
Parsing junit-1.xml
@@ -493,7 +493,7 @@
493493
end
494494

495495
it "reports specified amount of slowest tests" do
496-
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_REPORT_SLOWEST=5", "#{__dir__}/../bin/annotate", "#{__dir__}/no-test-failures/")
496+
output, status = Open3.capture2e("env", "BUILDKITE_PLUGIN_JUNIT_ANNOTATE_LOCAL_REPORT_SLOWEST=5", "#{__dir__}/../bin/annotate", "#{__dir__}/no-test-failures/")
497497

498498
assert_equal <<~OUTPUT, output
499499
Parsing junit-1.xml

0 commit comments

Comments
 (0)