-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathshopify-dev-preview-automation.yml
More file actions
86 lines (78 loc) · 3.12 KB
/
Copy pathshopify-dev-preview-automation.yml
File metadata and controls
86 lines (78 loc) · 3.12 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
# This workflow dispatches a docs sync event to Shop/world's templated-apis-docs-sync
# workflow when Liquid JSON schema files change in a PR.
#
# The templated-apis-docs-sync workflow will then run the Liquid JSON schemas sync
# pipeline to create a draft pull request in shopify-dev which contains the changes
# to preview the schema changes in shopify-dev's preview environment.
#
name: 'Liquid JSON schemas preview dispatch'
on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review, closed]
paths:
- 'schemas/theme/**'
concurrency:
group: liquid-json-schemas-preview-dispatch-${{ github.head_ref }}
cancel-in-progress: true
jobs:
dispatch-liquid-json-schemas-sync:
name: Dispatch Liquid JSON schemas sync
runs-on: shopify-ubuntu-latest
timeout-minutes: 10
steps:
- name: Create GitHub App Token (Shop org - world)
id: app-token
uses: actions/create-github-app-token@bcd2ba49218906704ab6c1aa796996da409d3eb1 # v3.2.0
with:
app-id: ${{ secrets.SHOPIFY_DEV_DOCS_SYNC_APP_ID }}
private-key: ${{ secrets.SHOPIFY_DEV_DOCS_SYNC_APP_PRIVATE_KEY }}
owner: Shop
repositories: |
world
- name: Dispatch to templated-apis-docs-sync
env:
GH_TOKEN: ${{ steps.app-token.outputs.token }}
SOURCE_BRANCH: ${{ github.event.pull_request.base.ref }}
SOURCE_REF: ${{ github.event.pull_request.head.ref }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
if [ "${{ github.event.action }}" = "closed" ]; then
ACTION="close"
CHANGED_FILES='[]'
else
ACTION="sync"
CHANGED_FILES='["schemas/theme/"]'
fi
PAYLOAD=$(jq -n \
--arg action "$ACTION" \
--arg source_repo "Shopify/theme-liquid-docs" \
--arg source_branch "$SOURCE_BRANCH" \
--arg source_ref "$SOURCE_REF" \
--argjson source_pr_number "$PR_NUMBER" \
--argjson changed_files "$CHANGED_FILES" \
'{
event_type: "templated-api-docs-sync",
client_payload: {
action: $action,
source_repo: $source_repo,
source_branch: $source_branch,
source_ref: $source_ref,
source_pr_number: $source_pr_number,
changed_files: $changed_files
}
}')
echo "Dispatching $ACTION to shop/world templated-apis-docs-sync..."
echo "$PAYLOAD" | jq .
HTTP_STATUS=$(curl -s -o response.txt -w "%{http_code}" \
-X POST \
-H "Authorization: Bearer $GH_TOKEN" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/shop/world/dispatches \
-d "$PAYLOAD")
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
echo "Successfully dispatched $ACTION event (HTTP $HTTP_STATUS)"
else
echo "Failed to dispatch $ACTION event (HTTP $HTTP_STATUS)"
cat response.txt
exit 1
fi