|
| 1 | +# Sample workflow for building and deploying a Gatsby site to GitHub Pages |
| 2 | +# |
| 3 | +# To get started with Gatsby see: https://www.gatsbyjs.com/docs/quick-start/ |
| 4 | +# |
| 5 | +name: Deploy Gatsby 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 one concurrent deployment |
| 22 | +concurrency: |
| 23 | + group: "pages" |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +# Default to bash |
| 27 | +defaults: |
| 28 | + run: |
| 29 | + shell: bash |
| 30 | + |
| 31 | +jobs: |
| 32 | + # Build job |
| 33 | + build: |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - name: Checkout |
| 37 | + uses: actions/checkout@v3 |
| 38 | + - name: Detect package manager |
| 39 | + id: detect-package-manager |
| 40 | + run: | |
| 41 | + if [ -f "${{ github.workspace }}/yarn.lock" ]; then |
| 42 | + echo "::set-output name=manager::yarn" |
| 43 | + echo "::set-output name=command::install" |
| 44 | + exit 0 |
| 45 | + elif [ -f "${{ github.workspace }}/package.json" ]; then |
| 46 | + echo "::set-output name=manager::npm" |
| 47 | + echo "::set-output name=command::ci" |
| 48 | + exit 0 |
| 49 | + else |
| 50 | + echo "Unable to determine packager manager" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + - name: Setup Node |
| 54 | + uses: actions/setup-node@v3 |
| 55 | + with: |
| 56 | + node-version: "16" |
| 57 | + cache: ${{ steps.detect-package-manager.outputs.manager }} |
| 58 | + - name: Setup Pages |
| 59 | + id: pages |
| 60 | + uses: actions/configure-pages@v1 |
| 61 | + with: |
| 62 | + # Automatically inject pathPrefix in your Gatsby configuration file. |
| 63 | + # |
| 64 | + # You may remove this line if you want to manage the configuration yourself. |
| 65 | + static_site_generator: gatsby |
| 66 | + - name: Restore cache |
| 67 | + uses: actions/cache@v3 |
| 68 | + with: |
| 69 | + path: | |
| 70 | + public |
| 71 | + .cache |
| 72 | + key: ${{ runner.os }}-gatsby-build-${{ hashFiles('public') }} |
| 73 | + restore-keys: | |
| 74 | + ${{ runner.os }}-gatsby-build- |
| 75 | + - name: Install dependencies |
| 76 | + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} |
| 77 | + - name: Build with Gatsby |
| 78 | + env: |
| 79 | + PREFIX_PATHS: 'true' |
| 80 | + run: ${{ steps.detect-package-manager.outputs.manager }} run build |
| 81 | + - name: Upload artifact |
| 82 | + uses: actions/upload-pages-artifact@v1 |
| 83 | + with: |
| 84 | + path: ./public |
| 85 | + |
| 86 | + # Deployment job |
| 87 | + deploy: |
| 88 | + environment: |
| 89 | + name: github-pages |
| 90 | + url: ${{ steps.deployment.outputs.page_url }} |
| 91 | + runs-on: ubuntu-latest |
| 92 | + needs: build |
| 93 | + steps: |
| 94 | + - name: Deploy to GitHub Pages |
| 95 | + id: deployment |
| 96 | + uses: actions/deploy-pages@v1 |
0 commit comments