-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
96 lines (81 loc) · 3.64 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
name: "index-digest"
author: "@macbre"
description: "An action to run https://github.com/macbre/index-digest"
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#branding
branding:
icon: "database"
color: "green"
inputs:
index-digest-version:
description: "The version of index-digest to install"
required: true
default: "1.5.1"
index-digest-dsn:
description: "DSN pointing at the database to check"
require: true
index-digest-sql-log:
description: "File with SQL queries to check against the database"
require: false
default: "/tmp/index_digest_empty_log.sql"
index-digest-checks:
description: "Which index-digest checks to perform"
require: true
default: "redundant_indices,missing_primary_index,not_used_indices,queries_not_using_index,queries_using_filesort,queries_using_temporary,queries_using_full_table_scan"
index-digest-report-file:
description: "Where to save YAML report file"
required: true
default: "/tmp/index-digest.yml"
fail-on-issues:
description: "Should the action fail when any issue is reported"
required: false
default: false
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs-for-composite-run-steps-actions
outputs:
number-of-issues:
description: 'Number of issues reported'
value: ${{ steps.process-the-report-file.outputs.number-of-issues }}
runs:
using: "composite"
steps:
# https://github.com/macbre/index-digest/pkgs/container/index-digest
- shell: bash
id: pull-and-set-up-index-digest-environment
run: |
echo "Pulling index-version ${{ inputs.index-digest-version }} from ghcr.io repository ..."
docker pull --quiet ghcr.io/macbre/index-digest:${{ inputs.index-digest-version }}
echo "Pulled $( docker run ghcr.io/macbre/index-digest:${{ inputs.index-digest-version }} --version )"
echo "Using SQL log file: ${{ inputs.index-digest-sql-log }} ..."
# create an empty SQL log file (will be used when "index-digest-sql-log" is not provided)
touch /tmp/index_digest_empty_log.sql
- shell: bash
id: run-index-digest
run: |
set -euxo pipefail
docker run --network=host --volume="${{ inputs.index-digest-sql-log }}:/tmp/log.sql:ro" \
-t ghcr.io/macbre/index-digest:${{ inputs.index-digest-version }} \
--checks=${{ inputs.index-digest-checks }} \
--sql-log=/tmp/log.sql \
--format=yaml \
${{ inputs.index-digest-dsn }} | tee ${{ inputs.index-digest-report-file }}
# process the report file
# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#outputs
- shell: bash
id: process-the-report-file
run: |
echo -n "Counting the number of issues reported ... "
number_of_issues=$(egrep '^\- type:' --count ${{ inputs.index-digest-report-file }} || true)
echo "got ${number_of_issues} issue(s)"
echo "::set-output name=number-of-issues::${number_of_issues}"
# fail on issues (see #9)
- shell: bash
name: Verify index-digest results and fail on issues
run: |
if [ "${{ inputs.fail-on-issues }}" = "true" ] && [ "${{ steps.process-the-report-file.outputs.number-of-issues }}" -gt 0 ]
then
echo "::warning::index-digest issues reported: ${{ steps.process-the-report-file.outputs.number-of-issues }}"
echo "::group::index-digest report"
cat ${{ inputs.index-digest-report-file }}
echo "::endgroup::"
echo "::error::index-digest database performance check failed"
exit 1
fi