feat: autodeploy #1
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 Application | |
| # This workflow handles automated deployment for nn-stack. | |
| # It supports two environments: 'dev' branch to 'dev' stage, and 'main' branch to 'prod' stage. | |
| # | |
| # SETUP INSTRUCTIONS: | |
| # To enable automated deployment, add the following secrets to your GitHub repository: | |
| # (Settings -> Secrets and variables -> Actions) | |
| # | |
| # 1. CLOUDFLARE_API_TOKEN: | |
| # - How to get: Cloudflare Dashboard -> My Profile -> API Tokens -> Create Token. | |
| # - Permissions: Use "Edit Cloudflare Workers" template, and ensure "Account -> Cloudflare KV Storage -> Edit" is added. | |
| # | |
| # 2. ALCHEMY_STATE_TOKEN: | |
| # - How to get: Generate a random string. | |
| # - Command: node -e "console.log(require('crypto').randomBytes(32).toString('base64url'))" | |
| # | |
| # 3. CLOUDFLARE_ACCOUNT_ID: | |
| # - How to get: Cloudflare Dashboard -> Workers & Pages -> Overview (Found on the right sidebar). | |
| # | |
| # 4. ENV_SERVER_DEV / ENV_SERVER_PROD: | |
| # - How to get: The full content of your apps/server/.env file for each stage. | |
| # | |
| # 5. ENV_WEB_DEV / ENV_WEB_PROD: | |
| # - How to get: The full content of your apps/web/.env file for each stage. | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - dev | |
| concurrency: | |
| group: deploy-${{ github.ref }} | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| with: | |
| run_install: false | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 24 | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install | |
| - name: Inject Environment Files (Dev) | |
| if: github.ref == 'refs/heads/dev' | |
| run: | | |
| echo "${{ secrets.ENV_SERVER_DEV }}" > apps/server/.env | |
| echo "${{ secrets.ENV_WEB_DEV }}" > apps/web/.env | |
| - name: Inject Environment Files (Prod) | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| echo "${{ secrets.ENV_SERVER_PROD }}" > apps/server/.env | |
| echo "${{ secrets.ENV_WEB_PROD }}" > apps/web/.env | |
| - name: Deploy to Dev | |
| if: github.ref == 'refs/heads/dev' | |
| run: pnpm run deploy:dev | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| ALCHEMY_STATE_TOKEN: ${{ secrets.ALCHEMY_STATE_TOKEN }} | |
| - name: Deploy to Prod | |
| if: github.ref == 'refs/heads/main' | |
| run: pnpm run deploy:prod | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
| CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
| ALCHEMY_STATE_TOKEN: ${{ secrets.ALCHEMY_STATE_TOKEN }} |