Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
Merge pull request #4 from dutterbutter/db/fix-logging-release
Browse files Browse the repository at this point in the history
fix: update readme and adjust console logs
  • Loading branch information
dutterbutter authored Sep 26, 2023
2 parents 821d6e5 + bda7c91 commit 1061881
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 13 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This GitHub Action runs the [`era_test_node`](https://github.com/matter-labs/era
- Enable hash resolution.
- Configurable logging options.
- Support for different target architectures.
- Ability to specify the version of `era_test_node`.
- Ability to specify the release tag of `era_test_node`.

## Inputs 🛠

Expand Down Expand Up @@ -107,9 +107,9 @@ Target architecture.
- **Default**: `x86_64-unknown-linux-gnu`
- **Options**: `x86_64-unknown-linux-gnu`, `x86_64-apple-darwin`, `aarch64-apple-darwin`

### `version`
### `releaseTag`

Version of `era_test_node` to use.
Release tag of `era_test_node` to use.

- **Required**: No
- **Default**: `latest`
Expand Down Expand Up @@ -166,7 +166,7 @@ jobs:
log: 'info'
logFilePath: 'era_test_node.log'
target: 'x86_64-unknown-linux-gnu'
version: 'latest'
releaseTag: 'latest'
```
### Upload log file to artifacts
Expand Down Expand Up @@ -204,7 +204,7 @@ jobs:
log: 'info'
logFilePath: 'era_test_node.log'
target: 'x86_64-unknown-linux-gnu'
version: 'latest'
releaseTag: 'latest'

- name: Install Dependencies
run: yarn install
Expand Down Expand Up @@ -251,7 +251,7 @@ jobs:
log: 'info'
logFilePath: 'era_test_node.log'
target: 'x86_64-unknown-linux-gnu'
version: 'latest'
releaseTag: 'latest'
```
## Contributing 🤝
Expand Down
1 change: 1 addition & 0 deletions dist/794.index.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"use strict";exports.id=794,exports.ids=[794],exports.modules={5794:(e,t,n)=>{var a=Object.defineProperty,r=(e,t)=>a(e,"name",{value:t,configurable:!0});n(7561),n(9411);const o=n(6824);n(8849),n(2286),n(5628),n(4492),n(2254),n(7261),n(1041),n(7503);let i=0;const s={START_BOUNDARY:i++,HEADER_FIELD_START:i++,HEADER_FIELD:i++,HEADER_VALUE_START:i++,HEADER_VALUE:i++,HEADER_VALUE_ALMOST_DONE:i++,HEADERS_ALMOST_DONE:i++,PART_DATA_START:i++,PART_DATA:i++,END:i++};let d=1;const E=d,A=d*=2,l=r((e=>32|e),"lower"),h=r((()=>{}),"noop"),D=class{constructor(e){this.index=0,this.flags=0,this.onHeaderEnd=h,this.onHeaderField=h,this.onHeadersEnd=h,this.onHeaderValue=h,this.onPartBegin=h,this.onPartData=h,this.onPartEnd=h,this.boundaryChars={},e="\r\n--"+e;const t=new Uint8Array(e.length);for(let n=0;n<e.length;n++)t[n]=e.charCodeAt(n),this.boundaryChars[t[n]]=!0;this.boundary=t,this.lookbehind=new Uint8Array(this.boundary.length+8),this.state=s.START_BOUNDARY}write(e){let t=0;const n=e.length;let a=this.index,{lookbehind:o,boundary:i,boundaryChars:d,index:h,state:D,flags:c}=this;const T=this.boundary.length,f=T-1,_=e.length;let u,R;const b=r((e=>{this[e+"Mark"]=t}),"mark"),H=r((e=>{delete this[e+"Mark"]}),"clear"),p=r(((e,t,n,a)=>{(void 0===t||t!==n)&&this[e](a&&a.subarray(t,n))}),"callback"),P=r(((n,a)=>{const r=n+"Mark";r in this&&(a?(p(n,this[r],t,e),delete this[r]):(p(n,this[r],e.length,e),this[r]=0))}),"dataCallback");for(t=0;t<n;t++)switch(u=e[t],D){case s.START_BOUNDARY:if(h===i.length-2){if(45===u)c|=A;else if(13!==u)return;h++;break}if(h-1==i.length-2){if(c&A&&45===u)D=s.END,c=0;else{if(c&A||10!==u)return;h=0,p("onPartBegin"),D=s.HEADER_FIELD_START}break}u!==i[h+2]&&(h=-2),u===i[h+2]&&h++;break;case s.HEADER_FIELD_START:D=s.HEADER_FIELD,b("onHeaderField"),h=0;case s.HEADER_FIELD:if(13===u){H("onHeaderField"),D=s.HEADERS_ALMOST_DONE;break}if(h++,45===u)break;if(58===u){if(1===h)return;P("onHeaderField",!0),D=s.HEADER_VALUE_START;break}if(R=l(u),R<97||R>122)return;break;case s.HEADER_VALUE_START:if(32===u)break;b("onHeaderValue"),D=s.HEADER_VALUE;case s.HEADER_VALUE:13===u&&(P("onHeaderValue",!0),p("onHeaderEnd"),D=s.HEADER_VALUE_ALMOST_DONE);break;case s.HEADER_VALUE_ALMOST_DONE:if(10!==u)return;D=s.HEADER_FIELD_START;break;case s.HEADERS_ALMOST_DONE:if(10!==u)return;p("onHeadersEnd"),D=s.PART_DATA_START;break;case s.PART_DATA_START:D=s.PART_DATA,b("onPartData");case s.PART_DATA:if(a=h,0===h){for(t+=f;t<_&&!(e[t]in d);)t+=T;t-=f,u=e[t]}if(h<i.length)i[h]===u?(0===h&&P("onPartData",!0),h++):h=0;else if(h===i.length)h++,13===u?c|=E:45===u?c|=A:h=0;else if(h-1===i.length)if(c&E){if(h=0,10===u){c&=~E,p("onPartEnd"),p("onPartBegin"),D=s.HEADER_FIELD_START;break}}else c&A&&45===u?(p("onPartEnd"),D=s.END,c=0):h=0;if(h>0)o[h-1]=u;else if(a>0){const e=new Uint8Array(o.buffer,o.byteOffset,o.byteLength);p("onPartData",0,a,e),a=0,b("onPartData"),t--}break;case s.END:break;default:throw new Error(`Unexpected state entered: ${D}`)}P("onHeaderField"),P("onHeaderValue"),P("onPartData"),this.index=h,this.state=D,this.flags=c}end(){if(this.state===s.HEADER_FIELD_START&&0===this.index||this.state===s.PART_DATA&&this.index===this.boundary.length)this.onPartEnd();else if(this.state!==s.END)throw new Error("MultipartParser.end(): stream ended unexpectedly")}};r(D,"MultipartParser");let c=D;function T(e){const t=e.match(/\bfilename=("(.*?)"|([^()<>@,;:\\"/[\]?={}\s\t]+))($|;\s)/i);if(!t)return;const n=t[2]||t[3]||"";let a=n.slice(n.lastIndexOf("\\")+1);return a=a.replace(/%22/g,'"'),a=a.replace(/&#(\d{4});/g,((e,t)=>String.fromCharCode(t))),a}async function f(e,t){if(!/multipart/i.test(t))throw new TypeError("Failed to fetch");const n=t.match(/boundary=(?:"([^"]+)"|([^;]+))/i);if(!n)throw new TypeError("no or bad content-type header, no multipart boundary");const a=new c(n[1]||n[2]);let i,s,d,E,A,l;const h=[],D=new o.FormData,f=r((e=>{d+=b.decode(e,{stream:!0})}),"onPartData"),_=r((e=>{h.push(e)}),"appendToFile"),u=r((()=>{const e=new o.File(h,l,{type:A});D.append(E,e)}),"appendFileToFormData"),R=r((()=>{D.append(E,d)}),"appendEntryToFormData"),b=new TextDecoder("utf-8");b.decode(),a.onPartBegin=function(){a.onPartData=f,a.onPartEnd=R,i="",s="",d="",E="",A="",l=null,h.length=0},a.onHeaderField=function(e){i+=b.decode(e,{stream:!0})},a.onHeaderValue=function(e){s+=b.decode(e,{stream:!0})},a.onHeaderEnd=function(){if(s+=b.decode(),i=i.toLowerCase(),"content-disposition"===i){const e=s.match(/\bname=("([^"]*)"|([^()<>@,;:\\"/[\]?={}\s\t]+))/i);e&&(E=e[2]||e[3]||""),l=T(s),l&&(a.onPartData=_,a.onPartEnd=u)}else"content-type"===i&&(A=s);s="",i=""};for await(const t of e)a.write(t);return a.end(),D}r(T,"_fileName"),r(f,"toFormData"),t.toFormData=f}};
3 changes: 2 additions & 1 deletion dist/index.cjs

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions dist/index.cjs.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*!
* mime-db
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015-2022 Douglas Christopher Wilson
* MIT Licensed
*/

/*!
* mime-types
* Copyright(c) 2014 Jonathan Ong
* Copyright(c) 2015 Douglas Christopher Wilson
* MIT Licensed
*/

/*! fetch-blob. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */

/*! formdata-polyfill. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */

/*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> */
40 changes: 34 additions & 6 deletions index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@ const { exec } = require('@actions/exec');
const tc = require('@actions/tool-cache');
const { spawn } = require('child_process');
const { fetch } = require('ofetch');
const axios = require('axios');

const ERA_TEST_NODE_RELEASE_TAG = getInput('releaseTag') || 'latest';
const ERA_TEST_NODE_ARCH = getInput('target') || 'x86_64-unknown-linux-gnu';

async function getDownloadUrl() {
const releaseInfo = await fetch(`https://api.github.com/repos/matter-labs/era-test-node/releases/${ERA_TEST_NODE_RELEASE_TAG}`);
const response = await fetch(`https://api.github.com/repos/matter-labs/era-test-node/releases/${ERA_TEST_NODE_RELEASE_TAG}`);
if (!response.ok) {
throw new Error(`Failed to fetch release info for tag ${ERA_TEST_NODE_RELEASE_TAG}. HTTP Status: ${response.status}`);
}

const releaseInfo = await response.json();

if (!releaseInfo || !releaseInfo.assets || !releaseInfo.assets.length) {
throw new Error(`Release tag ${ERA_TEST_NODE_RELEASE_TAG} not found.`);
throw new Error(`Release assets for tag ${ERA_TEST_NODE_RELEASE_TAG} are not available.`);
}

const assetInfo = releaseInfo.assets.find(asset => asset.name.includes(ERA_TEST_NODE_ARCH));
Expand Down Expand Up @@ -43,7 +50,6 @@ async function run() {
const extractedDir = await tc.extractTar(tarFile);
toolPath = await tc.cacheDir(extractedDir, 'era_test_node', ERA_TEST_NODE_RELEASE_TAG);
}

addPath(toolPath);

await exec('chmod', ['+x', `${toolPath}/era_test_node`]);
Expand Down Expand Up @@ -86,7 +92,7 @@ async function run() {
args.push('run');
}

console.log('About to start era_test_node with args:', args);
console.log('Starting era_test_node with args:', args);

const child = spawn(`${toolPath}/era_test_node`, args, {
detached: true,
Expand All @@ -108,12 +114,34 @@ async function run() {
});

child.unref();

console.log('era_test_node is now be running in the background');
// sanity check
// Adding a timeout to give the node some time to start up before checking
setTimeout(async () => {
if(port && await isNodeRunning(port)) {
console.log(`Confirmed: era_test_node is running on port ${port}`);
} else {
console.error('Health check failed: era_test_node appears to be not running.');
setFailed('Failed to start era_test_node');
}
}, 5000);

} catch (error) {
setFailed(error.message);
}
}

run();

async function isNodeRunning(port) {
try {
const response = await axios.post(`http://localhost:${port}`, {
jsonrpc: "2.0",
id: 1,
method: "eth_blockNumber",
params: []
});
return (response.data && response.data.result !== undefined);
} catch (error) {
return false;
}
}

0 comments on commit 1061881

Please sign in to comment.