forked from raycast/extensions
-
Notifications
You must be signed in to change notification settings - Fork 0
102 lines (88 loc) · 3.46 KB
/
sync-api-docs.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
name: Sync API Docs
on:
push:
paths:
- "docs/**"
- "!docs/utils-reference/**"
branches: ["main"]
jobs:
push-api-docs-to-upstream:
if: github.repository == 'raycast/extensions'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 2
- name: Setup Node.js
uses: raycast/github-actions/setup-node@master
- name: Get changed files in the docs folder
id: changed-files
uses: tj-actions/changed-files@v19
with:
files: |
docs/**
!docs/.config.json
!docs/utils-reference/**
- name: Setup git
uses: raycast/github-actions/setup-git@master
- name: Update the docs in the main repo
if: steps.changed-files.outputs.any_changed == 'true' || steps.changed-files.outputs.any_deleted == 'true'
id: commit
env:
API_TOKEN_GITHUB: ${{ secrets.RAYCAST_BOT_API_ACCESS_TOKEN }}
run: |
###########################
# sync docs
###########################
echo "🛠️ Syncing to main repo..."
cd ${{ github.workspace }}
git clone --depth=1 --single-branch --branch "master" "https://[email protected]/raycast/raycast-macos.git" "raycast-macos"
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
echo "Removing raycast-macos/Commands/$file"
# If it's already removed, that's ok
rm "raycast-macos/Commands/$file" || true
done
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "Updating raycast-macos/Commands/$file"
# If this fails, it's because there is a space in the filename
# so it's from GitBook messing things up. Ignore it
rsync -arv "$file" "raycast-macos/Commands/$file" || true
done
cd raycast-macos
if [[ $(git diff --stat) != '' ]]; then
git checkout -b docs-sync-${{ github.sha }}
git add .
git commit -m 'API Docs: Update from the extensions repo'
git push origin docs-sync-${{ github.sha }}
echo 'has_commit=true' >> $GITHUB_OUTPUT
else
echo 'No changes'
echo 'has_commit=false' >> $GITHUB_OUTPUT
fi
- name: Open PR on the main repo
uses: actions/github-script@v6
if: steps.commit.outputs.has_commit == 'true'
with:
github-token: ${{ secrets.RAYCAST_BOT_API_ACCESS_TOKEN }}
script: |
github.rest.pulls.create({
owner: 'raycast',
repo: 'raycast-macos',
head: 'docs-sync-${{ github.sha }}',
base: 'master',
title: 'API Docs: Update from the extensions repo'
})
- name: Notify Failure to Slack
if: failure()
uses: edge/simple-slack-notify@master
with:
color: "danger"
text: ":no_entry_sign: ${env.GITHUB_WORKFLOW} has failed"
fields: |
[
{ "title": "Action logs:", "value": "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/actions/runs/${env.GITHUB_RUN_ID}"},
{ "title": "Commit:", "value": "${env.GITHUB_SERVER_URL}/${env.GITHUB_REPOSITORY}/commit/${ env.GITHUB_SHA }"}
]
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_RELEASE_CHANNEL_WEBHOOK_URL }}