Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 5 additions & 26 deletions .github/workflows/publish-gh-pages-hack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,39 +30,18 @@ jobs:
- name: Install deps
run: yarn install --frozen-lockfile

- name: Build next.js (hacky static export)
run: |
export VERCEL_GIT_COMMIT_SHA="$(git rev-parse HEAD)"
export VERCEL_GIT_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
export NEXT_PUBLIC_FAKE_STATIC_EXPORT=true
export NEXT_PUBLIC_FORCE_PROJECT=osmapp.org
export NEXT_PUBLIC_OG_IMAGE_FETCHER_HOST=https://osmapp-preview.vercel.app
yarn build
mkdir public/_next
cp -r .next/static public/_next
#echo -e "User-agent: *\nDisallow: /" > public/robots.txt

yarn start &
sleep 5 # server usually starts in 1 second

curl --cookie "hideHomepage=yes" http://localhost:3000 > public/index.html
curl --cookie "hideHomepage=yes" http://localhost:3000 > public/404.html
for lang in $(node --input-type=module <<<'import { LANGUAGES } from "./src/config.mjs";process.stdout.write(Object.keys(LANGUAGES).join("\n")+"\n");'); do
mkdir public/$lang
curl --cookie "hideHomepage=yes; lang=$lang" http://localhost:3000 > public/$lang/index.html
done;

# cache SSR version of some pages (eg. Prague, english-only)
mkdir -p public/node/1601837931
curl --cookie "hideHomepage=yes" http://localhost:3000/node/1601837931 > public/node/1601837931/index.html
- name: Run hacky-static-export
run: yarn hacky-static-export

- name: Setup Pages
id: pages
uses: actions/configure-pages@v5

- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
path: ./public
path: ./static-export

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ yarn-error.log*
.env.local
.env.sentry-build-plugin
/public/icons-indoor
static-export
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"build": "next build",
"start": "next start",
"dist": "next build && next export -o dist",
"hacky-static-export": "bash scripts/hacky-static-export.sh",
"postinstall": "copyfiles -u 2 node_modules/maplibre-gl-indoorequal/sprite/* public/icons-indoor/"
},
"husky": {
Expand Down
59 changes: 59 additions & 0 deletions scripts/hacky-static-export.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
set -euom pipefail

if lsof -iTCP:3000 -sTCP:LISTEN -t > /dev/null 2>&1; then
echo "Error: port 3000 is already in use." >&2
exit 1
fi

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
OUT="$PROJECT_ROOT/static-export"

cd "$PROJECT_ROOT"

export VERCEL_GIT_COMMIT_SHA="$(git rev-parse HEAD)"
export VERCEL_GIT_COMMIT_MESSAGE="$(git log -1 --pretty=%B)"
export NEXT_PUBLIC_FAKE_STATIC_EXPORT=true
export NEXT_PUBLIC_FORCE_PROJECT=osmapp.org
export NEXT_PUBLIC_OG_IMAGE_FETCHER_HOST=https://osmapp-preview.vercel.app
export NEXT_PUBLIC_API_KEY_MAPTILER=yd6CSMQpAwnAcPVZwWQ6

yarn build

rm -rf "$OUT"
cp -r public "$OUT"
mkdir -p "$OUT/_next"
cp -r .next/static "$OUT/_next"

yarn start > /dev/null 2>&1 &
SERVER_PID=$!
cleanup() { kill -- -"$SERVER_PID" 2>/dev/null || true; } # works thanks to `set -m`
trap cleanup EXIT

for i in $(seq 1 5); do curl -sf localhost:3000/node/6 > /dev/null 2>&1 && break; sleep 5; done

echo "> Checking SSR..."
SSR_HTML="$(curl --silent --fail localhost:3000/node/6 || true)"
if grep -q "Originally Detonátor route (this message used for SSR check)" <<< "$SSR_HTML"; then
echo "SSR OK"
else
echo "SSR FAILED"; exit 1
fi

echo "> Get index.html and 404.html..."
curl -s --cookie "hideHomepage=yes" localhost:3000 > "$OUT/index.html"
curl -s --cookie "hideHomepage=yes" localhost:3000 > "$OUT/404.html"

for lang in $(node --input-type=module <<<'import { LANGUAGES } from "./src/config.mjs"; process.stdout.write(Object.keys(LANGUAGES).join("\n")+"\n");'); do
echo "> Get language $lang..."
mkdir -p "$OUT/$lang"
curl -s --cookie "hideHomepage=yes; lang=$lang" localhost:3000 > "$OUT/$lang/index.html"
done

echo "> Get Prague node page..."
mkdir -p "$OUT/node/1601837931"
curl -s --cookie "hideHomepage=yes" localhost:3000/node/1601837931 > "$OUT/node/1601837931/index.html"

echo ""
echo "Output in: $OUT"
Loading