Skip to content

Commit

Permalink
Merge pull request #784 from aehrc/issue/692
Browse files Browse the repository at this point in the history
Test github pages deployment #4
  • Loading branch information
fongsean authored May 14, 2024
2 parents 0c2022b + 8f99d9f commit c47dab6
Show file tree
Hide file tree
Showing 7 changed files with 30,836 additions and 14,587 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:

jobs:
build:
name: Deploy to S3
name: Deploy Smart Forms app to S3
runs-on: ubuntu-latest
permissions:
id-token: write
Expand Down Expand Up @@ -41,5 +41,5 @@ jobs:
# npx sentry-cli releases set-commits $VERSION --local --ignore-empty --ignore-missing && \
# npx sentry-cli releases files $VERSION upload-sourcemaps build

- name: Upload benchmark file to S3
- name: Upload static React site to S3
run: aws s3 sync apps/smart-forms-app/dist s3://smart-forms-react-app/
46 changes: 32 additions & 14 deletions .github/workflows/deploy_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,27 @@ on:
push:
# branches: [ "main" ]


permissions:
contents: read
pages: write
id-token: write

jobs:
deploy-docusaurus:
name: Deploy Docusaurus to GitHub Pages
environment:
name: github-pages
url: ${{ steps.build-publish.outputs.page_url }}

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18
cache: npm

- name: Install dependencies
run: npm ci
Expand All @@ -39,15 +42,30 @@ jobs:
uses: actions/deploy-pages@v4


# deploy-storybook:
# environment:
# name: github-pages
# url: ${{ steps.build-publish.outputs.page_url }}
#
# runs-on: ubuntu-latest
# steps:
# - uses: bitovi/github-actions-storybook-to-github-pages@v1.0.3
# with:
# path: packages/smart-forms-renderer/storybook-static
# install_command: npm ci
# build_command: npm run build-storybook -w packages/smart-forms-renderer
deploy-storybook:
name: Deploy Storybook to S3
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18
cache: npm

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::209248795938:role/SmartFormsReactAppDeployment
aws-region: ap-southeast-2

- name: Install dependencies
run: npm ci

- name: Build application
run:
npm run build-storybook -w packages/smart-forms-renderer

- name: Upload static Storybook site to S3
run: aws s3 sync packages/smart-forms-renderer/storybook-static s3://smart-forms-storybook/storybook
110 changes: 110 additions & 0 deletions deployment/cloudfront/SmartFormsRedirectToCorrectRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
function handler(event) {
var request = event.request;
var uri = request.uri;

// Handle ACDC Pilot routes
if (uri.includes('/acdcpilot')) {
if (uri.startsWith('/acdcpilot/fhir/Questionnaire')) {
// Rewrite the URI to the specific S3 object path
request.uri = '/acdcpilot/fhir/Questionnaire.json';
}

return request;
}

// Handle IG routes
if (uri.includes('/ig')) {
// Reroute to smartforms.csiro.au/ig/index.html
if (uri === '/ig/') {
request.uri += 'index.html';
return request;
}

if (uri === '/ig') {
request.uri += '/index.html';
return request;
}

// Append ".html to IG subroutes"
// if(uri.endsWith('.')) {
// request.uri += 'html';
// return request;
// }

// Replace http://example.com/ig/* into http://example.com/ig/*/index.html
if (uri.includes('.')) {
var parts = uri.split('.');
if (parts[parts.length - 1].match(/[0-9]/)) {
if (uri.match(/\/ig\/[a-z0-9]+/i)) {
if (uri.endsWith('/')) {
request.uri += 'redirect.html';
return request;
}

// if uri is /ig/* without a trailing slash
request.uri += '/redirect.html';
return request;
}
}
}

// Replace http://example.com/ig/* into http://example.com/ig/*/index.html
// if (uri.match(/\/ig\/[a-z0-9]+\//i)) {
// request.uri += "index.html";
// return request;
// }

var uriChunks = uri.split('/');
var lastUriChunk = uriChunks[uriChunks.length - 1];
if (!lastUriChunk.includes('.')) {
request.uri += '.html';
return request;
}
}

// Handle Storybook routes
if (uri.includes('/storybook')) {
// Reroute to smartforms.csiro.au/ig/index.html
if (uri === '/storybook/') {
request.uri += 'index.html';
return request;
}

if (uri === '/storybook') {
request.uri = '/redirect.html';
return request;
}

return request;
}

// Handle Forms Server API routes
if (uri.includes('/api')) {
// Remove the /api prefix
if (uri.startsWith('/api/')) {
request.uri = uri.replace('/api', '');
return request;
}

if (uri === '/api') {
request.uri = '/';
return request;
}
}

// Handle EHR Launcher routes
if (uri.includes('/ehr')) {
// Remove the /ehr prefix
if (uri.startsWith('/ehr/')) {
request.uri = uri.replace('/ehr', '');
return request;
}

if (uri === '/ehr') {
request.uri = '/';
return request;
}
}

return request;
}
18 changes: 13 additions & 5 deletions documentation/docusaurus.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ const config: Config = {
items: [
{
type: 'docSidebar',
sidebarId: 'gettingStartedSidebar',
sidebarId: 'tutorialSidebar',
position: 'left',
label: 'Getting Started'
label: 'Documentation'
},
// { to: '/blog', label: 'Blog', position: 'left' },
{
Expand All @@ -82,10 +82,18 @@ const config: Config = {
style: 'dark',
links: [
{
title: 'Docs',
title: 'Documentation',
items: [
{
label: 'Docs',
label: 'Developer Usage',
to: '/docs/intro'
},
{
label: 'Components',
to: '/docs/category/components'
},
{
label: 'Structured Data Capture',
to: '/docs/intro'
}
]
Expand Down Expand Up @@ -138,7 +146,7 @@ const config: Config = {
resolve: {
alias: {
// assuming root node_modules is up from "./packages/<your-docusaurus>
react: path.resolve('../../node_modules/react')
react: path.resolve('../node_modules/react')
}
}
};
Expand Down
Loading

0 comments on commit c47dab6

Please sign in to comment.