From 219073c7617e56bca31a8f61b3624d8898b72e9f Mon Sep 17 00:00:00 2001 From: Mark Higham Date: Mon, 9 Feb 2026 16:45:44 +0000 Subject: [PATCH] build(Hosting): Migrate from Netlify to GitHub Pages - Add GitHub Pages deployment workflow with manual trigger support - Add CNAME for custom domain (docs.design-system.navy.digital.mod.uk) - Add static export script to package.json - Configure Next.js with unoptimized images for static export - Remove Netlify configuration and branch deploy preview workflow Co-Authored-By: Claude Opus 4.5 --- .github/workflows/branch_deploy.yml | 54 --------------------------- .github/workflows/build_and_test.yml | 20 +++++----- .github/workflows/deploy-gh-pages.yml | 48 ++++++++++++++++++++++++ netlify.toml | 21 ----------- next.config.js | 3 ++ package.json | 1 + public/CNAME | 1 + 7 files changed, 63 insertions(+), 85 deletions(-) delete mode 100644 .github/workflows/branch_deploy.yml create mode 100644 .github/workflows/deploy-gh-pages.yml delete mode 100644 netlify.toml create mode 100644 public/CNAME diff --git a/.github/workflows/branch_deploy.yml b/.github/workflows/branch_deploy.yml deleted file mode 100644 index b31c142b..00000000 --- a/.github/workflows/branch_deploy.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: Branch deploy preview - -on: - workflow_dispatch: - inputs: - preview_branch: - description: 'Enter the branch name you wish to preview' - required: true - -jobs: - branch_deploy_preview: - runs-on: ubuntu-latest - env: - PREVIEW_URL: https://deploy-preview--peaceful-wiles-97aae8.netlify.app - steps: - - name: Git clone repository - uses: actions/checkout@v4 - - - name: Fetch all commits - run: git fetch --all - - - name: Remove deploy preview branch if it exists - run: | - result=$((git branch --all) 2>&1) - if [[ `echo $result` == *"deploy/preview"* ]]; - then - git push origin --delete deploy/preview; - else - echo "deploy/preview branch does not exist"; - fi - - - name: Checkout preview branch - run: | - git checkout ${{ github.event.inputs.preview_branch }} - git fetch - git checkout -b deploy/preview - git fetch - - - name: Merge into deploy/preview branch - run: | - git merge ${{ github.event.inputs.preview_branch }} - - - name: Push deploy_preview branch - run: | - git push origin deploy/preview - - - name: Deploy preview branch - run: | - curl -X POST -d {} ${{ secrets.BRANCH_DEPLOY_TOKEN }} - - - name: Check deployment - run: | - timeout 900 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' ${PREVIEW_URL})" != "200" ]]; do sleep 30; done' || false - echo "The branch is deployed & ready to preview - ${PREVIEW_URL}" diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index 14c097c3..f26a2844 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -13,7 +13,7 @@ jobs: if: ${{ github.event_name == 'pull_request' }} steps: - name: Git clone repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up environment uses: ./.github/actions/prepare-environment @@ -32,7 +32,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Git clone repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up environment uses: ./.github/actions/prepare-environment @@ -46,7 +46,7 @@ jobs: ESLINT_JUNIT_OUTPUT: 'test-results/eslint/docs-site-results.xml' steps: - name: Git clone repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up environment uses: ./.github/actions/prepare-environment @@ -63,7 +63,7 @@ jobs: if: ${{ github.actor != 'dependabot[bot]' }} steps: - name: Git clone repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up environment uses: ./.github/actions/prepare-environment @@ -87,11 +87,11 @@ jobs: run: | pnpm run test --ci --coverage --silent --no-cache --reporters=default --reporters=jest-junit --runInBand --testResultsProcessor=jest-sonar-reporter - - name: SonarCloud Scan - uses: defencedigital/design-system-sonarcloud-action@master - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + # - name: SonarCloud Scan + # uses: defencedigital/design-system-sonarcloud-action@master + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + # SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} Test-e2e_docs-site: runs-on: ubuntu-latest @@ -103,7 +103,7 @@ jobs: NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN }} steps: - name: Git clone repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 - name: Set up environment uses: ./.github/actions/prepare-environment diff --git a/.github/workflows/deploy-gh-pages.yml b/.github/workflows/deploy-gh-pages.yml new file mode 100644 index 00000000..34a2f600 --- /dev/null +++ b/.github/workflows/deploy-gh-pages.yml @@ -0,0 +1,48 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: + - master + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: pages + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up environment + uses: ./.github/actions/prepare-environment + + - name: Build and export site + env: + NEXT_PUBLIC_CONTENTFUL_SPACE_ID: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_SPACE_ID }} + NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN: ${{ secrets.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN }} + run: pnpm export + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./out + + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/netlify.toml b/netlify.toml deleted file mode 100644 index ab9af28e..00000000 --- a/netlify.toml +++ /dev/null @@ -1,21 +0,0 @@ -# example netlify.toml -[build] - command = "next build" - functions = "netlify/functions" - publish = ".next" - - ## Uncomment to use this redirect for Single Page Applications like create-react-app. - ## Not needed for static site generators. - #[[redirects]] - # from = "/*" - # to = "/index.html" - # status = 200 - - ## (optional) Settings for Netlify Dev - ## https://github.com/netlify/cli/blob/main/docs/netlify-dev.md#project-detection - #[dev] - # command = "yarn start" # Command to start your dev server - # port = 3000 # Port that the dev server will be listening on - # publish = "dist" # Folder with the static content for _redirect file - - ## more info on configuring this file: https://www.netlify.com/docs/netlify-toml-reference/ diff --git a/next.config.js b/next.config.js index 3c6166eb..2dcf2cfd 100644 --- a/next.config.js +++ b/next.config.js @@ -3,6 +3,9 @@ const withTM = require('next-transpile-modules')([ ]) module.exports = withTM({ + images: { + unoptimized: true, + }, webpack(config) { config.module.rules.push({ test: /\.svg$/i, diff --git a/package.json b/package.json index 1fe63de4..616cb26f 100644 --- a/package.json +++ b/package.json @@ -6,6 +6,7 @@ "scripts": { "dev": "next dev", "build": "next build", + "export": "next build && next export", "start": "next start", "lint": "eslint . --ext .ts --ext .tsx", "lint:ci": "eslint -f ./node_modules/eslint-junit/index.js . --ext .ts --ext .tsx", diff --git a/public/CNAME b/public/CNAME new file mode 100644 index 00000000..7b06b4d6 --- /dev/null +++ b/public/CNAME @@ -0,0 +1 @@ +docs.design-system.navy.digital.mod.uk