From 5f74e91b9e8f61c20fbacb0e4980ae8982354e96 Mon Sep 17 00:00:00 2001 From: M Firhan Azmi Nor Date: Sun, 29 Sep 2024 06:58:58 +0000 Subject: [PATCH] Refactor build workflow to include WASM package upload step and update interceptor artifact path --- .github/workflows/baseline.yml | 23 ----------------- .github/workflows/publish.yml | 26 ------------------- .github/workflows/{build.yml => release.yml} | 27 +++++++++++++++++--- config.json | 3 +++ index.js | 27 ++++++-------------- package.json | 17 +++++++----- 6 files changed, 44 insertions(+), 79 deletions(-) delete mode 100644 .github/workflows/baseline.yml delete mode 100644 .github/workflows/publish.yml rename .github/workflows/{build.yml => release.yml} (73%) create mode 100644 config.json diff --git a/.github/workflows/baseline.yml b/.github/workflows/baseline.yml deleted file mode 100644 index e252e9c..0000000 --- a/.github/workflows/baseline.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: baseline_github_action - -on: - workflow_dispatch: - pull_request: - types: - - opened - - reopened - branches: - - development - - main - -jobs: - Linux_Run_Tests: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: '1.21' - - name: "Echo Hello World" - run: echo "Hello World Hello" diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml deleted file mode 100644 index c9e6019..0000000 --- a/.github/workflows/publish.yml +++ /dev/null @@ -1,26 +0,0 @@ -# This Action Pubhlishes to NPM Automatically. -on: - workflow_dispatch: - push: - branches: main - -jobs: - publish: # Name - runs-on: ubuntu-latest - environment: npm_publishing - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Set Up Node - uses: actions/setup-node@v3 - with: - node-version: "20" - - name: Run Testing - run: npm test - # YOU NEED A BUILD STEP TO POPULATE THE DIST FOLDER! - - name: Publish to NPM - uses: JS-DevTools/npm-publish@v3 - with: - token: ${{ secrets.LAYER8_INTERCEPTOR_MIDDLEWARE_TOKEN }} - registry: https://registry.npmjs.org - access: public \ No newline at end of file diff --git a/.github/workflows/build.yml b/.github/workflows/release.yml similarity index 73% rename from .github/workflows/build.yml rename to .github/workflows/release.yml index 5194ef5..7a62d4e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: Build WASM Package +name: Release on: release: types: @@ -41,7 +41,7 @@ jobs: name: interceptor path: bin/ s3: - name: Upload WASM Package to CDN + name: Upload WASM File to CDN needs: build runs-on: ubuntu-latest steps: @@ -57,5 +57,24 @@ jobs: aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ vars.AWS_REGION }} - name: Upload WASM to S3 - run: aws s3 cp bin/interceptor.wasm.br s3://layer8-interceptor/${{ github.sha }}.wasm.br --content-encoding br --content-type application/wasm - \ No newline at end of file + run: aws s3 cp bin/interceptor.wasm.br s3://layer8-interceptor/${{ github.sha }}.wasm.br --content-encoding br --content-type application/wasm --acl public-read + publish: + name: Publish Node Package + needs: s3 + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + registry-url: https://npm.pkg.github.com/ + - name: Install Utilities + run: apt-get install jq moreutils + - name: Setup WASM Config + run: jq '.wasm_url = "${{vars.CLOUDFRONT_CDN_DOMAIN}}/${{ github.sha }}"' config.json | sponge config.json + - name: Install Dependencies + run: npm install + - name: Publish Package + run: npm publish --access public + \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..1179074 --- /dev/null +++ b/config.json @@ -0,0 +1,3 @@ +{ + "wasm_url": "https://d2063k79vh7a9d.cloudfront.net/b69c8172ef38807dec39fcfd7984b95a1b509c4f.wasm.br" +} \ No newline at end of file diff --git a/index.js b/index.js index 093abed..e71f0c3 100644 --- a/index.js +++ b/index.js @@ -1,22 +1,10 @@ -// IMPORTS -import wasmBin from "./dist/interceptor.json"; -import "./dist/wasm_exec.js"; +import './wasm_exec.js'; +import { wasm_url} from './config.json' -// GLOBALS let l8Ready = false; let callbackObjectArray = []; let layer8; -// UTILITY FUNCS -const decode = (encoded) => { - var str = atob(encoded); - var bytes = new Uint8Array(str.length); - for (var i = 0; i < str.length; i++) { - bytes[i] = str.charCodeAt(i); - } - return bytes.buffer; -}; - function illGetBackToYou(_func_name, _resolve, _reject, _args) { callbackObjectArray.push({ func_name: _func_name, @@ -41,15 +29,16 @@ function triggerCallbacks() { }); } -// MODULE LOAD & INITIAZLIZE -const go = new window.Go(); -const importObject = go.importObject; -WebAssembly.instantiate(decode(wasmBin), importObject).then((result) => { + +const go = new Go(); +WebAssembly.instantiateStreaming(fetch(wasm_url), go.importObject). +then((result) => { go.run(result.instance); l8Ready = true; layer8 = window.layer8; triggerCallbacks(); -}); +}); + // EXPORTS export default { diff --git a/package.json b/package.json index 150b039..6a84c3d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,7 @@ { - "name": "layer8_interceptor", - "version": "0.0.18", + "name": "layer8interceptor", + "version": "0.1.0", + "type": "module", "description": "This package allows Layer8 clients to connect to the remote Layer8 Server. It povides the 1) stock WASM glue code 2) binary of the Interceptor, and 3) the index.js necessary to run it. ", "main": "index.js", "types": "index.d.ts", @@ -26,9 +27,11 @@ }, "homepage": "https://github.com/globe-and-citizen/layer8-interceptor#readme", "files": [ - "./dist/interceptor.json", - "./dist/wasm_exec.js", + "index.js", + "wasm_exec.js", "index.d.ts", - "index.js" - ] -} + "config.json" + ], + "dependencies": { + } +} \ No newline at end of file