nuxt-hub/cli

Is it possible to use nuxthub cli in GitHub Actions?

stonega opened this issue · 6 comments

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

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:

  • NUXT_HUB_PROJECT_KEY that you can get in your project settings
  • NUXT_HUB_USER_TOKEN that you can create by cliking on your username in the admin -> Settings -> Tokens

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!

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 }}

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

(re-opening to keep it to do)

@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 }}