Skip to content

Commit 761b599

Browse files
author
Keith Halsall
committed
Add updated github actions scripts
1 parent 75e2dbc commit 761b599

File tree

7 files changed

+304
-53
lines changed

7 files changed

+304
-53
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Run Subgraph Check and Publish
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.graphql'
7+
workflow_dispatch:
8+
workflow_call:
9+
10+
env:
11+
GEN: "nov15"
12+
APOLLO_KEY: ${{ vars.TOKEN }}
13+
14+
jobs:
15+
checks:
16+
uses: ./.github/workflows/subgraph-check.yml
17+
secrets: inherit
18+
publish:
19+
needs: checks
20+
uses: ./.github/workflows/publish-subgraph.yml
21+
secrets: inherit
Lines changed: 81 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,89 @@
1-
name: Create Studio Account
1+
name: Setup Studio Account
22

33
on:
4-
create:
5-
push:
4+
workflow_run:
5+
workflows: ["Initial Setup"]
6+
types:
7+
- completed
8+
9+
env:
10+
GEN: "nov15"
11+
APOLLO_KEY: ${{ secrets.APOLLO_USER_KEY }}
612

713
jobs:
8-
create:
14+
publish:
15+
uses: ./.github/workflows/publish-subgraph.yml
16+
secrets: inherit
17+
18+
pqs:
919
runs-on: ubuntu-latest
1020
steps:
11-
- name: Create Graph in Apollo Studio
12-
run: |
13-
echo "GITHUB_ACTOR: ${GITHUB_ACTOR}"
14-
curl --request POST 'https://graphql.api.apollographql.com' \
15-
--header 'content-type: application/json' \
16-
--header 'X-API-Key: user:fp.d88ba77d-487c-4b97-9780-f1e4c5352a22:_60kU_wi1yLH1zt60UhxGg' \
17-
--data '{"query":"mutation CreateGraph($graphType: GraphType!, $hiddenFromUninvitedNonAdmin: Boolean!, $createGraphId: ID!, $title: String!, $accountId: ID!) {\n account(id: $accountId) {\n createGraph(graphType: $graphType, hiddenFromUninvitedNonAdmin: $hiddenFromUninvitedNonAdmin, id: $createGraphId, title: $title) {\n ... on Service {\n accountId\n }\n }\n }\n }\n \n \n","variables":{"graphType":"SELF_HOSTED_SUPERGRAPH","hiddenFromUninvitedNonAdmin":false,"createGraphId":"${GITUB_ACTOR}","title":"${GITHUB_ACTOR}","accountId":"summit-2023-enterprise-workshop"},"operationName":"CreateGraph"}'
18-
jobs:
19-
publish:
20-
name: Rover Subgraph Publish
21-
run-on: ubuntu-latest
21+
- name: Create PQ List
22+
run: |
23+
curl --request POST \
24+
--header 'content-type: application/json' \
25+
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
26+
--url 'https://graphql.api.apollographql.com/api/graphql' \
27+
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $description: String, $linkedVariants: [String!]) {\n graph(id: $graphId) {\n createPersistedQueryList(name: $name, description: $description, linkedVariants: $linkedVariants) {\n ... on CreatePersistedQueryListResult {\n persistedQueryList {\n id\n createdAt\n }\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{ env.GEN }}","name":"pq_list","description":"Our PQ List","linkedVariants":["current"]}}' -o pq.json
28+
cat pq.json
29+
30+
- name: Set Env
31+
run: echo "PQ_ID=$(cat pq.json | jq .data.graph.createPersistedQueryList.persistedQueryList.id)" >> $GITHUB_ENV
32+
33+
- name: Install Rover
34+
run: |
35+
curl -sSL https://rover.apollo.dev/nix/v0.19.0 | sh
36+
echo "$HOME/.rover/bin" >> $GITHUB_PATH
2237
38+
- name: Checkout
39+
uses: actions/checkout@v3
40+
41+
- name: Publish PQ List
42+
run: |
43+
rover persisted-queries publish --graph-id ${{vars.ACTOR}}${{env.GEN}} --list-id ${{env.PQ_ID}} \
44+
--manifest ./final/workshop-pq-manifest.json
45+
46+
deploy:
47+
needs: publish
48+
uses: ./.github/workflows/deploy-router.yml
49+
secrets: inherit
50+
51+
install-url:
52+
needs: deploy
53+
runs-on: ubuntu-latest
54+
steps:
55+
- id: "auth"
56+
uses: "google-github-actions/auth@v0"
57+
with:
58+
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
59+
- name: Get URL
60+
run: |
61+
gcloud run services describe ${{vars.ACTOR}}-router --region us-central1 --format 'value(status.url)' > url.json
62+
echo "URL=$(cat url.json)" >> $GITHUB_ENV
63+
- name: Set URL
64+
run: |
65+
curl --request POST \
66+
--header 'content-type: application/json' \
67+
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
68+
--url 'https://graphql.api.apollographql.com/api/graphql' \
69+
--data '{"query":"mutation UpdateURL($name: String!, $graphId: ID!, $url: String) {\n graph(id: $graphId) {\n variant(name: $name) {\n updateURL(url: $url) {\n createdAt\n }\n }\n }\n}","variables":{"name":"current","graphId":"${{vars.ACTOR}}${{ env.GEN }}","url":"${{ env.URL }}"}}'
70+
71+
- name: Set Subscription URL
72+
run: |
73+
curl --request POST \
74+
--header 'content-type: application/json' \
75+
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
76+
--url 'https://graphql.api.apollographql.com/api/graphql' \
77+
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $subscriptionUrl: String) {\n graph(id: $graphId) {\n variant(name: $name) {\n updateSubscriptionURL(subscriptionUrl: $subscriptionUrl) {\n createdAt\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{ env.GEN }}","name":"current","subscriptionUrl":"${{ env.URL }}"}}'
78+
79+
preflightScript:
80+
needs: publish
81+
runs-on: ubuntu-latest
2382
steps:
24-
- name: Checkout
25-
uses: actions/checkout@v3
26-
27-
- name: Install Rover
28-
run: |
29-
curl -sSL https://rover.apollo.dev/nix/v0.8.1 | sh
30-
echo "$HOME/.rover/bin" >> $GITHUB_PATH
31-
32-
- name: Rover Subgraph Publish
33-
run: |
34-
rover subgraph publish ${{secrets.APOLLO_GRAPH_REF }} \
35-
--name products \
36-
--routing-url https://https://subgraph-products-j3nprurqka-ue.a.run.app \
37-
--schema ./final/nosql-products/schema.graphql
83+
- name: Create PreFlight Script
84+
run: |
85+
curl --request POST \
86+
--header 'content-type: application/json' \
87+
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
88+
--url 'https://graphql.api.apollographql.com/api/graphql' \
89+
--data '{"query":"mutation Mutation($graphId: ID!, $name: String!, $preflightScript: String) {\n graph(id: $graphId) {\n variant(name: $name) {\n updatePreflightScript(preflightScript: $preflightScript) {\n createdAt\n }\n }\n }\n}","variables":{"graphId":"${{vars.ACTOR}}${{ env.GEN }}","name":"current","preflightScript":"const API_KEY=\"AIzaSyBGEWuarfRs4vVIzbdPj7EU_h3tMAVO_e4\";console.log(\"fetching new token.....\");const getToken=async e=>{let o=await explorer.fetch(\"https:\/\/identitytoolkit.googleapis.com\/v1\/accounts:signInWithPassword?key=AIzaSyBGEWuarfRs4vVIzbdPj7EU_h3tMAVO_e4\",{method:\"POST\",header:{\"Content-Type\":\"application\/json\"},body:JSON.stringify({email:e,password:\"apolloworkshop\",returnSecureToken:!0})});return o.json()},authorizedCredentials=await getToken(\"[email protected]\"),{idToken:authorizedToken}=authorizedCredentials;explorer.environment.set(\"authorizedToken\",authorizedToken),console.log(\"successfully set authorized token\");const unauthorizedCredentials=await getToken(\"[email protected]\"),{idToken:unauthorizedToken}=unauthorizedCredentials;explorer.environment.set(\"unauthorizedToken\",unauthorizedToken),console.log(\"successfully set token unauthorized token\");"}}'

.github/workflows/deploy-router.yml

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
name: Deploy Router to Cloud Run
22

33
on:
4-
push:
5-
branches:
6-
- summit-workshop
4+
workflow_dispatch:
5+
workflow_call:
6+
7+
env:
8+
GEN: "nov15"
79

810
jobs:
911
deploy:
@@ -12,34 +14,26 @@ jobs:
1214
steps:
1315
- name: Checkout code
1416
uses: actions/checkout@v2
17+
1518
- id: "auth"
1619
uses: "google-github-actions/auth@v0"
1720
with:
1821
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
1922

20-
- name: Set up Google Cloud SDK
21-
uses: google-github-actions/setup-gcloud@v0
22-
23-
- name: Configure Docker to use gcloud as a credential helper
24-
run: |
25-
gcloud auth configure-docker
23+
#- name: Set up Google Cloud SDK
24+
# uses: google-github-actions/setup-gcloud@v0
2625

27-
- name: Build Apollo Router Docker image
28-
run: |
29-
docker build -t gcr.io/summit-enterprise-workshop/apollo-router:latest .
30-
docker images
31-
working-directory: ./router
26+
- name: Create Secret for Cloud Run
27+
run: gcloud secrets create ${{vars.ACTOR}}
28+
continue-on-error: true
3229

33-
- name: Push Docker image to Google Container Registry
34-
run: |
35-
docker push gcr.io/summit-enterprise-workshop/apollo-router:latest
36-
working-directory: ./router
30+
- name: Add Secret data
31+
run: gcloud secrets versions add --data-file=./router/router.yaml ${{vars.ACTOR}}
3732

38-
- name: Deploy Apollo Router to Cloud Run
33+
- name: Depoy Apollo Router to Cloud Run
3934
run: |
40-
gcloud run deploy apollo-router \
41-
--image gcr.io/summit-enterprise-workshop/apollo-router:latest \
42-
--platform managed \
43-
--region us-central1 \
44-
--update-env-vars APOLLO_KEY=${{ secrets.APOLLO_KEY }},APOLLO_GRAPH_REF=${{ secrets.APOLLO_GRAPH_REF }} \
35+
gcloud run deploy ${{vars.ACTOR}}-router --image gcr.io/summit-enterprise-workshop/jesse-apollo-router:latest \
36+
--set-secrets=/dist/config/router.yaml=${{vars.ACTOR}}:latest \
37+
--set-env-vars "APOLLO_ROUTER_HOT_RELOAD=true,APOLLO_KEY=${{ vars.TOKEN }},APOLLO_GRAPH_REF=${{vars.ACTOR}}${{env.GEN}}@current" --platform managed --region us-central1 \
4538
--allow-unauthenticated
39+
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
name: Publish subgraphs to Apollo Studio
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
7+
env:
8+
GEN: "nov15"
9+
APOLLO_KEY: ${{ vars.TOKEN }}
10+
11+
jobs:
12+
publish:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v3
18+
19+
- name: Install Rover
20+
run: |
21+
curl -sSL https://rover.apollo.dev/nix/v0.19.0 | sh
22+
echo "$HOME/.rover/bin" >> $GITHUB_PATH
23+
24+
- name: Rover Subgraph Publish Products
25+
run: |
26+
rover subgraph publish ${{vars.ACTOR}}${{ env.GEN }}@current \
27+
--name products \
28+
--convert \
29+
--routing-url https://subgraph-products-j3nprurqka-ue.a.run.app \
30+
--schema ./products-schema.graphql
31+
32+
- name: Rover Subgraph Publish Orders
33+
run: |
34+
rover subgraph publish ${{vars.ACTOR}}${{ env.GEN }}@current \
35+
--name orders \
36+
--routing-url https://subgraph-orders-j3nprurqka-ue.a.run.app \
37+
--schema ./orders-schema.graphql
38+
39+
- name: Rover Subgraph Publish Customers
40+
run: |
41+
rover subgraph publish ${{vars.ACTOR}}${{ env.GEN }}@current \
42+
--name customers \
43+
--routing-url https://subgraph-customers-j3nprurqka-ue.a.run.app \
44+
--schema ./final/customers-schema.graphql

.github/workflows/setup.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
2+
name: Initial Setup
3+
4+
on:
5+
push:
6+
paths:
7+
- '**.yml'
8+
9+
env:
10+
GEN: "nov15"
11+
12+
jobs:
13+
create:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- id: string
17+
uses: ASzc/change-string-case-action@v5
18+
with:
19+
string: ${{github.actor}}
20+
- id: step2
21+
run: echo "ACTOR=${{ steps.string.outputs.lowercase }}" >> $GITHUB_ENV
22+
- name : lowercase github actor
23+
run: |
24+
curl -L \
25+
-X POST \
26+
-H "Accept: application/vnd.github+json" \
27+
-H "Authorization: Bearer ${{ secrets.GH_KEY }}" \
28+
-H "X-GitHub-Api-Version: 2022-11-28" \
29+
https://api.github.com/repos/${{github.repository}}/actions/variables \
30+
-d '{"name":"actor","value":"${{ steps.string.outputs.lowercase }}" }'
31+
32+
- name: Create Graph in Apollo Studio
33+
run: |
34+
echo "GITHUB_ACTOR: $GITHUB_ACTOR"
35+
curl --request POST 'https://graphql.api.apollographql.com' \
36+
--header 'content-type: application/json' \
37+
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
38+
--data '{"query":"mutation Mutation($accountId: ID!, $graphType: GraphType!, $hiddenFromUninvitedNonAdmin: Boolean!, $createGraphId: ID!, $title: String!, $variantCreationConfig: VariantCreationConfig) {\n account(id: $accountId) {\n createGraph(graphType: $graphType, hiddenFromUninvitedNonAdmin: $hiddenFromUninvitedNonAdmin, id: $createGraphId, title: $title, variantCreationConfig: $variantCreationConfig) {\n __typename\n ... on Service {\n __typename\n id\n }\n ... on GraphCreationError {\n __typename\n message\n }\n }\n }\n}","variables":{"accountId":"${{ secrets.APOLLO_ACCOUNT }}","graphType":"SELF_HOSTED_SUPERGRAPH","hiddenFromUninvitedNonAdmin":false,"createGraphId":"${{env.ACTOR}}${{ env.GEN }}","title":"${{env.ACTOR}} - ${{ env.GEN }}","variantCreationConfig":{"variantName":"current","buildConfigInput":{"apiDirectivePassThrough":[],"buildPipelineTrack":null,"composition":{"subgraphs":[]}}}}}'
39+
40+
keys:
41+
needs: create
42+
runs-on: ubuntu-latest
43+
steps:
44+
- name: Sleep
45+
run: sleep 10s
46+
shell: bash
47+
- id: string
48+
uses: ASzc/change-string-case-action@v5
49+
with:
50+
string: ${{github.actor}}
51+
- id: step2
52+
run: echo "ACTOR=${{ steps.string.outputs.lowercase }}" >> $GITHUB_ENV
53+
54+
- name: Create Apollo Key
55+
run: |
56+
curl --request POST 'https://graphql.api.apollographql.com' \
57+
--header 'content-type: application/json' \
58+
--header 'X-API-Key: ${{ secrets.APOLLO_USER_KEY }}' \
59+
--data '{"query":"mutation Mutation($graphId: ID!, $keyName: String, $role: UserPermission!) {\n graph(id: $graphId) {\n newKey(keyName: $keyName, role: $role) {\n token\n }\n }\n}","variables":{"graphId":"${{env.ACTOR}}${{ env.GEN }}","keyName":"my-first-key","role":"CONTRIBUTOR"}}' -o token.json
60+
cat token.json
61+
62+
- name: Set Env
63+
run: echo "TOKEN=$(cat token.json | jq .data.graph.newKey.token)" >> $GITHUB_ENV
64+
65+
- name: Retrieve Apollo Key
66+
run: |
67+
echo "Add code to extract token and save as a github secret"
68+
curl -L \
69+
-X POST \
70+
-H "Accept: application/vnd.github+json" \
71+
-H "Authorization: Bearer ${{ secrets.GH_KEY }}" \
72+
-H "X-GitHub-Api-Version: 2022-11-28" \
73+
https://api.github.com/repos/${{github.repository}}/actions/variables \
74+
-d '{"name":"token","value":${{ env.TOKEN }} }'

.github/workflows/subgraph-check.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Perform subgraph check via Apollo Studio
2+
3+
on:
4+
workflow_dispatch:
5+
workflow_call:
6+
7+
env:
8+
GEN: "nov15"
9+
APOLLO_KEY: ${{ vars.TOKEN }}
10+
11+
jobs:
12+
checks:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v3
17+
18+
- name: Install Rover
19+
run: |
20+
curl -sSL https://rover.apollo.dev/nix/v0.19.0 | sh
21+
echo "$HOME/.rover/bin" >> $GITHUB_PATH
22+
23+
- name: Rover Subgraph Check Products
24+
run: |
25+
rover subgraph check ${{vars.ACTOR}}${{ env.GEN }}@current \
26+
--name products \
27+
--schema ./products-schema.graphql
28+
29+
- name: Rover Subgraph Check Orders
30+
run: |
31+
rover subgraph check ${{vars.ACTOR}}${{ env.GEN }}@current \
32+
--name orders \
33+
--schema ./orders-schema.graphql
34+
35+
- name: Rover Subgraph Check Customers
36+
run: |
37+
rover subgraph check ${{vars.ACTOR}}${{ env.GEN }}@current \
38+
--name customers \
39+
--schema ./final/customers-schema.graphql

.github/workflows/update-router.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: Update Router on Cloud Run
2+
3+
on:
4+
push:
5+
paths:
6+
- '**.yaml'
7+
workflow_dispatch:
8+
workflow_call:
9+
10+
env:
11+
GEN: "nov15"
12+
13+
jobs:
14+
deploy:
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
21+
- id: "auth"
22+
uses: "google-github-actions/auth@v0"
23+
with:
24+
credentials_json: ${{ secrets.GCP_CREDENTIALS }}
25+
26+
- name: Add Secret data
27+
run: gcloud secrets versions add --data-file=./router/router.yaml ${{vars.ACTOR}}

0 commit comments

Comments
 (0)