-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathaction.yaml
More file actions
225 lines (202 loc) · 8.06 KB
/
action.yaml
File metadata and controls
225 lines (202 loc) · 8.06 KB
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
name: Update Supergraph
description: Perform supergraph composition (Cosmo) 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
subscription-url:
description: Optional WS/SSE subscription URL for this subgraph in Cosmo config
required: false
subscription-protocol:
description: Subscription protocol (e.g., ws, sse). Only used if subscription-url is set.
required: false
default: ws
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 (e.g. schema.graphql)
required: true
execution-config-artifact:
description: The name of the artifact to be created that contains the Cosmo router execution config
required: true
default: router-execution-config
execution-config-filename:
description: The filename of the composed Cosmo router execution config
required: true
default: router-execution-config.json
supergraph-artifact:
description: The name of the artifact to be created that contains the composed supergraph schema
required: true
default: supergraph-schema
supergraph-filename:
description: The filename of the composed supergraph schema
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: Whether to create a branch and PR
required: true
default: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags') }}
outputs:
execution-config-artifact-id:
description: The id of the artifact containing the Cosmo router execution config
value: ${{ steps.upload_exec.outputs.artifact-id }}
execution-config-artifact-url:
description: The url of the artifact containing the Cosmo router execution config
value: ${{ steps.upload_exec.outputs.artifact-url }}
supergraph-artifact-id:
description: The id of the artifact containing the supergraph schema
value: ${{ steps.upload_sdl.outputs.artifact-id }}
supergraph-artifact-url:
description: The url of the artifact containing the supergraph schema
value: ${{ steps.upload_sdl.outputs.artifact-url }}
runs:
using: composite
steps:
- name: Check Required Inputs
if: inputs.publish == 'true' && ( !inputs.github-app-id || !inputs.github-app-private-key )
shell: bash
run: echo "github-app-id and github-app-private-key inputs must be present when publish is true" && false
- name: Create GitHub App Token
id: app-token
if: inputs.github-app-id && inputs.github-app-private-key
uses: actions/create-github-app-token@v1.11.0
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/checkout@v4.2.2
with:
repository: DiamondLightSource/graph-federation
token: ${{ steps.app-token.outputs.token || github.token }}
- name: Download Subgraph schema
uses: actions/download-artifact@v4.1.8
with:
name: ${{ inputs.subgraph-schema-artifact }}
path: /tmp/schema/
- name: Install yq
shell: bash
run: |
if ! command -v yq >/dev/null 2>&1; then
YQ_VERSION=v4.44.3
curl -sSL -o /usr/local/bin/yq \
"https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64"
chmod +x /usr/local/bin/yq
fi
yq --version
- name: Add Subgraph Schema
shell: bash
run: |
mkdir -p schema
mv /tmp/schema/${{ inputs.subgraph-schema-filename }} schema/${{ inputs.name }}.graphql
- name: Update supergraph-config.yaml
shell: bash
env:
NAME: ${{ inputs.name }}
ROUTING_URL: ${{ inputs.routing-url }}
SUB_URL: ${{ inputs.subscription-url }}
SUB_PROTO: ${{ inputs.subscription-protocol }}
run: |
yq -i '.subgraphs = (.subgraphs // [])' supergraph-config.yaml
yq -i '
.subgraphs = (.subgraphs | map(select(.name != "'"$NAME"'")))
' supergraph-config.yaml
yq -i '
.subgraphs += [{
"name": "'"$NAME"'",
"routing_url": "'"$ROUTING_URL"'",
"schema": { "file": "schema/'"$NAME"'.graphql" }
}]
' supergraph-config.yaml
if [ -n "$SUB_URL" ]; then
yq -i '
.subgraphs[-1].subscription = {
"url": "'"$SUB_URL"'",
"protocol": "'"$SUB_PROTO"'"
}
' supergraph-config.yaml
fi
echo "Updated Cosmo config:"
yq e -P '.' supergraph-config.yaml
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "24"
- name: Install Cosmo CLI
shell: bash
run: npm install -g wgc@latest
- name: Compose Execution Config
id: compose_exec
shell: bash
run: |
mkdir -p charts/supergraph/files
wgc router compose \
--input supergraph-config.yaml \
--out "charts/supergraph/files/${{ inputs.execution-config-filename }}"
- name: Upload Execution Config Artifact
id: upload_exec
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.execution-config-artifact }}
path: charts/supergraph/files/${{ inputs.execution-config-filename }}
overwrite: true
- name: Install Supergraph Schema Composition deps
shell: bash
run: npm install @wundergraph/composition graphql js-yaml
- name: Generate Supergraph Schema
shell: bash
run: |
node .ci/generate-supergraph.mjs
mkdir -p charts/supergraph/files
test -s supergraph.graphql
mv supergraph.graphql "charts/supergraph/files/${{ inputs.supergraph-filename }}"
- name: Upload Supergraph Schema Artifact
id: upload_sdl
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.supergraph-artifact }}
path: charts/supergraph/files/${{ inputs.supergraph-filename }}
overwrite: true
- name: Configure Git with App
if: steps.app-token.outcome == 'success'
shell: bash
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
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"
- name: Create commit
id: commit
if: steps.app-token.outcome == 'success'
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; then
git commit -m "feat: 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' && steps.app-token.outcome == 'success'
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 "feat: Update ${{ inputs.name }} subgraph to ${{ github.ref_name }}" \
--body "$(echo -e '- Source repository: [${{ github.repository }}](https://github.com/${{ github.repository }})\n- Author: @${{ github.actor }}')" \
--head ${{ inputs.name }}-${{ github.ref_name }} \
--base main