-
Notifications
You must be signed in to change notification settings - Fork 6
147 lines (126 loc) · 5.16 KB
/
Copy pathsync-mintlify.yml
File metadata and controls
147 lines (126 loc) · 5.16 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
name: Sync Release to Mintlify
on:
push:
branches:
- main
paths:
- content/**/*.md
workflow_dispatch:
inputs:
content_paths:
description: "Optional comma or newline separated content/**/*.md paths to sync"
required: false
before_sha:
description: "Optional start SHA for manual git diff selection"
required: false
after_sha:
description: "Optional end SHA for manual git diff selection"
required: false
concurrency:
group: mintlify-changelog-sync
cancel-in-progress: false
jobs:
sync:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout changelog repo
uses: actions/checkout@v6
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Checkout box-mintlify
uses: actions/checkout@v6
with:
repository: box/box-mintlify
token: ${{ secrets.MINTLIFY_TOKEN }}
path: box-mintlify
- name: Convert and generate Mintlify entries
id: convert
env:
AFTER_SHA: ${{ github.event.inputs.after_sha || github.sha }}
BEFORE_SHA: ${{ github.event.inputs.before_sha || github.event.before }}
CHANGELOG_REPO_PATH: ${{ github.workspace }}
CONTENT_PATHS: ${{ github.event.inputs.content_paths }}
MINTLIFY_REPO_PATH: ${{ github.workspace }}/box-mintlify
run: node code/src/MintlifySync/index.js
- name: Create PR in box-mintlify
id: create_pr
env:
GH_TOKEN: ${{ secrets.MINTLIFY_TOKEN }}
working-directory: box-mintlify
run: |
OUTPUT_JSON="/tmp/mintlify-sync-output.json"
if [ ! -f "$OUTPUT_JSON" ]; then
echo "Expected output file not found: $OUTPUT_JSON"
exit 1
fi
ENTRY_COUNT="$(jq '.entries | length' "$OUTPUT_JSON")"
echo "entry_count=${ENTRY_COUNT}" >> "$GITHUB_OUTPUT"
if [ "$ENTRY_COUNT" -eq 0 ]; then
echo "No eligible SDK changes detected, skipping commit and PR creation."
echo "sync_target=no eligible SDK changes" >> "$GITHUB_OUTPUT"
echo "pr_url=" >> "$GITHUB_OUTPUT"
exit 0
fi
BRANCH_SUFFIX="$(jq -r '.branchSuffix' "$OUTPUT_JSON")"
PR_TITLE="$(jq -r '.prTitle' "$OUTPUT_JSON")"
SYNC_TARGET="$(jq -r 'if (.entries | length) == 1 then "\(.entries[0].repoDisplayName) \(.entries[0].version)" else "\(.entries | length) SDK releases" end' "$OUTPUT_JSON")"
SUMMARY_LINES="$(jq -r '.entries[] | "- \(.repoDisplayName) \(.version) ([Release](\(.releaseUrl)))"' "$OUTPUT_JSON")"
FILE_LINES="$(jq -r '.entries[] | "- `\(.filePath)` (new or updated snippet)"' "$OUTPUT_JSON")"
BRANCH_NAME="changelog-sync/${BRANCH_SUFFIX}"
if git ls-remote --exit-code --heads origin "$BRANCH_NAME" >/dev/null 2>&1; then
BRANCH_NAME="${BRANCH_NAME}-${GITHUB_RUN_ID}"
fi
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git checkout -b "$BRANCH_NAME"
git add "snippets/changelog" "changelog/index.mdx"
if git diff --cached --quiet; then
echo "No changes detected, skipping commit and PR creation."
echo "sync_target=${SYNC_TARGET}" >> "$GITHUB_OUTPUT"
echo "pr_url=" >> "$GITHUB_OUTPUT"
exit 0
fi
git commit -m "${PR_TITLE}"
git push -u origin "$BRANCH_NAME"
PR_URL="$(gh pr create \
--repo box/box-mintlify \
--title "${PR_TITLE}" \
--body "$(cat <<EOF
## Summary
${SUMMARY_LINES}
## Files changed
- \`changelog/index.mdx\` (updated import + component usage)
${FILE_LINES}
---
*Auto-generated by sync-mintlify workflow in box-developer-changelog*
EOF
)")"
echo "sync_target=${SYNC_TARGET}" >> "$GITHUB_OUTPUT"
echo "pr_url=${PR_URL}" >> "$GITHUB_OUTPUT"
- name: Notify Slack (success)
if: success()
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "${{ steps.create_pr.outputs.pr_url != '' && format('Changelog sync to Mintlify opened PR: {0} <{1}|Open PR>', steps.create_pr.outputs.sync_target, steps.create_pr.outputs.pr_url) || format('Changelog sync to Mintlify completed with no PR: {0}', steps.create_pr.outputs.sync_target) }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
- name: Notify Slack (failure)
if: failure()
uses: slackapi/slack-github-action@v1
with:
payload: |
{
"text": "Changelog sync to Mintlify FAILED on ${{ github.ref_name }}. Check: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
}
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}