Skip to content

Commit 1f17cb7

Browse files
RihanArfanatinux
andauthored
docs: NuxtHub github action & app (#390)
Co-authored-by: Sébastien Chopin <[email protected]> Co-authored-by: Sébastien Chopin <[email protected]>
1 parent d6e5a41 commit 1f17cb7

9 files changed

+214
-48
lines changed

docs/content/0.index.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ hero:
1010
light: '/images/landing/hero-light.svg'
1111
dark: '/images/landing/hero-dark.svg'
1212
headline:
13-
label: "Cloudflare Access integration"
14-
to: /changelog/cloudflare-access
13+
label: "NuxtHub Github App & Action"
14+
to: /changelog/github-app-and-action
1515
icon: i-lucide-arrow-right
1616
features:
1717
- name: Cloud Hosting

docs/content/1.docs/1.getting-started/3.deploy.md

+144-46
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ Toggle between production and preview environments in the NuxtHub admin using th
4343

4444
## NuxtHub CLI
4545

46-
::important
47-
If you do your first deployment with the NuxtHub CLI, you won't be able to attach your GitHub/GitLab repository later on due to a Cloudflare limitation, but you can use the [Github action](#github-action) to deploy on commit.
48-
::
49-
5046
Deploy your local project with a single command:
5147

5248
```bash [Terminal]
@@ -71,76 +67,178 @@ The command will:
7167
You can also install the [NuxtHub CLI](https://github.com/nuxt-hub/cli) globally with: `npm i -g nuxthub`.
7268
::
7369

74-
### GitHub Action
70+
## GitHub Action
71+
72+
After linking a GitHub repository to your project, NuxtHub automatically adds a GitHub Actions workflow to automatically deploy your application on every commit using the [NuxtHub GitHub Action](https://github.com/marketplace/actions/deploy-to-nuxthub).
73+
74+
NuxtHub integrates with [GitHub deployments](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments). This allows you to:
75+
- [View deployment statuses within GitHub](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/viewing-deployment-history)
76+
- [Setup deployment concurrency](https://docs.github.com/en/actions/use-cases-and-examples/deploying/deploying-with-github-actions#using-concurrency)
77+
- [Require approvals for deploying to environments](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/reviewing-deployments)
7578

76-
To deploy your project with a GitHub Action, you can use the following workflow:
79+
After deploying from a pull request, NuxtHub automatically adds a comment with information about the deployment.
80+
81+
:nuxt-img{src="/images/docs/nuxthub-github-app-pr-comment.png" alt="NuxtHUb GitHub Action commenting on pull requests" width="926" height="520"}
82+
83+
::tip
84+
You can customise the workflow to tailor to any specific custom DevOps requirements.
85+
::
7786

78-
```yaml [.github/workflows/deploy.yml]
79-
name: Deploy with NuxtHub CLI
87+
::note{to="#linking-a-repository-to-existing-projects"}
88+
Projects created prior to releasing our GitHub Action uses Pages CI for deployments. Read our [migration guide](#linking-a-repository-to-existing-projects).
89+
::
90+
91+
### Default workflow
92+
93+
The GitHub Workflow added to your repository is automatically tailored to your project's package manager. This is an example of a workflow added for a project using pnpm.
94+
95+
Currently, the supported package managers
96+
97+
```yaml [.github/workflows/nuxthub.yml]
98+
name: Deploy to NuxtHub
8099
on: push
100+
81101
jobs:
82-
build-and-deploy:
102+
deploy:
103+
name: "Deploy to NuxtHub"
83104
runs-on: ubuntu-latest
105+
environment:
106+
name: ${{ github.ref == 'refs/heads/main' && 'production' || 'preview' }}
107+
url: ${{ steps.deploy.outputs.deployment-url }}
108+
permissions:
109+
contents: read
110+
id-token: write
111+
84112
steps:
85-
- name: Checkout
86-
uses: actions/checkout@v4
87-
- uses: pnpm/action-setup@v4
88-
name: Install pnpm
113+
- uses: actions/checkout@v4
114+
115+
- name: Install pnpm
116+
uses: pnpm/action-setup@v4
89117
with:
90-
run_install: false
118+
version: 9
119+
91120
- name: Install Node.js
92121
uses: actions/setup-node@v4
93122
with:
94-
node-version: 20
123+
node-version: 22
95124
cache: 'pnpm'
96-
- name: Get pnpm store directory
97-
shell: bash
98-
run: |
99-
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
100-
- uses: actions/cache@v4
101-
name: Setup pnpm cache
102-
with:
103-
path: ${{ env.STORE_PATH }}
104-
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
105-
restore-keys: |
106-
${{ runner.os }}-pnpm-store-
125+
107126
- name: Install dependencies
108127
run: pnpm install
109128

110-
- name: Deploy with nuxthub
111-
run: npx nuxthub deploy
112-
env:
113-
NUXT_HUB_PROJECT_KEY: ${{ secrets.NUXT_HUB_PROJECT_KEY}}
114-
NUXT_HUB_USER_TOKEN: ${{ secrets.NUXT_HUB_USER_TOKEN }}
129+
- name: Build application
130+
run: pnpm run build
131+
132+
- name: Deploy to NuxtHub
133+
uses: nuxt-hub/action@v1
134+
id: deploy
115135
```
116136
117-
You need to add the following secrets to your GitHub repository:
118-
- `NUXT_HUB_PROJECT_KEY`: Your project key (available in your project settings in the NuxtHub Admin or in your `.env` file if you ran `npx nuxthub link`)
119-
- `NUXT_HUB_USER_TOKEN`: Your user token available in **User settings** → **Tokens** in the NuxtHub Admin
137+
### Options
120138
121-
::tip
122-
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.
139+
#### Inputs
140+
141+
The following input parameters can be provided to the GitHub Action. Learn more about [Workflow syntax for GitHub Actions](https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#jobsjob_idstepswith) on GitHub's documentation.
142+
143+
::field-group
144+
::field{name="directory" type="string" default="dist"}
145+
The directory of the built Nuxt application. Defaults to `dist`.
146+
::
147+
148+
::field{name="project-key" type="string"}
149+
The project key of the NuxtHub project to deploy to. If the repository is linked to more than one project, project key is required.
150+
::
123151
::
124152

153+
#### Outputs
154+
155+
The GitHub Action provides the following outputs that you can use in subsequent workflow steps.
156+
157+
158+
::field-group
159+
::field{name="environment" type="'production' | 'preview'"}
160+
The environment of the deployment (e.g. production, preview).
161+
::
162+
163+
::field{name="deployment-url" type="string"}
164+
The URL of the deployment. For preview environments, it links to the deployment of the commit.
165+
166+
Examples:
167+
- https://example.nuxt.dev (main)
168+
- https://abcdefg.example.pages.dev (feat/example)
169+
::
170+
171+
::field{name="branch-url" type="string"}
172+
The permanent URL for the current branch deployment.
173+
174+
Examples:
175+
- https://example.nuxt.dev (main)
176+
- https://feat-example.example.pages.dev (feat/example)
177+
::
178+
::
179+
180+
### Environment Variables & Secrets
181+
182+
NuxtHub automatically copies all your project's environment variables to your GitHub repository actions environment variables.
183+
184+
When encrypting an environment variable in the NuxtHub Admin, a GitHub actions secret will be created in your repository
185+
186+
In order to use the GitHub Actions secret, you need to update the GitHub Actions workflow to use the secret as environment variable:
187+
188+
```diff [.github/workflows/nuxthub.yml]
189+
- name: Build application
190+
run: pnpm run build
191+
+ env:
192+
+ NUXT_UI_PRO_LICENSE: ${{ secrets.NUXT_UI_PRO_LICENSE }}
193+
```
194+
125195
::note
126-
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.
196+
This is mostly useful for build-time environment variables.
127197
::
128198

129-
## Cloudflare Pages CI
199+
### Setup
200+
201+
#### Creating a new project
202+
203+
When creating a new project from a template, or importing a Git repository, the GitHub Action workflow will automatically be set up for you.
204+
205+
#### Linking a repository to existing projects
206+
207+
Link your project to a GitHub repository within [NuxtHub Admin](https://admin.hub.nuxt.com/) → Project → Settings → Git.
130208

131209
::warning
132-
You should never create the project on Cloudflare Pages as NuxtHub will create it for you.
210+
Only non-secret environment variables are automatically copied to GitHub. Existing environment secrets are not automatically migrated to GitHub, and should be updated to sync them to GitHub.
133211
::
134212

135-
It is possible to use [Cloudflare Pages CI](https://pages.cloudflare.com) to deploy your project by connecting your GitHub or GitLab account. Once your repository is connected, each commit will trigger a new deployment.
213+
#### Monorepo setup
136214

137-
1. Open the [NuxtHub Admin](https://admin.hub.nuxt.com)
138-
2. Click on `New Project` then `Import a GitHub repository`
139-
3. Select your Github repository
140-
4. Click on `Import repository`
215+
Our GitHub integration supports deploying multiple applications from the same repository.
141216

142-
::tip
143-
That's it! NuxtHub will automatically configure the necessary resources and environment variables for you start a deployment on Cloudflare.
217+
When linking a Git repository, set "project root directory" to the base folder of your Nuxt application corresponding to that NuxtHub project.
218+
219+
When a repository is already linked to at least one project, additional projects linked will have the generated GitHub Actions workflow named `nuxthub-<projectSlug>.yml`.
220+
221+
::note
222+
When multiple projects are linked to the same repository, the [`project-key`](#inputs) input parameter must be specified on each [Deploy to NuxtHub GitHub Action](https://github.com/marketplace/actions/deploy-to-nuxthub).
223+
::
224+
225+
**Current limitations**
226+
227+
- Separate applications should be deployed using different workflow jobs.
228+
229+
## Cloudflare Pages CI
230+
231+
Importing an existing Cloudflare Pages project that is already linked to a Git repository will use [Cloudflare Pages CI](https://pages.cloudflare.com) to deploy your project.
232+
233+
- Each commit will trigger a new deployment within Pages CI.
234+
- Environment variables set within NuxtHub Admin will be available during CI.
235+
236+
::note
237+
All existing projects with a Git repository linked to Cloudflare Pages prior to our GitHub Action being released uses [Cloudflare Pages CI](https://pages.cloudflare.com) for automated deployments.
238+
::
239+
240+
::tip{to="#migrating-to-from-pages-ci"}
241+
You can migrate from Cloudflare Pages CI to [GitHub Actions](#github-action) at any time. Read our [migration guide](#linking-a-repository-to-existing-projects).
144242
::
145243

146244
## Self-hosted
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: NuxtHub GitHub App & Action
3+
description: "Introducing our GitHub App & Action for automating your Nuxt deployments with GitHub as well as a new project creation flow."
4+
date: 2024-12-23
5+
image: '/images/changelog/nuxthub-github-app-action.png'
6+
authors:
7+
- name: Rihan Arfan
8+
avatar:
9+
src: https://avatars.githubusercontent.com/u/20425781?v=4
10+
to: https://bsky.app/profile/rihan.dev
11+
username: RihanArfan
12+
- name: Sebastien Chopin
13+
avatar:
14+
src: https://avatars.githubusercontent.com/u/904724?v=4
15+
to: https://bsky.app/profile/atinux.com
16+
username: atinux
17+
---
18+
19+
We're thrilled to release our brand new [GitHub Application](https://github.com/apps/nuxthub-admin) & [GitHub Action](https://github.com/marketplace/actions/deploy-to-nuxthub) to help you create and deploy Nuxt applications to NuxtHub.
20+
21+
22+
## Pull Request Integration
23+
24+
Once setup, NuxtHub will automatically comment on pull requests with branch URLs, permalinks and QR codes for easy preview access.
25+
26+
:nuxt-img{src="/images/changelog/nuxthub-github-app-action.png" alt="GitHub Action" width="926" height="520"}
27+
28+
## GitHub Deployments
29+
30+
NuxtHub also integrates with GitHub's deployment system, including status updates and environment tracking.
31+
32+
:nuxt-img{src="/images/changelog/nuxthub-github-action-deployment.png" alt="NuxtHub GitHub Action deployments" width="926" height="521"}
33+
34+
This includes GitHub Deployments support in pull requests.
35+
36+
:nuxt-img{src="/images/changelog/nuxthub-github-action-deployment-pr.png" alt="NuxtHub GitHub Action deployments" width="926" height="219"}
37+
38+
And many more:
39+
- **Deployment Protection**: Support for GitHub's deployment protection rules which enable approval workflows and environment restrictions ([learn more on GitHub's documentation](https://docs.github.com/en/actions/managing-workflow-runs-and-deployments/managing-deployments/managing-environments-for-deployment#deployment-protection-rules))
40+
- **Secure**: Our GitHub integration prevents the need for long-lived secrets as it uses OIDC under the hood
41+
- **Customizable**: You can create tailored workflows to fit your DevOps requirements using our GitHub Action
42+
43+
## Cloning a Template
44+
45+
Thanks to the new GitHub App, you can now clone a template from NuxtHub Admin and deploy it with a single click.
46+
47+
:nuxt-img{src="/images/changelog/nuxthub-github-app-clone-template.png" alt="NuxtHub GitHub App clone template" width="2596" height="1460"}
48+
49+
::note
50+
The repository will be created in your GitHub account with the GitHub Actions workflow already configured.
51+
::
52+
53+
## Migrating to GitHub Actions
54+
55+
Migrating from Cloudflare Pages CI or the legacy GitHub Action is simple and can be done from [NuxtHub Admin](https://admin.hub.nuxt.com/) → Project → Settings → Git.
56+
57+
<!-- img of migration alert -->
58+
59+
When migrating from Cloudflare Pages CI, please note:
60+
61+
- Deployment quotas will shift from [Pages CI limits](https://developers.cloudflare.com/pages/platform/limits/#builds) to your [GitHub Actions usage](https://docs.github.com/en/billing/managing-billing-for-your-products/managing-billing-for-github-actions/about-billing-for-github-actions#included-storage-and-minutes)
62+
- Environment variables and secrets needed at build time should be managed through [GitHub Environment settings](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/store-information-in-variables#creating-configuration-variables-for-an-environment) (we are working on a way to synchronize them automatically)
63+
64+
::callout{to="/docs/getting-started/deploy#github-action" icon="i-lucide-book"}
65+
Learn more about deploying with GitHub Actions to NuxtHub.
66+
::
67+
68+
P.S. Give our new [GitHub Action](https://github.com/nuxt-hub/action) a star 🌟💚
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)