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 diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 028b4c8e3..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,17 +152,19 @@ 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 - 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 +178,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 @@ -269,3 +275,25 @@ 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: "Checkout" + uses: actions/checkout@v4 + - 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 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,