This repository has been archived by the owner on Jan 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
137 lines (131 loc) · 4.9 KB
/
supergraph-build-webhook.yml
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
name: Supergraph Build Webhook
on:
schedule:
- cron: '*/30 * * * *'
workflow_dispatch: {}
repository_dispatch:
types: [studio-build-webhook]
jobs:
supergraph-build-webhook:
runs-on: ubuntu-latest
strategy:
matrix:
include:
- graph-ref: "supergraph-router@dev"
short-name: dev
target-file: "router/dev/supergraph.graphql"
pr-branch: "bump-supergraph-dev"
- graph-ref: "supergraph-router@stage"
short-name: stage
target-file: "router/stage/supergraph.graphql"
pr-branch: "bump-supergraph-stage"
- graph-ref: "supergraph-router@prod"
short-name: prod
target-file: "router/prod/supergraph.graphql"
pr-branch: "bump-supergraph-prod"
name: ${{ matrix.graph-ref }}
concurrency:
group: ${{ matrix.graph-ref }}
cancel-in-progress: true
env:
APOLLO_KEY: ${{ secrets.APOLLO_KEY }}
GRAPH_REF: ${{ matrix.graph-ref }}
SUPERGRAPH: ${{ matrix.target-file }}
steps:
-
name: Checkout
uses: actions/checkout@v2
-
name: install rover
run: |
curl -sSL https://rover.apollo.dev/nix/latest | sh
echo "PATH=$PATH:$HOME/.rover/bin" >> ${GITHUB_ENV}
-
id: pre-check
name: pre-check
run: |
SHA=$(shasum ${{ matrix.target-file }} | awk '{print $1}')
echo "::set-output name=sha::$SHA"
echo "::set-output name=sha-short::$(git rev-parse --short $SHA)"
-
name: supergraph fetch
run: |
rover supergraph fetch $GRAPH_REF > ${{ matrix.target-file }}
echo "$(git diff --name-only)"
-
id: check
name: check
run: |
echo "::set-output name=result::$(git diff --name-only | grep -E $SUPERGRAPH)"
SHA=$(shasum $SUPERGRAPH | awk '{print $1}')
echo "::set-output name=sha::$SHA"
echo "::set-output name=sha-short::$(git rev-parse --short $SHA)"
-
name: validate
if: steps.check.outputs.result == matrix.target-file
env:
RESULT: ${{ steps.check.outputs.result }}
SHA: ${{ steps.check.outputs.sha }}
SHA_SHORT: ${{ steps.check.outputs.sha-short }}
run: |
echo "RESULT: $RESULT"
echo "SHA: $SHA"
echo "SHA_SHORT: $SHA_SHORT"
DIFF=$(git diff $SUPERGRAPH)
echo "DIFF<<EOF" >> $GITHUB_ENV
echo "$DIFF" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
echo "-----------------------"
echo "$SUPERGRAPH"
echo "-----------------------"
echo "$DIFF"
-
name: create pull request
id: cpr
if: steps.check.outputs.result == matrix.target-file
uses: peter-evans/create-pull-request@v3
with:
token: ${{ secrets.PAT }}
committer: Supergraph Demo Bot <[email protected]>
author: Supergraph Demo Bot <[email protected]>
commit-message: Bump ${{ matrix.short-name }} supergraph schema from ${{ steps.pre-check.outputs.sha-short }} to ${{ steps.check.outputs.sha-short }}
title: Bump ${{ env.GRAPH_REF }} from ${{ steps.pre-check.outputs.sha-short }} to ${{ steps.check.outputs.sha-short }}
body: |
Bump ${{ env.GRAPH_REF }} from ${{ steps.pre-check.outputs.sha-short }} to ${{ steps.check.outputs.sha-short }}
* Old: SHA1 ${{ steps.pre-check.outputs.sha }} ( ${{ steps.pre-check.outputs.sha-short }} )
* New: SHA1 ${{ steps.check.outputs.sha }} ( ${{ steps.check.outputs.sha-short }} )
<details>
<summary>${{ env.GRAPH_REF }} changes</summary>
```diff
${{ env.DIFF }}
```
</details>
branch: ${{ matrix.pr-branch }}
base: main
delete-branch: true
-
name: enable pull request automerge
if: |
steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated'
uses: peter-evans/enable-pull-request-automerge@v1
with:
token: ${{ secrets.PAT }}
pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
merge-method: rebase
-
name: Check output
if: |
steps.cpr.outputs.pull-request-operation == 'created' ||
steps.cpr.outputs.pull-request-operation == 'updated'
run: |
echo PR CREATED or MODIFIED
echo "Pull Request Number - ${{ steps.cpr.outputs.pull-request-number }}"
echo "Pull Request URL - ${{ steps.cpr.outputs.pull-request-url }}"
-
name: No changes detected
if: |
steps.cpr.outputs.pull-request-operation != 'created' &&
steps.cpr.outputs.pull-request-operation != 'updated'
run: |
echo "No changes detected."