A personal website for self-learning interest. We host our website in 2 locations:
flowchart LR;
vercel[NextJS in Vercel] --> github[Static in Github pages];
In your terminal, run the following command:
For local execution:
npm run dev
For test with watch
npm run test
For test coverage
npm run test:ci
For linting and prettifier check
npm run lint
For package analysing, do not check-in as it contains alot of security issues.
npm install @next/bundle-analyzer
# Wrap next.config.js with withBundleAnalyzer({...})
npx next build
For BackstopJS - regression for view and approve website design UI Note: that browser executes differently in OS, especially font's. In this case use the approved generated backstopJS snapshots directly from the OS/Docker container.
npm run backstop:test //To test
npm run backstop:approve // Approve the new website ok
To stop animation, append query string to use animate-none
class
?animate=none
- Install Vercel Cli, with
npm i -g vercel
- Pull all the environment into local with
vercel env pull .env.local
. This wil create an environment straight for testing. Incase, there are reset of environment to setup in Vercel, refer to .env file.
- CORS_ALLOW_ORIGIN - for whitelisting /api url defined in next.config.js to external apps.
- NEXT_PUBLIC_SITE_URL - configure for static site to call api. Overrides blank with https://www.walcron.com.
- NEXT_PUBLIC_API_SITE_URL - Indicate local api is url.
- NEXT_PUBLIC_GA_4_ID - Google 4 Tag Manager Ids
flowchart TD;
branch["branch w/ (Non-spaced and lowercased)"] --> commit --> push --> pull[pull request] --> workflow["workflow w/ success"] --> merge --> report["Generate Reports"];
push --> deploy1["Vercel in Development Environment"]
merge --> promote["Promote Vercel"];
report --> deploy2["Github Pages"] --> tag --> smoketest["Smoke test"];
report --> sonar["SonarQube Cloud scan"]
In case there is a need to generate a new backstopJS approved page.
- In github, go to Actions tab.
- Select 'Create Approved Snapshot By File'.
- Click on 'Run workflow'
- Enter the vercel/public website to generate an approved website domain. Without http, e.g. https://www.walcron.com to www.walcron.com
- Manually enter a valid branch it can checkout, e.g. develop.
Updating backstopJS snapshot.
--By pull request / action
- Download the artifacts generated in "Summary" of the latest build. Replace generated snapshot in backstopdata/bitmaps_test//!failed_.png
- replace into bitmaps_reference.
--Auto approval (Recommended)
- Get the latest pipeline no from snapshotcheck.sh output from previous failed Validation workflow.
- OR view latest running script in github's Actions tab for Validation workflow.
- Execute the command below and it will auto-approve and rerun Validation workflow again.
echo ${running no# +1} > backstopjs.approve
git add backstopjs.approve
git push
Note: Add create PAT, personal profile -> Developer Settings -> Fine Grain Token -> Actions(R)/Commit Statues(RW)/Contents(RW)/Metadata(R)
- Required an NPM token for private repository. See "Deployment for Github NPM_TOKEN for private repo"
- Login locally into github NPM repo with the PAT.
npm login --scope=@yoonghan --auth-type=legacy --registry=https://npm.pkg.github.com/
- Copy in ~/.npmrc into vercel's variable NPM_RC. Basically the variable will contain:
//npm.pkg.github.com/:_authToken=...
@yoonghan:registry=https://npm.pkg.github.com/
- For accessing private repo, please allow Profile -> Settings -> Personal Access Token (classic), open read:packages (basically the same as vercel deployment). For more info refer: https://docs.github.com/en/packages/working-with-a-github-packages-registry. Add as Github secret in Settings->Secrets And variable and add NPM_TOKEN key. NOTE: During npm install NODE_AUTH_TOKEN variable is read instead.
- Workflow requires
- registry-url in checkout action,
- NODE_AUTH_TOKEN env. If the workflow is callable, use "secrets: inherit", else secret cannot be shown. To test print with
echo ${#NODE_AUTH_TOKEN}
and should return some integer values. - Same/extra NPM_TOKEN needs to be created for dependabot under Profile -> Security -> Dependabot.
- NextJS on vercel re-uses .next build cache. This sometimes creates an issue, e.g. a page that was once deployed as AMP will forever be recognized as AMP until the cache is cleared.
- To build without previous build cache; click redeploy button from Vercel dashboard (a menu from the 3 vertical dots) and uncheck "Build with previous build cache".
NextJS for static generation output: "export"
in next.config.js
, requires all pages to have removed "use server"
. Generally all pages that requires /api call needs to be removed as well.
Process.env variable for client side access are required to be defined in .env file (written in merge.yml)
Key | Description |
---|---|
NEXT_PUBLIC_PUSHER_APP_KEY | Public key for pusher API to access pusher |
NEXT_PUBLIC_PUSHER_CLUSTER | Public pusher API cluster region |
NEXT_PUBLIC_SITE_URL | URL to hosted url for content metadata (i.e. canonical) |
NEXT_PUBLIC_API_SITE_URL | URL to hosted api url, i.e. https://www.walcron.com/api |
- To regenerate new Wasm from webassembly, run the command below:
- The scripts include a custom .gitignore.
- Incase wanted to run rust:test, remove --headless and browse with https://localhost:8000. Failed to run it in MacOS.
npm run rust:generate
npm run rust:test //test rust running on browser
- Set variables configured in axiom to view telemetry AXIOM_API_TOKEN and AXIOM_DATASET_NAME.
- To show open telemetry logs, run OTEL_LOG_LEVEL=debug.