Skip to content

Commit 1a7c134

Browse files
add PR comments and test instruction (#128)
* add PR comments and test instruction * add main artifact in readme
1 parent 37b4ccd commit 1a7c134

3 files changed

Lines changed: 80 additions & 1 deletion

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
name: CI
2+
13
on:
24
push:
35
branches:

.github/workflows/pr_comment.yml

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: Comment on pull request
2+
on:
3+
workflow_run:
4+
workflows: [CI]
5+
types: [completed]
6+
jobs:
7+
pr_comment:
8+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/github-script@v6
12+
with:
13+
# This snippet is public-domain, taken from
14+
# https://github.com/oprypin/nightly.link/blob/master/.github/workflows/pr-comment.yml
15+
script: |
16+
async function upsertComment(owner, repo, issue_number, purpose, body) {
17+
const {data: comments} = await github.rest.issues.listComments(
18+
{owner, repo, issue_number});
19+
20+
const marker = `<!-- bot: ${purpose} -->`;
21+
body = marker + "\n" + body;
22+
23+
const existing = comments.filter((c) => c.body.includes(marker));
24+
if (existing.length > 0) {
25+
const last = existing[existing.length - 1];
26+
core.info(`Updating comment ${last.id}`);
27+
await github.rest.issues.updateComment({
28+
owner, repo,
29+
body,
30+
comment_id: last.id,
31+
});
32+
} else {
33+
core.info(`Creating a comment in issue / PR #${issue_number}`);
34+
await github.rest.issues.createComment({issue_number, body, owner, repo});
35+
}
36+
}
37+
38+
const {owner, repo} = context.repo;
39+
const run_id = ${{github.event.workflow_run.id}};
40+
41+
const pull_requests = ${{ toJSON(github.event.workflow_run.pull_requests) }};
42+
if (!pull_requests.length) {
43+
return core.error("This workflow doesn't match any pull requests!");
44+
}
45+
46+
const artifacts = await github.paginate(
47+
github.rest.actions.listWorkflowRunArtifacts, {owner, repo, run_id});
48+
if (!artifacts.length) {
49+
return core.error(`No artifacts found`);
50+
}
51+
let body = `Download the artifacts for this pull request:\n`;
52+
for (const art of artifacts) {
53+
body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;
54+
}
55+
56+
core.info("Review thread message body:", body);
57+
58+
for (const pr of pull_requests) {
59+
await upsertComment(owner, repo, pr.number,
60+
"nightly-link", body);
61+
}

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This repository contains a Javascript implementation of [esptool](https://github
88

99
**CDN**
1010

11-
`https://unpkg.com/esptool-js/lib/index.js?module`
11+
`https://unpkg.com/esptool-js/lib/index.js` or `https://unpkg.com/esptool-js/bundle.js` to use the single bundle JavaScript file.
1212

1313
**NPM**
1414

@@ -20,6 +20,8 @@ This repository contains a Javascript implementation of [esptool](https://github
2020

2121
Check an example project [here](./examples/typescript).
2222

23+
**Nightly builds** for <a href="https://nightly.link/espressif/esptool-js/workflows/ci/main">ESPTOOL-JS</a>
24+
2325
## Define port filters for device using WebSerial
2426

2527
```js
@@ -62,6 +64,20 @@ npm run dev # Run local sever with example code
6264

6365
Then open `http://localhost:1234` in a Chrome browser. The `npm run build` step builds the `lib` used in the example `examples/typescript/index.html`. Update this reference as described in [Usage](#usage) section.
6466

67+
## Test from Pull Request artifact
68+
69+
If you are testing the main branch or any Pull Request (PR) artifact you can follow these steps:
70+
71+
1. Get the `esptool-js-<version>.tgz` where `<version>` is the current version and download it.
72+
2. Add the following line to your project's package.json dependencies
73+
74+
```json
75+
"dependencies": {
76+
"esptool-js": "file:../path/to/esptool-js-<version>.tgz"
77+
}
78+
```
79+
3. Use the package like `import "esptool-js/lib/index.js"` when added in package.json as shown before.
80+
6581
## License
6682

6783
The code in this repository is Copyright (c) 2023 Espressif Systems (Shanghai) Co. Ltd. It is licensed under Apache 2.0 license, as described in [LICENSE](LICENSE) file.

0 commit comments

Comments
 (0)