-
Notifications
You must be signed in to change notification settings - Fork 18
107 lines (95 loc) · 3.55 KB
/
update-docs.yml
File metadata and controls
107 lines (95 loc) · 3.55 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
name: Update Documentation
on:
workflow_dispatch:
schedule:
- cron: '0 17 * * *' # 9am PT
- cron: '0 20 * * *' # 12pm PT
- cron: '0 23 * * *' # 3pm PT
- cron: '0 2 * * *' # 6pm PT
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: Install Puppeteer
run: npm install puppeteer
- name: Fetch Latest OpenAPI Specification with Puppeteer
run: |
cat << EOF > fetch-openapi.js
const puppeteer = require('puppeteer');
const fs = require('fs/promises');
(async () => {
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
const page = await browser.newPage();
const response = await page.goto('https://api.twitter.com/2/openapi.json', { waitUntil: 'networkidle0' });
const body = await response.text();
await fs.writeFile('openapi.json', body);
await browser.close();
})();
EOF
node fetch-openapi.js
- 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
# Add more rename commands here if needed, e.g.:
# if [ -d "api-reference/other" ]; then
# mv api-reference/other api-reference/newname
# 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: 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