Skip to content

Commit

Permalink
chore: test PR pipeline (#21)
Browse files Browse the repository at this point in the history
* test pipeline

* add id to install step

* wip

* upload renderer and kernel

* enable branch testing

* fix renderer branch

* prevent comment flood

* normalize renderer-urn -> renderer

* use new cdn

* Update main.yml

* npm with cache
  • Loading branch information
menduz authored Jul 26, 2021
1 parent 4fc506e commit c4b9f8f
Show file tree
Hide file tree
Showing 8 changed files with 191 additions and 25 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/deploy-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
on:
pull_request:

name: Pull request
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Use Node.js 14.x
uses: actions/setup-node@v2
with:
node-version: 14.x
cache: npm

- id: install
name: install
run: npm ci

- name: build
run: npm run build
- name: test
run: npm run test

- name: deploy preview
env:
AWS_DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
EXPLORER_WEB_BUCKET: ${{ secrets.EXPLORER_WEB_BUCKET }}
if: ${{ steps.install.outputs.public_path }}
run: |
npx @dcl/cdn-uploader@next \
--bucket $EXPLORER_WEB_BUCKET \
--local-folder build \
--bucket-folder "${{ steps.install.outputs.public_path }}"
- name: Find Comment
uses: peter-evans/find-comment@v1
id: fc
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Test this pull request

- name: Create or update comment
uses: peter-evans/create-or-update-comment@v1
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ github.event.pull_request.number }}
body: |
# Test this pull request
This branch can be previewed at ${{ steps.install.outputs.public_url }}
edit-mode: replace
19 changes: 17 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,35 @@ jobs:
steps:
- uses: actions/checkout@master
- name: Use Node.js 14.x
uses: actions/setup-node@v1
uses: actions/setup-node@v2
with:
node-version: 14.x
cache: npm

- name: set package.json version
uses: menduz/oddish-action@master
with:
deterministic-snapshot: true
only-update-versions: true

- name: install
run: npm ci

- name: build
run: npm run build
- name: test
run: npm run test
- name: Publish

- name: publish npm package
uses: menduz/oddish-action@master
with:
registry-url: "https://registry.npmjs.org"
access: public
cwd: ./build
## use action runId instead of current date to generate snapshot numbers
deterministic-snapshot: true
## inform gitlab after publishing to proceed with CDN propagation
gitlab-token: ${{ secrets.GITLAB_TOKEN }}
gitlab-pipeline-url: ${{ secrets.GITLAB_URL }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
12 changes: 11 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "decentraland-explorer-website",
"name": "@dcl/explorer-website",
"version": "0.0.1",
"private": true,
"scripts": {
Expand Down Expand Up @@ -34,8 +34,10 @@
]
},
"dependencies": {
"@dcl/feature-flags": "^1.0.0",
"@dcl/kernel-interface": "^1.0.0-20210722175856.commit-173aa62",
"@dcl/unity-renderer": "^1.0.7377",
"@dcl/urn-resolver": "^1.2.1",
"decentraland-dapps": "^9.7.1",
"decentraland-kernel": "^6.6.6-20210705191533.commit-894f7d2",
"eth-connect": "^6.0.0",
Expand Down Expand Up @@ -69,5 +71,6 @@
"react-test-renderer": "^16.13.1",
"redux-devtools-extension": "^2.13.8",
"typescript": "~3.7.2"
}
},
"homepage": "http://localhost:3000"
}
10 changes: 1 addition & 9 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,7 @@
}
</style>
<script>
var RENDERER_ARTIFACTS_ROOT = '/cdn/packages/unity-renderer/%REACT_APP_KERNEL_VERSION%/'
var KERNEL_ROOT = '/cdn/packages/decentraland-kernel/%REACT_APP_RENDERER_VERSION%/'
window.VERSION = '%REACT_APP_WEBSITE_VERSION%'
console.log('Versions', {
website: '%REACT_APP_WEBSITE_VERSION%',
renderer: '%REACT_APP_RENDERER_VERSION%',
kernel: '%REACT_APP_KERNEL_VERSION%'
})
</script>
</head>
<body class="dcl-loading">
Expand Down Expand Up @@ -157,7 +150,7 @@
<link rel="stylesheet" href="css/errors.css" />
</noscript>
<!-- google -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-63691338-5"></script>
<script crossorigin async src="https://www.googletagmanager.com/gtag/js?id=UA-63691338-5"></script>
<script>
window.dataLayer = window.dataLayer || []

Expand Down Expand Up @@ -194,6 +187,5 @@
!function(r){var e={};function o(n){if(e[n])return e[n].exports;var t=e[n]={i:n,l:!1,exports:{}};return r[n].call(t.exports,t,t.exports,o),t.l=!0,t.exports}o.m=r,o.c=e,o.d=function(r,e,n){o.o(r,e)||Object.defineProperty(r,e,{enumerable:!0,get:n})},o.r=function(r){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(r,"__esModule",{value:!0})},o.t=function(r,e){if(1&e&&(r=o(r)),8&e)return r;if(4&e&&"object"==typeof r&&r&&r.__esModule)return r;var n=Object.create(null);if(o.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:r}),2&e&&"string"!=typeof r)for(var t in r)o.d(n,t,function(e){return r[e]}.bind(null,t));return n},o.n=function(r){var e=r&&r.__esModule?function(){return r.default}:function(){return r};return o.d(e,"a",e),e},o.o=function(r,e){return Object.prototype.hasOwnProperty.call(r,e)},o.p="",o(o.s=0)}([function(r,e,o){"use strict";var n=o(1),t=o(5);_rollbarConfig=_rollbarConfig||{},_rollbarConfig.rollbarJsUrl=_rollbarConfig.rollbarJsUrl||"https://cdn.rollbar.com/rollbarjs/refs/tags/v2.19.4/rollbar.min.js",_rollbarConfig.async=void 0===_rollbarConfig.async||_rollbarConfig.async;var a=n.setupShim(window,_rollbarConfig),l=t(_rollbarConfig);window.rollbar=n.Rollbar,a.loadFull(window,document,!_rollbarConfig.async,_rollbarConfig,l)},function(r,e,o){"use strict";var n=o(2),t=o(3);function a(r){return function(){try{return r.apply(this,arguments)}catch(r){try{console.error("[Rollbar]: Internal error",r)}catch(r){}}}}var l=0;function i(r,e){this.options=r,this._rollbarOldOnError=null;var o=l++;this.shimId=function(){return o},"undefined"!=typeof window&&window._rollbarShims&&(window._rollbarShims[o]={handler:e,messages:[]})}var s=o(4),d=function(r,e){return new i(r,e)},c=function(r){return new s(d,r)};function u(r){return a((function(){var e=this,o=Array.prototype.slice.call(arguments,0),n={shim:e,method:r,args:o,ts:new Date};window._rollbarShims[this.shimId()].messages.push(n)}))}i.prototype.loadFull=function(r,e,o,n,t){var l=!1,i=e.createElement("script"),s=e.getElementsByTagName("script")[0],d=s.parentNode;i.crossOrigin="",i.src=n.rollbarJsUrl,o||(i.async=!0),i.onload=i.onreadystatechange=a((function(){if(!(l||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState)){i.onload=i.onreadystatechange=null;try{d.removeChild(i)}catch(r){}l=!0,function(){var e;if(void 0===r._rollbarDidLoad){e=new Error("rollbar.js did not load");for(var o,n,a,l,i=0;o=r._rollbarShims[i++];)for(o=o.messages||[];n=o.shift();)for(a=n.args||[],i=0;i<a.length;++i)if("function"==typeof(l=a[i])){l(e);break}}"function"==typeof t&&t(e)}()}})),d.insertBefore(i,s)},i.prototype.wrap=function(r,e,o){try{var n;if(n="function"==typeof e?e:function(){return e||{}},"function"!=typeof r)return r;if(r._isWrap)return r;if(!r._rollbar_wrapped&&(r._rollbar_wrapped=function(){o&&"function"==typeof o&&o.apply(this,arguments);try{return r.apply(this,arguments)}catch(o){var e=o;throw e&&("string"==typeof e&&(e=new String(e)),e._rollbarContext=n()||{},e._rollbarContext._wrappedSource=r.toString(),window._rollbarWrappedError=e),e}},r._rollbar_wrapped._isWrap=!0,r.hasOwnProperty))for(var t in r)r.hasOwnProperty(t)&&(r._rollbar_wrapped[t]=r[t]);return r._rollbar_wrapped}catch(e){return r}};for(var p="log,debug,info,warn,warning,error,critical,global,configure,handleUncaughtException,handleAnonymousErrors,handleUnhandledRejection,captureEvent,captureDomContentLoaded,captureLoad".split(","),f=0;f<p.length;++f)i.prototype[p[f]]=u(p[f]);r.exports={setupShim:function(r,e){if(r){var o=e.globalAlias||"Rollbar";if("object"==typeof r[o])return r[o];r._rollbarShims={},r._rollbarWrappedError=null;var l=new c(e);return a((function(){e.captureUncaught&&(l._rollbarOldOnError=r.onerror,n.captureUncaughtExceptions(r,l,!0),e.wrapGlobalEventHandlers&&t(r,l,!0)),e.captureUnhandledRejections&&n.captureUnhandledRejections(r,l,!0);var a=e.autoInstrument;return!1!==e.enabled&&(void 0===a||!0===a||"object"==typeof a&&a.network)&&r.addEventListener&&(r.addEventListener("load",l.captureLoad.bind(l)),r.addEventListener("DOMContentLoaded",l.captureDomContentLoaded.bind(l))),r[o]=l,l}))()}},Rollbar:c}},function(r,e,o){"use strict";function n(r,e,o,n){r._rollbarWrappedError&&(n[4]||(n[4]=r._rollbarWrappedError),n[5]||(n[5]=r._rollbarWrappedError._rollbarContext),r._rollbarWrappedError=null);var t=e.handleUncaughtException.apply(e,n);o&&o.apply(r,n),"anonymous"===t&&(e.anonymousErrorsPending+=1)}r.exports={captureUncaughtExceptions:function(r,e,o){if(r){var t;if("function"==typeof e._rollbarOldOnError)t=e._rollbarOldOnError;else if(r.onerror){for(t=r.onerror;t._rollbarOldOnError;)t=t._rollbarOldOnError;e._rollbarOldOnError=t}e.handleAnonymousErrors();var a=function(){var o=Array.prototype.slice.call(arguments,0);n(r,e,t,o)};o&&(a._rollbarOldOnError=t),r.onerror=a}},captureUnhandledRejections:function(r,e,o){if(r){"function"==typeof r._rollbarURH&&r._rollbarURH.belongsToShim&&r.removeEventListener("unhandledrejection",r._rollbarURH);var n=function(r){var o,n,t;try{o=r.reason}catch(r){o=void 0}try{n=r.promise}catch(r){n="[unhandledrejection] error getting `promise` from event"}try{t=r.detail,!o&&t&&(o=t.reason,n=t.promise)}catch(r){}o||(o="[unhandledrejection] error getting `reason` from event"),e&&e.handleUnhandledRejection&&e.handleUnhandledRejection(o,n)};n.belongsToShim=o,r._rollbarURH=n,r.addEventListener("unhandledrejection",n)}}}},function(r,e,o){"use strict";function n(r,e,o){if(e.hasOwnProperty&&e.hasOwnProperty("addEventListener")){for(var n=e.addEventListener;n._rollbarOldAdd&&n.belongsToShim;)n=n._rollbarOldAdd;var t=function(e,o,t){n.call(this,e,r.wrap(o),t)};t._rollbarOldAdd=n,t.belongsToShim=o,e.addEventListener=t;for(var a=e.removeEventListener;a._rollbarOldRemove&&a.belongsToShim;)a=a._rollbarOldRemove;var l=function(r,e,o){a.call(this,r,e&&e._rollbar_wrapped||e,o)};l._rollbarOldRemove=a,l.belongsToShim=o,e.removeEventListener=l}}r.exports=function(r,e,o){if(r){var t,a,l="EventTarget,Window,Node,ApplicationCache,AudioTrackList,ChannelMergerNode,CryptoOperation,EventSource,FileReader,HTMLUnknownElement,IDBDatabase,IDBRequest,IDBTransaction,KeyOperation,MediaController,MessagePort,ModalWindow,Notification,SVGElementInstance,Screen,TextTrack,TextTrackCue,TextTrackList,WebSocket,WebSocketWorker,Worker,XMLHttpRequest,XMLHttpRequestEventTarget,XMLHttpRequestUpload".split(",");for(t=0;t<l.length;++t)r[a=l[t]]&&r[a].prototype&&n(e,r[a].prototype,o)}}},function(r,e,o){"use strict";function n(r,e){this.impl=r(e,this),this.options=e,function(r){for(var e=function(r){return function(){var e=Array.prototype.slice.call(arguments,0);if(this.impl[r])return this.impl[r].apply(this.impl,e)}},o="log,debug,info,warn,warning,error,critical,global,configure,handleUncaughtException,handleAnonymousErrors,handleUnhandledRejection,_createItem,wrap,loadFull,shimId,captureEvent,captureDomContentLoaded,captureLoad".split(","),n=0;n<o.length;n++)r[o[n]]=e(o[n])}(n.prototype)}n.prototype._swapAndProcessMessages=function(r,e){var o,n,t;for(this.impl=r(this.options);o=e.shift();)n=o.method,t=o.args,this[n]&&"function"==typeof this[n]&&("captureDomContentLoaded"===n||"captureLoad"===n?this[n].apply(this,[t[0],o.ts]):this[n].apply(this,t));return this},r.exports=n},function(r,e,o){"use strict";r.exports=function(r){return function(e){if(!e&&!window._rollbarInitialized){for(var o,n,t=(r=r||{}).globalAlias||"Rollbar",a=window.rollbar,l=function(r){return new a(r)},i=0;o=window._rollbarShims[i++];)n||(n=o.handler),o.handler._swapAndProcessMessages(l,o.messages);window[t]=n,window._rollbarInitialized=!0}}}}]);
// End Rollbar Snippet
</script>

</body>
</html>
4 changes: 2 additions & 2 deletions public/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
"bugs": {
"url": "https://github.com/decentraland/explorer-website/issues"
},
"homepage": "https://github.com/decentraland/explorer-website#readme"
}
"homepage": "http://localhost:3000"
}
46 changes: 42 additions & 4 deletions scripts/hash_generator.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,67 @@
const fs = require('fs')
const path = require('path')
const dotenv = require('dotenv')
const childProcess = require('child_process')

let ENV_CONTENT = {}

if (fs.existsSync('.env')) {
Object.assign(ENV_CONTENT, dotenv.parse(fs.readFileSync('.env')))
}

const commitVersion = childProcess.execSync('git rev-parse HEAD').toString().trim()
const packageJson = JSON.parse(fs.readFileSync('./package.json').toString())
const publicPackageJson = JSON.parse(fs.readFileSync('./public/package.json').toString())

const kernelVersion = JSON.parse(fs.readFileSync(require.resolve('decentraland-kernel/package.json'))).version
const rendererVersion = JSON.parse(fs.readFileSync(require.resolve('@dcl/unity-renderer/package.json'))).version

ENV_CONTENT['KERNEL_PATH'] = path.dirname(require.resolve('decentraland-kernel/package.json'))
ENV_CONTENT['REACT_APP_WEBSITE_VERSION'] = commitVersion
ENV_CONTENT['REACT_APP_WEBSITE_VERSION'] = packageJson.version
ENV_CONTENT['REACT_APP_RENDERER_VERSION'] = rendererVersion
ENV_CONTENT['REACT_APP_KERNEL_VERSION'] = kernelVersion

console.log('VERSIONS:', Object.entries(ENV_CONTENT), '\n')
Object.assign(ENV_CONTENT, getPublicUrls())

packageJson.homepage = ENV_CONTENT['PUBLIC_URL']

// github action outputs. Do not touch.
console.log('::set-output name=public_url::' + packageJson.homepage)
console.log('::set-output name=public_path::' + new URL(packageJson.homepage).pathname)

console.log('VERSIONS: ', Object.entries(ENV_CONTENT), '\n')

fs.writeFileSync(
'.env',
Object.entries(ENV_CONTENT)
.map((e) => e[0] + '=' + JSON.stringify(e[1]))
.join('\n') + '\n'
)

publicPackageJson.homepage = packageJson.homepage
publicPackageJson.version = packageJson.version

fs.writeFileSync('./package.json', JSON.stringify(packageJson, null, 2))
fs.writeFileSync('./public/package.json', JSON.stringify(publicPackageJson, null, 2))

function getPublicUrls() {
if (process.env.GITHUB_BASE_REF) {
// Pull request
return {
PUBLIC_URL: `https://explorer-artifacts.decentraland.org/${packageJson.name}/branch/${process.env.GITHUB_HEAD_REF}`,
REACT_APP_RENDERER_BASE_URL: ``,
REACT_APP_KERNEL_BASE_URL: ``
}
} else if (process.env.CI) {
// master/main branch, also releases
return {
PUBLIC_URL: `https://cdn.decentraland.org/${packageJson.name}/${packageJson.version}`,
REACT_APP_RENDERER_BASE_URL: ``,
REACT_APP_KERNEL_BASE_URL: ``
}
}
// localhost
return {
PUBLIC_URL: `http://localhost:3000`,
REACT_APP_RENDERER_BASE_URL: `/cdn/packages/unity-renderer/${rendererVersion}/`,
REACT_APP_KERNEL_BASE_URL: `/cdn/packages/decentraland-kernel/${kernelVersion}/`
}
}
64 changes: 59 additions & 5 deletions src/kernel-loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import {
} from '../state/actions'
import { store } from '../state/redux'
import { ProviderType } from 'decentraland-connect'
import { FeatureFlagsResult, fetchFlags } from '@dcl/feature-flags'
import { resolveUrlFromUrn } from '@dcl/urn-resolver'

export async function authenticate(providerType: ProviderType | null) {
const provider = await getEthereumProvider(providerType, 1)
const provider = await getEthereumProvider(providerType, 1 /* mainnet */)

const kernel = store.getState().kernel.kernel

Expand All @@ -21,19 +23,71 @@ export async function authenticate(providerType: ProviderType | null) {
kernel.authenticate(provider, providerType == null)
}

declare var KERNEL_ROOT: string
declare var RENDERER_ARTIFACTS_ROOT: string
declare var globalThis: { KERNEL_BASE_URL?: string; RENDERER_BASE_URL?: string }

globalThis.KERNEL_BASE_URL = process.env.REACT_APP_KERNEL_BASE_URL
globalThis.RENDERER_BASE_URL = process.env.REACT_APP_RENDERER_BASE_URL

async function resolveBaseUrl(urn: string): Promise<string> {
if (urn.startsWith('urn:')) {
const t = await resolveUrlFromUrn(urn)
if (t) {
console.log(urn, t)
return (t + '/').replace(/(\/)+$/, '/')
}
throw new Error('Cannot resolve content for URN ' + urn)
}
return (new URL(`${urn}`, global.location.toString()).toString() + '/').replace(/(\/)+$/, '/')
}

async function getVersions(flags: FeatureFlagsResult) {
const qs = new URLSearchParams(document.location.search)

if (qs.has('renderer')) {
globalThis.RENDERER_BASE_URL = qs.get('renderer')!
}

if (qs.has('kernel-urn')) {
globalThis.KERNEL_BASE_URL = qs.get('kernel-urn')!
}

if (qs.has('renderer-branch')) {
globalThis.RENDERER_BASE_URL = `https://renderer-artifacts.decentraland.org/branch/${qs.get('renderer-branch')!}`
}

if (qs.has('kernel-branch')) {
globalThis.KERNEL_BASE_URL = `https://explorer-web.decentraland.io/@dcl/kernel/branch/${qs.get('kernel-branch')!}`
}

if (!globalThis.KERNEL_BASE_URL) {
if (flags.variants['explorer-rollout-kernel-version']) {
const version = flags.variants['explorer-rollout-kernel-version'].name
globalThis.KERNEL_BASE_URL = `urn:decentraland:off-chain:kernel-cdn:${version}`
}
}

if (!globalThis.RENDERER_BASE_URL) {
if (flags.variants['explorer-rollout-unity-renderer-version']) {
const version = flags.variants['explorer-rollout-unity-renderer-version'].name
globalThis.RENDERER_BASE_URL = `urn:decentraland:off-chain:unity-renderer-cdn:${version}`
}
}
}

async function initKernel() {
const container = document.getElementById('gameContainer') as HTMLDivElement

const flags = await fetchFlags({ applicationName: 'explorer' })
console.log('Feature flags', flags)
await getVersions(flags)

const kernel = await injectKernel({
kernelOptions: {
baseUrl: new URL(`${KERNEL_ROOT}`, global.location.toString()).toString()
baseUrl: await resolveBaseUrl(globalThis.KERNEL_BASE_URL || `urn:decentraland:off-chain:kernel-cdn:latest`)
},
rendererOptions: {
container,
baseUrl: new URL(`${RENDERER_ARTIFACTS_ROOT}`, global.location.toString()).toString()
baseUrl: await resolveBaseUrl(globalThis.RENDERER_BASE_URL || `urn:decentraland:off-chain:unity-renderer-cdn:latest`)
}
})

Expand Down

0 comments on commit c4b9f8f

Please sign in to comment.