nuxt-hub / cli

Build full-stack Nuxt application with NuxtHub command line interface (CLI).
Apache License 2.0
38 stars 3 forks source link

Is it possible to use nuxthub cli in GitHub Actions? #15

Closed stonega closed 1 week ago

stonega commented 2 weeks ago

If so, is there any documentation or examples available that demonstrate how to set it up?

Atinux commented 2 weeks ago

It is possible but not documented yet.

It should be the same as using any Node.js CI action + running npx nuxthub deploy with a 2 env variables:

CleanShot 2024-06-25 at 23 50 20@2x

Also released v0.5.13 of the CLI so it should work properly with the env variables.

Would love your feedback on this!

stonega commented 2 weeks ago

Thanks, works like a charm

      - name: Nuxthub deploy
        run: npx nuxthub deploy
        env:
          NUXT_HUB_PROJECT_KEY: ${{ secrets.NUXT_HUB_PROJECT_KEY}}
          NUXT_HUB_USER_TOKEN: ${{ secrets.NUXT_HUB_USER_TOKEN }}
Atinux commented 1 week ago

Would you mind sharing your whole Github action so I could write it in the readme or in the docs?

Atinux commented 1 week ago

(re-opening to keep it to do)

stonega commented 1 week ago

@Atinux It is pretty simple, just pnpm install && deploy.

name: Deploy to Cloudflare with NuxtHub Cli

on:
  push:
    branches: ['main']

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4

      - uses: pnpm/action-setup@v4
        name: Install pnpm
        with:
          run_install: false

      - name: Install Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'pnpm'

      - name: Get pnpm store directory
        shell: bash
        run: |
          echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

      - uses: actions/cache@v4
        name: Setup pnpm cache
        with:
          path: ${{ env.STORE_PATH }}
          key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
          restore-keys: |
            ${{ runner.os }}-pnpm-store-

      - name: Install dependencies
        run: pnpm install

      - name:  Deploy with nuxt-hub cli
        run: npx nuxthub deploy
        env:
          NUXT_HUB_PROJECT_KEY: ${{ secrets.NUXT_HUB_PROJECT_KEY}}
          NUXT_HUB_USER_TOKEN: ${{ secrets.NUXT_HUB_USER_TOKEN }}
Atinux commented 1 week ago

Thanks for sharing!

Updated the docs https://hub.nuxt.com/docs/getting-started/deploy#github-action