fix: Use .env instead of .env.local in GitHub Actions deploy #3
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: Deploy to Motia Cloud | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_dispatch: | |
| inputs: | |
| versionName: | |
| description: 'Version Name to deploy (e.g., v1.2.0)' | |
| required: false | |
| versionDescription: | |
| description: 'Version Description to deploy' | |
| required: false | |
| env: | |
| # API Key stored as GitHub Secret (NEVER commit API keys to code) | |
| MOTIA_API_KEY: ${{ secrets.MOTIA_API_KEY }} | |
| # Project name in Motia Cloud | |
| MOTIA_PROJECT_NAME: git-history | |
| # Environment ID from Motia Cloud dashboard (Settings tab) | |
| MOTIA_ENV_ID: ${{ secrets.MOTIA_ENV_ID }} | |
| jobs: | |
| deploy: | |
| name: Deploy to Motia Cloud | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # Fetch all history for commit count | |
| - name: Generate Version Number | |
| id: version | |
| run: | | |
| # Get commit count for incremental versioning | |
| COMMIT_COUNT=$(git rev-list --count HEAD) | |
| # Calculate version: major.minor.patch based on commit count | |
| MAJOR=1 | |
| MINOR=$((COMMIT_COUNT / 100)) | |
| PATCH=$((COMMIT_COUNT % 100)) | |
| AUTO_VERSION="v${MAJOR}.${MINOR}.${PATCH}" | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.versionName }}" ]; then | |
| echo "VERSION_NAME=${{ github.event.inputs.versionName }}" >> $GITHUB_ENV | |
| echo "VERSION_DESCRIPTION=${{ github.event.inputs.versionDescription || github.event.head_commit.message }}" >> $GITHUB_ENV | |
| else | |
| echo "VERSION_NAME=${AUTO_VERSION}" >> $GITHUB_ENV | |
| echo "VERSION_DESCRIPTION=${{ github.event.head_commit.message }}" >> $GITHUB_ENV | |
| fi | |
| echo "Generated version: ${AUTO_VERSION}" | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '22' | |
| cache: 'npm' | |
| cache-dependency-path: 'package-lock.json' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Generate types | |
| run: npx motia generate-types | |
| - name: Create Env file from Secrets | |
| run: | | |
| # Create .env file from GitHub Secrets (secure way to pass env vars) | |
| echo "GITHUB_TOKEN=${{ secrets.GH_TOKEN }}" > .env | |
| # Add any other environment variables your app needs here | |
| # echo "OTHER_VAR=${{ secrets.OTHER_VAR }}" >> .env | |
| - name: Deploy to Motia Cloud | |
| run: | | |
| npx motia cloud deploy \ | |
| --api-key ${{ env.MOTIA_API_KEY }} \ | |
| --project-name ${{ env.MOTIA_PROJECT_NAME }} \ | |
| --environment-id ${{ env.MOTIA_ENV_ID }} \ | |
| --version-name "${{ env.VERSION_NAME }}" \ | |
| --version-description "${{ env.VERSION_DESCRIPTION }}" \ | |
| --env-file .env | |
| - name: Deployment Summary | |
| run: | | |
| echo "## 🚀 Deployment Complete" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Version:** ${{ env.VERSION_NAME }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Description:** ${{ env.VERSION_DESCRIPTION }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Branch:** ${{ github.ref_name }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- **Commit:** ${{ github.sha }}" >> $GITHUB_STEP_SUMMARY | |