generated from datumforge/template-buildkite-plugin
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
init implementation, adds rover subgraph check command (#2)
Signed-off-by: Golang Lemonade <147884153+golanglemonade@users.noreply.github.com>
- Loading branch information
1 parent
4d27929
commit a8b4732
Showing
11 changed files
with
197 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,4 +26,4 @@ tasks: | |
cmds: | ||
- task: shellcheck | ||
- task: lint | ||
- task: test | ||
- task: test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#!/bin/bash | ||
|
||
set -o nounset # script exits when tries to use undeclared variables == set -u | ||
set -o pipefail # causes pipelines to retain / set the last non-zero status | ||
|
||
# set path | ||
export PATH="$PATH:/var/lib/buildkite-agent/.rover/bin" | ||
|
||
graph_ref=${BUILDKITE_PLUGIN_APOLLO_GRAPH_REF} | ||
subgraph=${BUILDKITE_PLUGIN_APOLLO_SUBGRAPH} | ||
schema=${BUILDKITE_PLUGIN_APOLLO_SCHEMA:-"schema.graphql"} | ||
ignore_existing=${BUILDKITE_PLUGIN_APOLLO_IGNORE_EXISTING:-false} | ||
|
||
debug=${BUILDKITE_PLUGIN_APOLLO_DEBUG:-false} | ||
|
||
if [[ "$debug" == "true" ]]; then | ||
set -o xtrace # trace what's executed == set -x (useful for debugging) | ||
fi | ||
|
||
function main() { | ||
echo +++ :graphql: schema check | ||
|
||
# Run the check command with the rover client | ||
# Example: rover subgraph check golanglemonades-Team@current --name datum --schema schema.graphql | ||
append_command="" | ||
if [[ "$ignore_existing" == "true" ]]; then | ||
append_command="--ignore-existing-lint-violations" | ||
fi | ||
|
||
check_result=$(rover subgraph check "${graph_ref}" --name "${subgraph}" --schema "${schema}" ${append_command} --format=json) | ||
|
||
success=$(echo "$check_result" | jq -r '.data.success') | ||
errors=$(echo "$check_result" | jq -r '.error') | ||
|
||
# Parse the results to display on the top of the buildkite job | ||
lint_result="$check_result" parse_lint_result | ||
|
||
# Start the annotation | ||
echo -e "\`apollo schema check\` results: " | buildkite-agent annotate --context apollo | ||
|
||
# Check for error results, warning results, otherwise it was successful | ||
if [[ "$error_results" != "[]" && "$error_results" != "null" ]]; then | ||
echo -e ":graphql: errors found\n" | buildkite-agent annotate --context "apollo" --style "error" --append | ||
echo -e "**Errors**:\n" | buildkite-agent annotate --context "apollo" --append | ||
echo -e "$(echo "$error_results" |jq -r '"Level | Field | Line | Message", "---| ---| --- |----", (.[] | "\(.level) | \(.coordinate) | \(.start_line)| \(.message)" )')\n\n" | buildkite-agent annotate --context "apollo" --append | ||
if [[ "$warning_results" != ""&& "$warning_results" != "null" ]]; then | ||
echo -e "**Warnings**:\n" | buildkite-agent annotate --context "apollo" --append | ||
echo -e "$(echo "$warning_results" |jq -r '"Level | Field | Line | Message", "---| ---| --- |----", (.[] | "\(.level) | \(.coordinate) | \(.start_line)| \(.message)" )')\n\n" | buildkite-agent annotate --context "apollo" --append | ||
fi | ||
elif [[ "$warning_results" != "[]" && "$warning_results" != "null" ]]; then | ||
# do not error on warnings | ||
echo -e ":graphql: warnings found\n" | buildkite-agent annotate --context "apollo" --style "warning" --append | ||
echo -e "**Warnings**:\n" | buildkite-agent annotate --context "apollo" --append | ||
echo -e "$(echo "$warning_results" |jq -r '"Level | Field | Line | Message", "---| ---| --- |----", (.[] | "\(.level) | \(.coordinate) | \(.start_line)| \(.message)" )')\n\n" | buildkite-agent annotate --context "apollo" --append | ||
else | ||
echo -e ":graphql: no errors found, congrats!\n"| buildkite-agent annotate --context "apollo" --style "success" --append | ||
fi | ||
|
||
if [ "${success}" == "false" ]; then | ||
echo "Error: ${errors}" | ||
exit 1 | ||
fi | ||
|
||
exit 0 | ||
} | ||
|
||
function parse_lint_result () { | ||
warning_results=$(echo "$check_result" | jq '.data.tasks.lint.diagnostics | ||
| map(select(.level == "WARNING" ))') | ||
|
||
error_results=$(echo "$check_result" | jq '.data.tasks.lint.diagnostics | ||
| map(select(.level == "ERROR" ))') | ||
|
||
|
||
# Display these in the logs | ||
echo "$warning_results" |jq | ||
echo "$error_results" |jq | ||
} | ||
|
||
|
||
main |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
--- | ||
name: template-buildkite-plugin | ||
description: what your plugin does | ||
name: Apollo | ||
description: Apollo schema checks with rover | ||
author: Datum | ||
requirements: | ||
- if you have requirements | ||
- bash | ||
- curl | ||
configuration: | ||
properties: | ||
propertyname: | ||
graph-ref: # The name of the apollo graph to check | ||
type: string | ||
required: [] | ||
# - if any properties are required | ||
dependencies: | ||
dependencyname: [dep] | ||
subgraph: # The name of the subgraph to check | ||
type: string | ||
schema: # The schema to check, defaults to schema.graphql | ||
type: string | ||
ignore-existing: # Ignore existing lint errors and only return new errors | ||
type: boolean | ||
default: false | ||
required: | ||
- graph-ref | ||
- subgraph | ||
- schema | ||
additionalProperties: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
{ | ||
"extends": [ | ||
"config:base" | ||
] | ||
} | ||
"$schema": "https://docs.renovatebot.com/renovate-schema.json", | ||
"extends": [ | ||
"config:recommended" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env bats | ||
|
||
load "$BATS_PLUGIN_PATH/load.bash" | ||
|
||
# Uncomment the following line to debug stub failures | ||
# export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty | ||
# export WHICH_STUB_DEBUG=/dev/tty | ||
|
||
@test "default step" { | ||
export BUILDKITE_PIPELINE_DEFAULT_BRANCH="main" | ||
export BUILDKITE_PLUGIN_APOLLO_GRAPH_REF="pets@current" | ||
export BUILDKITE_PLUGIN_APOLLO_SUBGRAPH="cats" | ||
|
||
stub rover \ | ||
'subgraph check $BUILDKITE_PLUGIN_APOLLO_GRAPH_REF --name BUILDKITE_PLUGIN_APOLLO_SUBGRAPH --schema "schema.graphql" --format=json'\ | ||
|
||
run "$PWD/hooks/command" | ||
|
||
assert_success | ||
assert_output --partial "+++ :graphql: schema check" | ||
assert_output --partial "check" | ||
|
||
unstub rover | ||
} | ||
|
||
@test "default step with schema" { | ||
export BUILDKITE_PIPELINE_DEFAULT_BRANCH="main" | ||
export BUILDKITE_PLUGIN_APOLLO_GRAPH_REF="pets@current" | ||
export BUILDKITE_PLUGIN_APOLLO_SUBGRAPH="cats" | ||
export BUILDKITE_PLUGIN_APOLLO_SCHEMA="graphql/schema.graphql" | ||
|
||
stub rover \ | ||
'subgraph check $BUILDKITE_PLUGIN_APOLLO_GRAPH_REF --name BUILDKITE_PLUGIN_APOLLO_SUBGRAPH --schema $BUILDKITE_PLUGIN_APOLLO_SCHEMA --format=json'\ | ||
|
||
run "$PWD/hooks/command" | ||
|
||
assert_success | ||
assert_output --partial "+++ :graphql: schema check" | ||
assert_output --partial "check" | ||
|
||
unstub rover | ||
} | ||
|
||
@test "ignore existing" { | ||
export BUILDKITE_PIPELINE_DEFAULT_BRANCH="main" | ||
export BUILDKITE_PLUGIN_APOLLO_GRAPH_REF="pets@current" | ||
export BUILDKITE_PLUGIN_APOLLO_SUBGRAPH="cats" | ||
export BUILDKITE_PLUGIN_APOLLO_IGNORE_EXISTING="true" | ||
|
||
stub rover \ | ||
'subgraph check $BUILDKITE_PLUGIN_APOLLO_GRAPH_REF --name BUILDKITE_PLUGIN_APOLLO_SUBGRAPH --schema "schema.graphql" --ignore-existing-lint-violations --format=json'\ | ||
|
||
run "$PWD/hooks/command" | ||
|
||
assert_success | ||
assert_output --partial "+++ :graphql: schema check" | ||
assert_output --partial "check" | ||
|
||
unstub rover | ||
} |
This file was deleted.
Oops, something went wrong.