From f1e91f82e7cae2e2a063d0db7f5c59b30382460a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Chopin?= Date: Fri, 28 Jun 2024 11:46:58 +0200 Subject: [PATCH] docs: add GitHub Action example --- .../1.docs/1.getting-started/3.deploy.md | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/docs/content/1.docs/1.getting-started/3.deploy.md b/docs/content/1.docs/1.getting-started/3.deploy.md index 447cf1be..51e899dc 100644 --- a/docs/content/1.docs/1.getting-started/3.deploy.md +++ b/docs/content/1.docs/1.getting-started/3.deploy.md @@ -52,6 +52,63 @@ The command will: ::note You can also install the [NuxtHub CLI](https://github.com/nuxt-hub/cli) globally with: `npm i -g nuxthub`. :: + +#### GitHub Action + +To deploy your project with a GitHub Action, you can use the following workflow: + +```yaml [.github/workflows/deploy.yml] +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 }} +``` + +You need to add the following secrets to your GitHub repository: +- `NUXT_HUB_PROJECT_KEY`: Your project key (available in your project settings in the NuxtHub Admin or in your `.env` file if you ran `nuxthub link`) +- `NUXT_HUB_USER_TOKEN`: Your user token available in your profile settings → Tokens in the NuxtHub Admin + +::tip +We recommend to create a new user token for the Github CI so you can revoke it at any time or add an expiration date. +:: + +::note +This GitHub action uses pnpm to install dependencies. If you are using npm or yarn, we recommend you to adapt the action to your needs. +:: + ## Self-hosted You can deploy your project on your own Cloudflare account without using the NuxtHub Admin.