-
Notifications
You must be signed in to change notification settings - Fork 17
150 lines (140 loc) · 6.42 KB
/
update-docs.yml
File metadata and controls
150 lines (140 loc) · 6.42 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
name: Update Documentation
on:
workflow_dispatch:
schedule:
- cron: '0 20 * * *'
jobs:
update-docs:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Set Up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'
- name: Fetch Latest OpenAPI Specification
run: curl -o openapi.json https://api.twitter.com/2/openapi.json
- name: Remove Existing api-reference Directory
run: rm -rf api-reference
- name: Generate MDX Files
run: npx @mintlify/scraping@latest openapi-file ./openapi.json -o api-reference
- name: Rename Subdirectories
run: |
if [ -d "api-reference/tweets" ]; then
mv api-reference/tweets api-reference/posts
fi
if [ -d "api-reference/mediaupload" ]; then
mv api-reference/mediaupload/* api-reference/media
fi
# Add more rename commands here if needed, e.g.:
# if [ -d "api-reference/other" ]; then
# mv api-reference/other api-reference/newname
# fi
- name: Move Files Within api-reference
run: |
# Ensure the destination directory exists
mkdir -p api-reference/openapi
# Move the file if it exists
if [ -f "api-reference/general/returns-the-openapi-specification-document.mdx" ]; then
mv api-reference/general/returns-the-openapi-specification-document.mdx api-reference/openapi/returns-the-openapi-specification-document.mdx
echo "Moved returns-the-openapi-specification-document.mdx from general to openapi"
else
echo "Source file api-reference/general/returns-the-openapi-specification-document.mdx not found"
fi
# Ensure the destination directory exists
mkdir -p api-reference/posts
# Move the file if it exists
if [ -f "api-reference/general/rules-count.mdx" ]; then
mv api-reference/general/rules-count.mdx api-reference/posts/rules-count.mdx
echo "Moved rules-count.mdx from general to posts"
else
echo "Source file api-reference/general/rules-count.mdx not found"
fi
- name: Rename Files Containing '%'
run: |
find api-reference -type f -name '*%*.mdx' -exec bash -c '
new_name="${0//%/}"
if [ ! -f "$new_name" ]; then
mv "$0" "$new_name"
else
echo "Cannot rename $0 to $new_name: file already exists"
fi
' {} \;
- name: Rename Files
run: |
if [ -f "api-reference/posts/analytics-of-posts.mdx" ]; then
mv api-reference/posts/analytics-of-posts.mdx api-reference/posts/get-engagement-analytics.mdx
echo "Renamed analytics-of-posts.mdx to get-engagement-analytics.mdx"
else
echo "Source file api-reference/posts/analytics-of-posts.mdx not found"
fi
if [ -f "api-reference/media/analytics-of-media.mdx" ]; then
mv api-reference/media/analytics-of-media.mdx api-reference/media/get-media-analytics.mdx
echo "Renamed analytics-of-media.mdx to get-media-analytics.mdx"
else
echo "Source file api-reference/posts/analytics-of-posts.mdx not found"
fi
if [ -f "api-reference/media/initialize-a-media-upload-request.mdx" ]; then
mv api-reference/media/initialize-a-media-upload-request.mdx api-reference/media/media-upload-initialize.mdx
echo "Renamed initialize-a-media-upload-request.mdx to media-upload-initialize.mdx"
else
echo "Source file api-reference/media/initialize-a-media-upload-request.mdx not found"
fi
if [ -f "api-reference/media/media-upload-resumable-upload-append-endpoint.mdx" ]; then
mv api-reference/media/media-upload-resumable-upload-append-endpoint.mdx api-reference/media/media-upload-append.mdx
echo "Renamed media-upload-resumable-upload-append-endpoint.mdx to media-upload-append.mdx"
else
echo "Source file api-reference/media/media-upload-resumable-upload-append-endpoint.mdx not found"
fi
if [ -f "api-reference/media/finalize-a-media-upload-request.mdx" ]; then
mv api-reference/media/finalize-a-media-upload-request.mdx api-reference/media/media-upload-finalize.mdx
echo "Renamed finalize-a-media-upload-request.mdx to media-upload-finalize.mdx"
else
echo "Source file api-reference/media/finalize-a-media-upload-request.mdx not found"
fi
- name: Remove Files
run: |
if [ -f "api-reference/compliance/posts-label-stream.mdx" ]; then
rm api-reference/compliance/posts-label-stream.mdx
echo "Removed posts-label-stream.mdx"
else
echo "Source file api-reference/compliance/posts-label-stream.mdx not found"
fi
- name: Move Files to x-api
run: |
# Function to move files from api-reference to x-api
move_files() {
local src_dir=$1
local dest_dir=$2
for item in "$src_dir"/*; do
if [ -d "$item" ]; then
# Handle subdirectories
local base_name=$(basename "$item")
local new_dest="$dest_dir/$base_name"
mkdir -p "$new_dest" # Create subdirectory in x-api if it doesn’t exist
move_files "$item" "$new_dest" # Recursively move contents
elif [ -f "$item" ]; then
# Move individual files
local file_name=$(basename "$item")
local dest_file="$dest_dir/$file_name"
mv "$item" "$dest_file" # Move file to x-api subdirectory
fi
done
}
# Start moving files from api-reference to x-api
move_files "api-reference" "x-api"
- name: Remove api-reference Directory
run: rm -rf api-reference
- name: Commit and Push Changes
run: |
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
git add openapi.json x-api
if git commit -m "Update documentation with latest OpenAPI spec"; then
git push
else
echo "No changes to commit"
fi