From eaee489df4b5d1279e5086400f6fc937424d24fc Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Sun, 4 May 2025 15:15:17 +0200 Subject: [PATCH 1/5] Try preview deployment with action Potential todo: Add action that removes deployments on PR closure --- .github/workflows/web.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 028b4c8e3..0fc75285d 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -269,3 +269,23 @@ jobs: git tag "web-${version}" git push origin "web-${version}" + + deploy-preview: + name: "Deploy PR Preview" + if: github.event_name == 'pull_request' + needs: [ build-web ] + runs-on: ubuntu-22.04 + permissions: + contents: write + pull-requests: write + steps: + - name: "Download build artifacts" + uses: actions/download-artifact@v4 + with: + name: "out" # Must match the artifact name from build-web + path: "preview-build" + - name: "Deploy PR Preview to GitHub Pages" + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: "preview-build" # Must match path from download-artifact + preview-branch: "gh-pages" \ No newline at end of file From cb9c2ad3c77fb2c1c0423fdc7b6336e1c5b7513e Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Sun, 4 May 2025 15:28:24 +0200 Subject: [PATCH 2/5] Faster testing --- .github/workflows/web.yml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 0fc75285d..f1f5f9a0f 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -149,16 +149,16 @@ jobs: sed -i -e "s|FULL_DOMAIN=autodetect|FULL_DOMAIN=${FULL_DOMAIN}|g" .env sed -i -e "s|DATA_FULL_DOMAIN=https://data.master.clades.nextstrain.org/v3|DATA_FULL_DOMAIN=${DATA_FULL_DOMAIN}|g" .env - - name: "Login to Docker Hub" - uses: docker/login-action@v3 - with: - registry: docker.io - username: nextstrainbot - password: ${{ secrets.DOCKER_TOKEN }} + # - name: "Login to Docker Hub" + # uses: docker/login-action@v3 + # with: + # registry: docker.io + # username: nextstrainbot + # password: ${{ secrets.DOCKER_TOKEN }} - - name: "Build docker image" - run: | - CROSS="wasm32-unknown-unknown" ./docker/dev docker-image-build-push + # - name: "Build docker image" + # run: | + # CROSS="wasm32-unknown-unknown" ./docker/dev docker-image-build-push - name: "Install Node.js packages" run: | @@ -172,13 +172,13 @@ jobs: run: | ./docker/dev web-release - - name: "Lint web app code" - run: | - ./docker/dev web yarn lint:ci + # - name: "Lint web app code" + # run: | + # ./docker/dev web yarn lint:ci - - name: "Lint Rust code" - run: | - ./docker/dev lint-ci + # - name: "Lint Rust code" + # run: | + # ./docker/dev lint-ci - name: "Upload build artifacts" uses: actions/upload-artifact@v4 From aadbdbea80d4b2ab9809ff1fed2408ea959731ae Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Sun, 4 May 2025 15:48:45 +0200 Subject: [PATCH 3/5] Checkout code first --- .github/workflows/web.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index f1f5f9a0f..055758034 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -279,6 +279,8 @@ jobs: contents: write pull-requests: write steps: + - name: "Checkout" + uses: actions/checkout@v4 - name: "Download build artifacts" uses: actions/download-artifact@v4 with: From 74cccc3180d3581959d5a11189cfe3a3b3342673 Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Sun, 4 May 2025 16:28:29 +0200 Subject: [PATCH 4/5] Try setting basePath --- .github/workflows/web.yml | 6 ++++++ packages/nextclade-web/config/next/next.config.ts | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 055758034..c0824fb3c 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -102,6 +102,10 @@ jobs: fetch-depth: 1 submodules: true + - name: "Set PR_NUMBER for preview builds" + if: github.event_name == 'pull_request' + run: echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV + - name: "Get docker build checksum" id: docker-build-checksum run: echo "checksum=$(./scripts/docker_build_checksum.sh)" >> $GITHUB_OUTPUT @@ -148,6 +152,8 @@ jobs: cp .env.example .env sed -i -e "s|FULL_DOMAIN=autodetect|FULL_DOMAIN=${FULL_DOMAIN}|g" .env sed -i -e "s|DATA_FULL_DOMAIN=https://data.master.clades.nextstrain.org/v3|DATA_FULL_DOMAIN=${DATA_FULL_DOMAIN}|g" .env + # include PR_NUMBER for preview builds in .env + if [ -n "${PR_NUMBER:-}" ]; then echo "PR_NUMBER=${PR_NUMBER}" >> .env; fi # - name: "Login to Docker Hub" # uses: docker/login-action@v3 diff --git a/packages/nextclade-web/config/next/next.config.ts b/packages/nextclade-web/config/next/next.config.ts index 22cd557fa..656fd0827 100644 --- a/packages/nextclade-web/config/next/next.config.ts +++ b/packages/nextclade-web/config/next/next.config.ts @@ -66,7 +66,16 @@ const clientEnv = { BLOCK_SEARCH_INDEXING: DOMAIN === RELEASE_URL ? '0' : '1', } +// use PR_NUMBER from GitHub Actions for preview deployments +const { PR_NUMBER } = process.env +const previewNumber = PR_NUMBER +const basePath = previewNumber ? `/nextclade/pr-preview/pr-${previewNumber}` : '' +const assetPrefix = basePath || undefined + const nextConfig: NextConfig = { + // use dynamic basePath on preview + basePath, + assetPrefix, distDir: `.build/${process.env.NODE_ENV}/tmp`, pageExtensions: ['js', 'jsx', 'ts', 'tsx', 'md', 'mdx', 'all-contributorsrc'], onDemandEntries: { @@ -79,6 +88,7 @@ const nextConfig: NextConfig = { experimental: { reactRoot: true, scrollRestoration: true, + esmExternals: 'loose', }, swcMinify: true, productionBrowserSourceMaps: ENABLE_SOURCE_MAPS, From c03d72f310b25bd9e58455ec8662b394608a20f0 Mon Sep 17 00:00:00 2001 From: Cornelius Roemer Date: Mon, 5 May 2025 18:47:09 +0200 Subject: [PATCH 5/5] Remove pr previews when closed --- .github/workflows/remove-preview.yml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 .github/workflows/remove-preview.yml diff --git a/.github/workflows/remove-preview.yml b/.github/workflows/remove-preview.yml new file mode 100644 index 000000000..eb7e2db90 --- /dev/null +++ b/.github/workflows/remove-preview.yml @@ -0,0 +1,16 @@ +name: Deploy PR previews +concurrency: preview-${{ github.ref }} +on: + pull_request: + types: + - closed +jobs: + deploy-preview: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: rossjrw/pr-preview-action@v1 + with: + source-dir: "preview-build" + preview-branch: "gh-pages" + action: remove \ No newline at end of file