Repository navigation
158 lines (132 loc) · 5.23 KB
/
Copy pathsync-utils-docs.yml
File metadata and controls
158 lines (132 loc) · 5.23 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
148
149
150
151
152
153
154
155
156
157
158
name: Sync Utils Docs
on:
push:
paths:
- "docs/utils-reference/**"
branches: ["main"]
workflow_dispatch:
jobs:
pull-utils-docs-from-upstream:
if: github.repository == 'raycast/extensions' && github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.15.1
- name: Setup git
uses: raycast/github-actions/setup-git@master
- name: Pull the docs
env:
API_TOKEN_GITHUB: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
run: |
cd ${{ github.workspace }}
git clone --depth=1 --single-branch --branch "main" "https://$API_TOKEN_GITHUB@github.com/raycast/utils.git" "raycast-utils"
rm -rf docs/utils-reference
rsync -arv "raycast-utils/docs/utils-reference/" "docs/utils-reference"
rm -rf raycast-utils
if [[ $(git diff --stat) != '' ]]; then
git add docs
git commit -m 'Docs: Update the utils docs'
git push origin main
echo 'has_commit=true' >> $GITHUB_OUTPUT
else
echo 'No changes'
echo 'has_commit=false' >> $GITHUB_OUTPUT
fi
- name: Set SHORT_SHA
if: always()
run: echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Notify Failure to Slack
if: failure()
uses: raycast/github-actions/slack-send@master
with:
webhook: ${{ secrets.SLACK_RELEASE_CHANNEL_WEBHOOK_URL }}
color: "danger"
text: |
:no_entry_sign: ${{ github.workflow }} has failed
<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Action logs> | <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|Commit: ${{ env.SHORT_SHA }}>
push-utils-docs-to-upstream:
if: github.repository == 'raycast/extensions' && github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 20.15.1
- name: Get changed files in the docs folder
id: changed-files
uses: tj-actions/changed-files@v42
with:
files: |
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.PERSONAL_ACCESS_TOKEN }}
run: |
###########################
# sync docs
###########################
echo "🛠️ Syncing to main repo..."
cd ${{ github.workspace }}
git clone --depth=1 --single-branch --branch "main" "https://$API_TOKEN_GITHUB@github.com/raycast/utils.git" "raycast-utils"
for file in ${{ steps.changed-files.outputs.deleted_files }}; do
echo "Removing $file"
# If it's already removed, that's ok
rm "$file" || true
done
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo "Updating $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" "$file" || true
done
cd raycast-utils
if [[ $(git diff --stat) != '' ]]; then
git checkout -b docs-sync-${{ github.sha }}
git add .
git commit -m 'Utils 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@v7
if: steps.commit.outputs.has_commit == 'true'
with:
github-token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
script: |
github.rest.pulls.create({
owner: 'raycast',
repo: 'utils',
head: 'docs-sync-${{ github.sha }}',
base: 'main',
title: 'Docs: Update from the extensions repo'
})
- name: Set SHORT_SHA
if: always()
run: echo "SHORT_SHA=${GITHUB_SHA::8}" >> $GITHUB_ENV
- name: Notify Failure to Slack
if: failure()
uses: raycast/github-actions/slack-send@master
with:
webhook: ${{ secrets.SLACK_RELEASE_CHANNEL_WEBHOOK_URL }}
color: "danger"
text: |
:no_entry_sign: ${{ github.workflow }} has failed
<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Action logs> | <${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }}|Commit: ${{ env.SHORT_SHA }}>