-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaction.yaml
138 lines (125 loc) · 4.85 KB
/
action.yaml
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
name: Update Supergraph
description: Perform Supergraph composition with appropraite subgraph schema and metadata and create PR
inputs:
name:
description: A unique name given to the subgraph
required: true
routing-url:
description: The public-facing URL of the subgraph
required: true
subgraph-schema-artifact:
description: The name of an artifact from this workflow run containing the subgraph schema
required: true
subgraph-schema-filename:
description: The name of the subgraph schema file within the artifact
required: true
supergraph-schema-artifact:
description: The name of the artifact to be created containing the supergraph schema
required: true
default: supergraph
supergraph-schema-filename:
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.compose.outputs.artifact-id }}
supergraph-schema-artifact-url:
description: The url of the artifact containing the supergraph schema
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]
with:
name: ${{ inputs.subgraph-schema-artifact }}
path: /tmp/schema/
- name: Add Subgraph schema to schema/ directory
shell: bash
run: mv /tmp/schema/${{ inputs.subgraph-schema-filename}} schema/${{ inputs.name }}.graphql
- name: Add Subgraph workflows to Supergraph config
shell: bash
run: >
yq -i
'
.subgraphs.${{ inputs.name }}={
"routing_url":"${{ inputs.routing-url}}",
"schema":{
"file":"schema/${{ inputs.name }}.graphql"
}
}
'
supergraph-config.yaml
- name: Install Rover CLI
shell: bash
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "$HOME/.rover/bin" >> $GITHUB_PATH
- name: Compose Supergraph Schema
shell: bash
run: >
rover supergraph compose
--config supergraph-config.yaml
--elv2-license=accept
> ${{ inputs.supergraph-schema-filename }}
- name: Upload Supergraph Artifact
id: supergraph-artifact
uses: actions/[email protected]
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