Skip to content

Commit

Permalink
feat: combine compose and update workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
garryod committed Jan 31, 2025
1 parent ce7f413 commit 902f664
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 235 deletions.
9 changes: 2 additions & 7 deletions .github/workflows/_actions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,14 @@ jobs:
name: test-update-schema
path: test-schema.graphql

- name: Compose Supergraph
uses: ./actions/compose
- name: Update Supergraph
uses: .
with:
name: test
routing-url: https://example.com/graphql
subgraph-schema-artifact: test-compose-schema
subgraph-schema-filename: test-schema.graphql
supergraph-schema-artifact: compose-supergraph

- name: Update Supergraph
uses: ./actions/update
with:
name: test
github-app-id: 1010045
github-app-private-key: ${{ secrets.GRAPH_FEDERATOR }}
publish: false
92 changes: 92 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
61 changes: 57 additions & 4 deletions actions/compose/action.yml → action.yml
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:
Expand All @@ -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]
Expand Down Expand Up @@ -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
72 changes: 0 additions & 72 deletions actions/compose/README.md

This file was deleted.

74 changes: 0 additions & 74 deletions actions/update/README.md

This file was deleted.

Loading

0 comments on commit 902f664

Please sign in to comment.