Skip to content

Commit

Permalink
Merge pull request #2563 from buildkite/fix-graphql-docs
Browse files Browse the repository at this point in the history
Fix GraphQL pipeline
  • Loading branch information
dannymidnight authored Nov 20, 2023
2 parents a671a58 + d1a7f6a commit 46ed55a
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 27 deletions.
10 changes: 0 additions & 10 deletions .buildkite/pipeline.graphql.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
steps:
- label: Update GraphQL docs
command: .buildkite/update_graphql_docs
plugins:
- docker-compose#v4.9.0:
run: app
mount-ssh-agent: true
mount-buildkite-agent: true
env:
- API_ACCESS_TOKEN
- GIT_NAME
- GIT_EMAIL
- GH_TOKEN
19 changes: 9 additions & 10 deletions .buildkite/update_graphql_docs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ set -euo pipefail
. bin/utils.sh

echo "+++ Fetch latest schema (via GraphQL introspection)"
rake graphql:fetch_schema >| data/graphql/schema.graphql
docker compose run \
--no-deps \
-e API_ACCESS_TOKEN \
app \
bash -c "rake graphql:fetch_schema >| data/graphql/schema.graphql"

echo "+++ Check for schema changes"
if git diff --exit-code --quiet data/graphql/schema.graphql; then
Expand All @@ -21,12 +25,12 @@ BRANCH=buildkite-docs-bot/graphql/$(git rev-parse --short :data/graphql/schema.g
PULL_REQUEST_NUMBER=$(get_branch_pull_request_number $BRANCH)

if [ -n "$PULL_REQUEST_NUMBER" ]; then
buildkite-agent annotate "Nothing to change, pull request [#$PULL_REQUEST_NUMBER](https://github.com/buildkite/docs/pull/$PULL_REQUEST_NUMBER) awaiting approval." --style "info"
buildkite-agent annotate "Nothing to change, pull request [#$PULL_REQUEST_NUMBER](https://github.com/buildkite/docs/pull/$PULL_REQUEST_NUMBER) awaiting approval." --style "info"
exit 0
fi

echo "+++ Generate GraphQL docs"
./scripts/generate-graphql-api-content.sh
docker compose run --no-deps app rake graphql:generate

echo "--- Commit and push changes"
git add .
Expand All @@ -37,10 +41,5 @@ git commit -m "Update GraphQL docs"
git push -u origin $BRANCH

echo "+++ Create pull request"
gh pr create \
--title "Update GraphQL docs" \
--body "This is an automated PR based on the current GraphQL schema" \
| buildkite-agent annotate --style "success"

# Auto-merge PR once checks have passed
gh pr merge -m --auto
create_pull_request "Update GraphQL docs" "This is an automated PR based on the current GraphQL schema" \
| jq ".url" | buildkite-agent annotate --style "success"
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ If you need to fetch the latest schema you can either:
API_ACCESS_TOKEN=xxx rake graphql:fetch_schema >| data/graphql/schema.graphql

# Generate docs based on latest schema
./scripts/generate-graphql-api-content.sh
rake graphql:generate
```


Expand Down
10 changes: 10 additions & 0 deletions bin/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,13 @@ function post_github_comment() {
--data "{\"body\":\"$2\"}" \
https://api.github.com/repos/buildkite/docs/issues/$1/comments
}

function create_pull_request() {
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
--data "{\"title\":\"$1\", "body\":\"$2\"}" \
https://api.github.com/repos/buildkite/docs/pulls"
}
5 changes: 5 additions & 0 deletions lib/tasks/graphql.rake
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ namespace :graphql do

puts GraphQL::Client.load_schema(HTTP).to_definition
end

desc "Generate GraphQL docs and navigation from GraphQL schema"
task :generate do
ruby "scripts/generate_graphql_api_content.rb"
end
end
5 changes: 0 additions & 5 deletions scripts/generate-graphql-api-content.sh

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/generate_graphql_api_content.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
schema_type_data["kind"].to_s.downcase
end

Dir.mkdir("#{schemas_dir}/#{sub_dir}") unless File.exists?("#{schemas_dir}/#{sub_dir}")
Dir.mkdir("#{schemas_dir}/#{sub_dir}") unless File.exist?("#{schemas_dir}/#{sub_dir}")
File.write("#{schemas_dir}/#{sub_dir}/#{name.downcase}.md", render_page(schema_type_data, sub_dir.capitalize.pluralize))
end
end
Expand Down

0 comments on commit 46ed55a

Please sign in to comment.