Build and Deploy Flash API Docs #10
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: Build and Deploy Flash API Docs | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| environment: | |
| description: 'Environment to deploy to' | |
| required: true | |
| default: 'production' | |
| type: choice | |
| options: | |
| - production | |
| - staging | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '18' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Fetch schema and build documentation | |
| run: npm run build | |
| - name: Upload build artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: site-build | |
| path: public/ | |
| if-no-files-found: error | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Download build artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: site-build | |
| path: public | |
| - name: Install doctl | |
| uses: digitalocean/action-doctl@v2 | |
| with: | |
| token: ${{ secrets.DIGITALOCEAN_ACCESS_TOKEN }} | |
| - name: Verify DigitalOcean Permissions | |
| run: | | |
| echo "Checking DigitalOcean access..." | |
| doctl account get || { | |
| echo "::error::Failed to access DigitalOcean account. Please check your DIGITALOCEAN_ACCESS_TOKEN secret." | |
| echo "The token needs to have both read and write access to apps." | |
| echo "You can create a new token at https://cloud.digitalocean.com/account/api/tokens" | |
| exit 1 | |
| } | |
| echo "Checking App Platform access..." | |
| # Just list apps to verify app platform access | |
| doctl apps list || { | |
| echo "::error::Failed to access DigitalOcean App Platform. Please check your token has the apps scope." | |
| exit 1 | |
| } | |
| - name: Deploy to DigitalOcean App Platform | |
| run: | | |
| # Create tar of the public directory | |
| tar -czf deploy.tar.gz -C public . | |
| # Verify that the APP_ID is set | |
| if [ -z "${{ secrets.DIGITALOCEAN_APP_ID }}" ]; then | |
| echo "::error::DIGITALOCEAN_APP_ID is not set. Please add this secret in your repository settings." | |
| exit 1 | |
| fi | |
| # Check App ID format (UUID validation) | |
| APP_ID="${{ secrets.DIGITALOCEAN_APP_ID }}" | |
| if ! [[ $APP_ID =~ ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$ ]]; then | |
| echo "::error::Invalid App ID format. The App ID should be a valid UUID in the format: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | |
| echo "Please check DIGITALOCEAN_SETUP.md for instructions on finding your correct App ID." | |
| exit 1 | |
| fi | |
| # List available apps to help debugging | |
| echo "Available DigitalOcean apps:" | |
| doctl apps list --format ID,Spec.Name,DefaultIngress --no-header | |
| # Deploy to DigitalOcean App Platform | |
| echo "Deploying to DigitalOcean App Platform (App ID: $APP_ID)..." | |
| # Try the deployment with more verbose output | |
| doctl apps create-deployment "$APP_ID" --wait --format ID --verbose || { | |
| echo "::error::Failed to deploy to DigitalOcean App Platform." | |
| echo "Error: invalid uuid suggests the App ID is not correctly formatted." | |
| echo "" | |
| echo "To find your correct App ID:" | |
| echo "1. Go to https://cloud.digitalocean.com/apps" | |
| echo "2. Click on your app" | |
| echo "3. The App ID is in the URL: https://cloud.digitalocean.com/apps/YOUR-APP-ID-HERE" | |
| echo "4. It should look like: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" | |
| echo "" | |
| echo "Update your DIGITALOCEAN_APP_ID secret with this value." | |
| exit 1 | |
| } | |
| - name: Deployment Summary | |
| run: | | |
| echo "✅ Flash API Documentation has been successfully deployed to DigitalOcean!" | |
| echo "🔗 Live URL: https://flash-api-docs.${GITHUB_REF_NAME/main/flashapp.me}" |