Update Documentation #157
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: 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 | |
| # 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 |