Skip to content

Commit 8daeebb

Browse files
committed
chore: test workflow!
1 parent 6068188 commit 8daeebb

File tree

4 files changed

+141
-6
lines changed

4 files changed

+141
-6
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# This workflow dispatches a docs sync event to shopify-dev when generated docs files change.
2+
# It monitors changes to generated docs files in PRs.
3+
#
4+
# The shopify-dev repository will then sync these docs files for preview.
5+
6+
name: Shopify Dev Docs Sync
7+
8+
on:
9+
pull_request:
10+
types: [opened, synchronize, reopened, ready_for_review, closed]
11+
paths:
12+
- 'docs-shopify.dev/generated/generated_docs_data.json'
13+
- 'docs-shopify.dev/generated/generated_static_pages.json'
14+
- 'docs-shopify.dev/generated/generated_category_pages.json'
15+
16+
concurrency:
17+
group: shopify-dev-docs-sync-${{ github.head_ref }}
18+
cancel-in-progress: true
19+
20+
jobs:
21+
dispatch-docs-sync:
22+
name: Dispatch docs sync to shopify-dev
23+
runs-on: ubuntu-latest
24+
timeout-minutes: 10
25+
if: github.repository_owner == 'Shopify'
26+
steps:
27+
- name: Checkout repository
28+
if: github.event.action != 'closed'
29+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
30+
with:
31+
fetch-depth: 0
32+
33+
# Generate GitHub App token
34+
- name: Create GitHub App Token
35+
id: app-token
36+
uses: actions/create-github-app-token@af35edadc00be37caa72ed9f3e6d5f7801bfdf09 # v1.11.7
37+
with:
38+
app-id: ${{ secrets.SHOPIFY_DEV_DOCS_SYNC_APP_ID }}
39+
private-key: ${{ secrets.SHOPIFY_DEV_DOCS_SYNC_APP_PRIVATE_KEY }}
40+
owner: Shopify
41+
repositories: |
42+
shopify-dev
43+
44+
- name: Get changed files
45+
id: changed-files
46+
if: github.event.action != 'closed'
47+
env:
48+
BASE_SHA: ${{ github.event.pull_request.base.sha }}
49+
HEAD_SHA: ${{ github.event.pull_request.head.sha }}
50+
run: |
51+
# Define the files we're monitoring
52+
MONITORED_FILES=(
53+
"docs-shopify.dev/generated/generated_docs_data.json"
54+
"docs-shopify.dev/generated/generated_static_pages.json"
55+
"docs-shopify.dev/generated/generated_category_pages.json"
56+
)
57+
58+
# Get the list of changed files in this PR using explicit SHAs
59+
echo "Comparing $BASE_SHA...$HEAD_SHA"
60+
CHANGED_FILES=$(git diff --name-only "$BASE_SHA"..."$HEAD_SHA")
61+
62+
# Filter to only include our monitored files
63+
MATCHING_FILES=()
64+
for file in "${MONITORED_FILES[@]}"; do
65+
if echo "$CHANGED_FILES" | grep -Fxq "$file"; then
66+
MATCHING_FILES+=("$file")
67+
fi
68+
done
69+
70+
# Convert to JSON array
71+
if [ ${#MATCHING_FILES[@]} -eq 0 ]; then
72+
echo "No monitored files changed"
73+
echo "has_changes=false" >> $GITHUB_OUTPUT
74+
else
75+
JSON_ARRAY=$(printf '%s\n' "${MATCHING_FILES[@]}" | jq -R . | jq -s -c .)
76+
echo "Changed files: $JSON_ARRAY"
77+
echo "has_changes=true" >> $GITHUB_OUTPUT
78+
echo "files=$JSON_ARRAY" >> $GITHUB_OUTPUT
79+
fi
80+
81+
- name: Dispatch to shopify-dev
82+
if: github.event.action == 'closed' || steps.changed-files.outputs.has_changes == 'true'
83+
env:
84+
GH_TOKEN: ${{ steps.app-token.outputs.token }}
85+
SOURCE_BRANCH: ${{ github.event.pull_request.base.ref }}
86+
SOURCE_REF: ${{ github.event.pull_request.head.ref }}
87+
PR_NUMBER: ${{ github.event.pull_request.number }}
88+
CHANGED_FILES: ${{ steps.changed-files.outputs.files }}
89+
run: |
90+
# Determine action based on PR event
91+
if [ "${{ github.event.action }}" = "closed" ]; then
92+
ACTION="close"
93+
CHANGED_FILES='[]'
94+
else
95+
ACTION="sync"
96+
fi
97+
98+
# Build the payload
99+
PAYLOAD=$(jq -n \
100+
--arg action "$ACTION" \
101+
--arg source_repo "Shopify/cli" \
102+
--arg source_branch "$SOURCE_BRANCH" \
103+
--arg source_ref "$SOURCE_REF" \
104+
--argjson source_pr_number "$PR_NUMBER" \
105+
--argjson changed_files "$CHANGED_FILES" \
106+
'{
107+
event_type: "templated-api-docs-sync",
108+
client_payload: {
109+
action: $action,
110+
source_repo: $source_repo,
111+
source_branch: $source_branch,
112+
source_ref: $source_ref,
113+
source_pr_number: $source_pr_number,
114+
changed_files: $changed_files
115+
}
116+
}')
117+
118+
echo "Dispatching to shopify-dev with payload:"
119+
echo "$PAYLOAD" | jq .
120+
121+
# Send the dispatch request
122+
HTTP_STATUS=$(curl -s -o response.txt -w "%{http_code}" \
123+
-X POST \
124+
-H "Authorization: Bearer $GH_TOKEN" \
125+
-H "Accept: application/vnd.github+json" \
126+
https://api.github.com/repos/Shopify/shopify-dev/dispatches \
127+
-d "$PAYLOAD")
128+
129+
if [ "$HTTP_STATUS" -ge 200 ] && [ "$HTTP_STATUS" -lt 300 ]; then
130+
echo "Successfully dispatched docs $ACTION event to shopify-dev (HTTP $HTTP_STATUS)"
131+
else
132+
echo "Failed to dispatch docs $ACTION event (HTTP $HTTP_STATUS)"
133+
cat response.txt
134+
exit 1
135+
fi

docs-shopify.dev/generated/generated_category_pages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"category": "app",
4-
"title": "Shopify CLI App commands",
4+
"title": "OTHER SIIIIIIIIIDE Shopify CLI App commands",
55
"sections": []
66
},
77
{
@@ -19,4 +19,4 @@
1919
"title": "Shopify CLI Theme commands",
2020
"sections": []
2121
}
22-
]
22+
]

docs-shopify.dev/generated/generated_docs_data.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"name": "app build",
4-
"description": "This command executes the build script specified in the element's TOML file. You can specify a custom script in the file. To learn about configuration files in Shopify apps, refer to [App configuration](/docs/apps/tools/cli/configuration).\n\n If you're building a [theme app extension](/docs/apps/online-store/theme-app-extensions), then running the `build` command runs [Theme Check](/docs/themes/tools/theme-check) against your extension to ensure that it's valid.",
4+
"description": "Hello command executes the build script specified in the element's TOML file. You can specify a custom script in the file. To learn about configuration files in Shopify apps, refer to [App configuration](/docs/apps/tools/cli/configuration).\n\n If you're building a [theme app extension](/docs/apps/online-store/theme-app-extensions), then running the `build` command runs [Theme Check](/docs/themes/tools/theme-check) against your extension to ensure that it's valid.",
55
"overviewPreviewDescription": "Build the app, including extensions.",
66
"type": "command",
77
"isVisualComponent": false,
@@ -7857,4 +7857,4 @@
78577857
"category": "general commands",
78587858
"related": []
78597859
}
7860-
]
7860+
]

docs-shopify.dev/generated/generated_static_pages.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[
22
{
33
"title": "Shopify CLI",
4-
"description": "Shopify CLI is a command-line interface tool that helps you generate and work with Shopify apps, themes and custom storefronts. You can also use it to automate many common development tasks.",
4+
"description": "From The Shopify CLI is a command-line interface tool that helps you generate and work with Shopify apps, themes and custom storefronts. You can also use it to automate many common development tasks.",
55
"id": "Shopify CLI",
66
"image": "/assets/landing-pages/templated-apis/web-pixels-api/landing-page.png",
77
"darkImage": "/assets/landing-pages/templated-apis/web-pixels-api/landing-page.png",
@@ -118,4 +118,4 @@
118118
}
119119
]
120120
}
121-
]
121+
]

0 commit comments

Comments
 (0)