-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: combine compose and update workflows
- Loading branch information
Showing
7 changed files
with
158 additions
and
235 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,95 @@ Docs can be found [on github pages](https://diamondlightsource.github.io/graph-f | |
- `workflows/compose`: A [GitHub action](https://github.com/features/actions) used to perform schema composition | ||
- `workflows/update`: A [GitHub action](https://github.com/features/actions) used to create subgraph schema update pull requests | ||
- `mkdocs.yaml` & `docs/`: User facing documentation, built with [mkdocs](https://www.mkdocs.org/) | ||
|
||
## Action | ||
|
||
### Update Supergraph Schema | ||
|
||
This workflow may be used to create or update a Subgraph Schema by adding the schema to the `schema/` directory and an entry in the `supergraph-config.yaml` of this repository. | ||
|
||
#### Usage | ||
|
||
This workflow must be called after `diamondlightsource/graph-federation/actions/compose` | ||
|
||
##### Inputs | ||
|
||
```yaml | ||
- uses: diamondlightsource/graph-federation/actions/update@v1 | ||
with: | ||
# A unique name given to the subgraph. | ||
# Required. | ||
name: | ||
|
||
# The public-facing URL of the subgraph. | ||
# Required. | ||
routing-url: | ||
|
||
# The name of an artifact from this workflow run containing the subgraph schema. | ||
# Required. | ||
subgraph-schema-artifact: | ||
|
||
# The name of the subgraph schema file within the artifact. | ||
# Required. | ||
subgraph-schema-filename: | ||
|
||
# The name of the artifact to be created containing the supergraph schema. | ||
# Optional. Default is 'supergraph' | ||
supergraph-schema-artifact: | ||
|
||
# The name of the supergraph schema file within the created artifact. | ||
# Optional. Default is 'supergraph.graphql' | ||
supergraph-schema-filename: | ||
|
||
# The ID of the GitHub App used to create the commit / pull request | ||
# Required. | ||
github-app-id: | ||
|
||
# The private key of the GitHub App used to create the commit / pull request | ||
# Required. | ||
github-app-private-key: | ||
|
||
# A boolean value which determines whether a pull request should be created | ||
# Optional. Default is ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} | ||
publish: | ||
``` | ||
##### Outputs | ||
| Name | Description | Example | | ||
| ------------------------------ | -------------------------------------------------------- | ------------------------------------------------------------------------- | | ||
| supergraph-schema-artifact-id | The id of the artifact containing the supergraph schema | 1234 | | ||
| supergraph-schema-artifact-url | The url of the artifact containing the supergraph schema | <https://github.com/example-org/example-repo/actions/runs/1/artifacts/1234> | | ||
##### Example | ||
```yaml | ||
steps: | ||
- name: Create Test Subgraph schema | ||
run: > | ||
echo " | ||
schema { | ||
query: Query | ||
} | ||
type Query { | ||
_empty: String | ||
} | ||
" > test-schema.graphql | ||
- name: Upload Test Subgraph schema | ||
uses: actions/[email protected] | ||
with: | ||
name: test-schema | ||
path: test-schema.graphql | ||
|
||
- name: Update Supergraph | ||
uses: diamondlightsource/graph-federation/actions/update@v1 | ||
with: | ||
name: test | ||
routing-url: https://example.com/graphql | ||
subgraph-schema-artifact: test-schema | ||
subgraph-schema-filename: test-schema.graphql | ||
github-app-id: 1010045 | ||
github-app-private-key: ${{ secrets.GRAPH_FEDERATOR }} | ||
publish: 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,5 @@ | ||
name: Compose Supergraph | ||
description: Perform supergraph composition with appropraite subgraph schema and metadata | ||
name: Update Supergraph | ||
description: Perform Supergraph composition with appropraite subgraph schema and metadata and create PR | ||
|
||
inputs: | ||
name: | ||
|
@@ -22,22 +22,42 @@ inputs: | |
description: The name of the supergraph schema file within the created artifact | ||
required: true | ||
default: supergraph.graphql | ||
github-app-id: | ||
description: The ID of the GitHub App used to create the commit / pull request | ||
required: false | ||
github-app-private-key: | ||
description: The private key of the GitHub App used to create the commit / pull request | ||
required: false | ||
publish: | ||
description: A boolean value which determines whether a branch and pull request should be created | ||
required: true | ||
default: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }} | ||
|
||
outputs: | ||
supergraph-schema-artifact-id: | ||
description: The id of the artifact containing the supergraph schema | ||
value: ${{ steps.supergraph-artifact.outputs.artifact-id }} | ||
value: ${{ steps.compose.outputs.artifact-id }} | ||
supergraph-schema-artifact-url: | ||
description: The url of the artifact containing the supergraph schema | ||
value: ${{ steps.supergraph-artifact.outputs.artifact-url }} | ||
value: ${{ steps.compose.outputs.artifact-url }} | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: Create GitHub App Token | ||
id: app-token | ||
uses: actions/[email protected] | ||
with: | ||
app-id: ${{ inputs.github-app-id }} | ||
private-key: ${{ inputs.github-app-private-key }} | ||
owner: DiamondLightSource | ||
repositories: graph-federation | ||
|
||
- name: Checkout Graph Federation source | ||
uses: actions/[email protected] | ||
with: | ||
repository: DiamondLightSource/graph-federation | ||
token: ${{ steps.app-token.outputs.token }} | ||
|
||
- name: Download Subgraph schema | ||
uses: actions/[email protected] | ||
|
@@ -83,3 +103,36 @@ runs: | |
with: | ||
name: ${{ inputs.supergraph-schema-artifact }} | ||
path: ./${{ inputs.supergraph-schema-filename }} | ||
|
||
- name: Configure Git | ||
shell: bash | ||
run: | | ||
USER_ID="$(gh api "/users/${{ steps.app-token.outputs.app-slug }}[bot]" --jq .id)" | ||
git config --local user.name "${{ steps.app-token.outputs.app-slug }}[bot]" | ||
git config --local user.email "$USER_ID+${{ steps.app-token.outputs.app-slug }}[bot]@users.noreply.github.com" | ||
env: | ||
GH_TOKEN: ${{ steps.app-token.outputs.token }} | ||
|
||
- name: Create commit | ||
id: commit | ||
shell: bash | ||
run: | | ||
git checkout -b ${{ inputs.name }}-${{ github.ref_name }} | ||
git fetch | ||
git add supergraph-config.yaml schema/${{ inputs.name }}.graphql | ||
if ! git diff --staged --quiet --exit-code supergraph-config.yaml schema/${{ inputs.name }}.graphql; then | ||
git commit -m "Update ${{ inputs.name }} schema to ${{ github.ref_name }}" | ||
echo "changed=true" >> $GITHUB_OUTPUT | ||
fi | ||
- name: Create PR | ||
if: inputs.publish == 'true' && steps.commit.outputs.changed == 'true' | ||
shell: bash | ||
run: | | ||
git push origin ${{ inputs.name }}-${{ github.ref_name }} --force-with-lease | ||
gh auth login --with-token <<< ${{ steps.app-token.outputs.token }} | ||
gh pr create \ | ||
--title "chore: Update ${{ inputs.name }} subgraph to ${{ github.ref_name }}" \ | ||
--body "" \ | ||
--head ${{ inputs.name }}-${{ github.ref_name }} \ | ||
--base main |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.