Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Foundation deployment #40

Merged
merged 15 commits into from
Dec 11, 2023
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
53 changes: 53 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: build

on:
release:
types: [created]
push:
branches:
- "**"

concurrency:
group: ${{ github.workflow }}-${{ startsWith(github.ref, 'refs/tags/v') && 'release' || github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/main' && !startsWith(github.ref, 'refs/tags/v') }}

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: read
env:
AWS_DEFAULT_REGION: eu-west-1
PRODUCTION_CLOUDFRONT_DISTRIBUTION_ID: NOT_YET
STAGING_CLOUDFRONT_DISTRIBUTION_ID: E37K3V5Y65XQIX
REVIEW_CLOUDFRONT_DISTRIBUTION_ID: E3KUGPF02I4CJ4
VITE_FOUNDATION_BUILD: ${{ github.repository_owner == 'microbit-foundation' }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v3
with:
node-version: 20
cache: 'npm'
registry-url: "https://npm.pkg.github.com"
- run: npm ci
- run: npm install --no-save @microbit-foundation/[email protected] @microbit-foundation/[email protected] @microbit-foundation/npm-package-versioner@2
if: github.repository_owner == 'microbit-foundation'
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- run: npx update-ci-version
- run: node ./bin/print-ci-env.cjs >> $GITHUB_ENV
- run: npm run test
- run: npm run check
- run: npx prettier --check src
- run: npm run build
- run: npx website-deploy-aws
if: github.repository_owner == 'microbit-foundation' && (env.STAGE == 'REVIEW' || success())
env:
AWS_ACCESS_KEY_ID: ${{ secrets.WEB_DEPLOY_ML_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEB_DEPLOY_ML_AWS_SECRET_ACCESS_KEY }}
- run: npx invalidate-cloudfront-distribution
if: github.repository_owner == 'microbit-foundation' && (env.STAGE == 'REVIEW' || success())
env:
AWS_ACCESS_KEY_ID: ${{ secrets.WEB_DEPLOY_ML_AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.WEB_DEPLOY_ML_AWS_SECRET_ACCESS_KEY }}
72 changes: 0 additions & 72 deletions .github/workflows/main.yml

This file was deleted.

71 changes: 0 additions & 71 deletions .github/workflows/production.yml

This file was deleted.

22 changes: 0 additions & 22 deletions .github/workflows/test.yml

This file was deleted.

23 changes: 23 additions & 0 deletions bin/print-ci-env.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env node

const ref = process.env.GITHUB_REF;
let stage;
if (ref === 'refs/heads/main') {
stage = 'STAGING';
} else if (ref.startsWith('refs/tags/v')) {
stage = 'PRODUCTION';
} else {
stage = 'REVIEW';
}

process.env.STAGE = stage;
// STAGE must be defined before this is imported
const { bucketName, bucketPrefix } = require('../deployment.cjs');
const baseUrl = !bucketPrefix ? '/' : `/${bucketPrefix}/`;
const fullUrl = `https://${bucketName}${baseUrl}`;

console.log(`STAGE=${stage}`);
console.log(`VITE_STAGE=${stage}`);
console.log(`BASE_URL=${baseUrl}`);
// This can be used for og:url and similar. Not quite right for review domain but we don't really care.
console.log(`VITE_FULL_URL=${fullUrl}`);
50 changes: 50 additions & 0 deletions deployment.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const {
createDeploymentDetailsFromOptions,
} = require('@microbit-foundation/website-deploy-aws-config');

const { s3Config } = createDeploymentDetailsFromOptions({
production: {
bucket: 'ml.microbit.org',
mode: 'root',
allowPrerelease: false,
},
staging: {
bucket: 'stage-ml.microbit.org',
},
review: {
bucket: 'review-ml.microbit.org',
mode: 'branch-prefix',
},
});

module.exports = {
deploymentDir: './dist',
...s3Config,
region: 'eu-west-1',
removeNonexistentObjects: true,
enableS3StaticWebsiteHosting: true,
errorDocumentKey: 'index.html',
redirects: [],
params: {
'**/**.html': {
CacheControl: 'public, max-age=0, must-revalidate',
},
'**/assets/**': { CacheControl: 'public, max-age=31536000, immutable' },
// There's lots in public/ that we'd ideally use the bundler for to improve caching
'css/**': {
CacheControl: 'public, max-age=0, must-revalidate',
},
'firmware/**': {
CacheControl: 'public, max-age=0, must-revalidate',
},
'imgs/**': {
CacheControl: 'public, max-age=0, must-revalidate',
},
'sounds/**': {
CacheControl: 'public, max-age=0, must-revalidate',
},
'webfonts/**': {
CacheControl: 'public, max-age=0, must-revalidate',
},
},
};
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<title>&#65279;</title>

<link rel="icon" type="image/png" href="/imgs/favicon.png" />
<link rel="stylesheet" href="/global.css" />
<link rel="stylesheet" href="/all.min.css" />
<link rel="stylesheet" href="/css/global.css" />
<link rel="stylesheet" href="/css/all.min.css" />

<script
src="https://shared-assets.microbit.org/common/v1/common.js"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 2 additions & 5 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import BottomPanel from './components/bottom/BottomPanel.svelte';
import { t } from './i18n';
import { consent } from './script/stores/complianceStore';
import microbitLogoImage from './imgs/microbit-logo.svg';

ConnectionBehaviours.setInputBehaviour(new InputBehaviour());
ConnectionBehaviours.setOutputBehaviour(new OutputBehaviour());
Expand Down Expand Up @@ -50,11 +51,7 @@

<div class="w-full flex flex-col bg-backgrounddark">
<ControlBar>
<img
class="mr-8"
src="/imgs/microbit-logo.svg"
alt="Micro:bit logo"
width="150px" />
<img class="mr-8" src={microbitLogoImage} alt="Micro:bit logo" width="150px" />
<h1 class="text-xl font-thin whitespace-nowrap">{$t('content.index.title')}</h1>
<div class="flex flex-row basis-full justify-end">
<SelectLanguageControlBarDropdown />
Expand Down
6 changes: 3 additions & 3 deletions src/__tests__/license-identifiers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import 'jest-expect-message';
import * as path from 'path';

// Place files you wish to ignore by name in here
const ignoredFiles: string[] = ['.DS_Store'];
const ignoredFiles: RegExp[] = [/^\.DS_Store$/, /\.(gif|svg|png|jpg|jpeg)$/];
const directoriesToScan = ['./src/', './microbit/v2/source/', './microbit/v1/source/'];

const licenseIdentifierStringSPDX = 'SPDX-License-Identifier:';
Expand All @@ -27,12 +27,12 @@ type DirectoryContents = {
folders: string[];
};

const readDirectory = (directory: string, ignoreList: string[]): DirectoryContents => {
const readDirectory = (directory: string, ignoreList: RegExp[]): DirectoryContents => {
const files: string[] = [];
const folders: string[] = [];
const filesRead = fs.readdirSync(directory);
filesRead.forEach(file => {
if (ignoreList.includes(file)) return;
if (ignoreList.some(ignoreRegExp => ignoreRegExp.test(file))) return;
const fileLocation = path.join(directory, file);
const stats = fs.statSync(fileLocation);
if (stats.isFile()) {
Expand Down
7 changes: 6 additions & 1 deletion src/components/3d-inspector/View3DUtility.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ class Live3DUtility {
resolve(group);
};

this.loader.load('/assets/models/microbit.gltf', onFinished, onProgress, reject);
this.loader.load(
`${import.meta.env.BASE_URL}models/microbit.gltf`,
onFinished,
onProgress,
reject,
);
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConnectionOfflineWarning.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
2 - Set favicon into it as src
3 - Use onerror and onload to determine whether or not it was successfully loaded
*/
const pingDestination = '/imgs/favicon.png';
const pingDestination = import.meta.env.BASE_URL + 'imgs/favicon.png';

const getAnimatedDots = (numOfDots: number) => {
return `•`.repeat(numOfDots);
Expand Down
3 changes: 2 additions & 1 deletion src/components/Gesture.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import ImageSkeleton from './skeletonloading/ImageSkeleton.svelte';
import GestureTilePart from './GestureTilePart.svelte';
import StaticConfiguration from '../StaticConfiguration';
import microbitRecordingGuideImage from '../imgs/microbit_record_guide.svg';
import BaseDialog from './dialogs/BaseDialog.svelte';

export let onNoMicrobitSelect: () => void;
Expand Down Expand Up @@ -313,7 +314,7 @@
<ImageSkeleton
height={95}
width={140}
src="/imgs/microbit_record_guide.svg"
src={microbitRecordingGuideImage}
alt="microbit recording guide" />
</div>
<p class=" text-center absolute w-60px right-23px top-30px">
Expand Down
Loading