|
| 1 | +# Sample workflow for building and deploying a Nuxt site to GitHub Pages |
| 2 | +# |
| 3 | +# To get started with Nuxt see: https://nuxtjs.org/docs/get-started/installation |
| 4 | +# |
| 5 | +name: Deploy Nuxt site to Pages |
| 6 | + |
| 7 | +on: |
| 8 | + # Runs on pushes targeting the default branch |
| 9 | + push: |
| 10 | + branches: ["master"] |
| 11 | + |
| 12 | + # Allows you to run this workflow manually from the Actions tab |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages |
| 16 | +permissions: |
| 17 | + contents: read |
| 18 | + pages: write |
| 19 | + id-token: write |
| 20 | + |
| 21 | +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. |
| 22 | +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. |
| 23 | +concurrency: |
| 24 | + group: "pages" |
| 25 | + cancel-in-progress: false |
| 26 | + |
| 27 | +jobs: |
| 28 | + # Build job |
| 29 | + build: |
| 30 | + runs-on: ubuntu-latest |
| 31 | + steps: |
| 32 | + - name: Checkout |
| 33 | + uses: actions/checkout@v4 |
| 34 | + - name: Detect package manager |
| 35 | + id: detect-package-manager |
| 36 | + run: | |
| 37 | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
| 38 | + echo "manager=yarn" >> $GITHUB_OUTPUT |
| 39 | + echo "command=install" >> $GITHUB_OUTPUT |
| 40 | + exit 0 |
| 41 | + elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 42 | + echo "manager=npm" >> $GITHUB_OUTPUT |
| 43 | + echo "command=ci" >> $GITHUB_OUTPUT |
| 44 | + exit 0 |
| 45 | + else |
| 46 | + echo "Unable to determine package manager" |
| 47 | + exit 1 |
| 48 | + fi |
| 49 | + - name: Setup Node |
| 50 | + uses: actions/setup-node@v4 |
| 51 | + with: |
| 52 | + node-version: "20" |
| 53 | + cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 54 | + - name: Setup Pages |
| 55 | + uses: actions/configure-pages@v5 |
| 56 | + with: |
| 57 | + # Automatically inject router.base in your Nuxt configuration file and set |
| 58 | + # target to static (https://nuxtjs.org/docs/configuration-glossary/configuration-target/). |
| 59 | + # |
| 60 | + # You may remove this line if you want to manage the configuration yourself. |
| 61 | + static_site_generator: nuxt |
| 62 | + - name: Restore cache |
| 63 | + uses: actions/cache@v4 |
| 64 | + with: |
| 65 | + path: | |
| 66 | + dist |
| 67 | + .nuxt |
| 68 | + key: ${{ runner.os }}-nuxt-build-${{ hashFiles('dist') }} |
| 69 | + restore-keys: | |
| 70 | + ${{ runner.os }}-nuxt-build- |
| 71 | + - name: Install dependencies |
| 72 | + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 73 | + - name: Static HTML export with Nuxt |
| 74 | + run: ${{ steps.detect-package-manager.outputs.manager }} run generate |
| 75 | + - name: Upload artifact |
| 76 | + uses: actions/upload-pages-artifact@v3 |
| 77 | + with: |
| 78 | + path: ./dist |
| 79 | + |
| 80 | + # Deployment job |
| 81 | + deploy: |
| 82 | + environment: |
| 83 | + name: github-pages |
| 84 | + url: ${{ steps.deployment.outputs.page_url }} |
| 85 | + runs-on: ubuntu-latest |
| 86 | + needs: build |
| 87 | + steps: |
| 88 | + - name: Deploy to GitHub Pages |
| 89 | + id: deployment |
| 90 | + uses: actions/deploy-pages@v4 |
0 commit comments