• Stars
    star
    439
  • Rank 99,247 (Top 2 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 4 years ago
  • Updated 6 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Execute any script in a GitHub issue comment

comment-run

Execute any script in a GitHub issue comment

Say "hello, world"

You can make GitHub Actions Bot to say "hello, world".

Post comment below on your issue or pull request.

For shorter, you can use as follows.

@github-actions run

```js
await postComment("hello, world");
```

Introduce this action

Put .github/workflows/comment-run.yml to introduce comment-run.

# .github/workflows/comment-run.yml
name: "Comment run"
on:
  issue_comment:
    types: [created, edited]

jobs:
  comment-run:
    runs-on: ubuntu-20.04
    steps:
    - uses: actions/checkout@v3
    - uses: nwtgck/actions-comment-run@v2
      with:
        github-token: ${{ secrets.GITHUB_TOKEN }}
        allowed-associations: '["OWNER"]'

You can introduce comment-run with the following command.

mkdir -p .github/workflows && cd .github/workflows && wget https://gist.githubusercontent.com/nwtgck/a9b291f6869db42ecc3d9e30d0a0494c/raw/comment-run.yml && cd -

After introducing this, create new issue or pull request and post @github-actions run comment.

Comment author who can run scripts

Only accounts who have admin or write permission can execute the comment on your repository. (ref: Collaborators | GitHub Developer Guide)

By default, only owner can execute the scripts. You can change allowed-associations: '["OWNER"]' in the yaml above.

Here are examples.

  • allowed-associations: '["OWNER"]'
  • allowed-associations: '["OWNER", "MEMBER"]'
  • allowed-associations: '["OWNER", "COLLABORATOR"]'

Learn more: CommentAuthorAssociation | GitHub Developer Guide

Available variables in the js-comment-context

Here are available variables and functions in the ```js code block.

variable examples type or reference
context context.repo.owner, context.payload.comment toolkit/context.ts at @actions/[email protected] · actions/toolkit
githubToken require('@actions/github').getOctokit(githubToken)
octokit await octokit.rest.pulls.create(...), await octokit.graphql(...) toolkit/packages/github at master · actions/toolkit
execSync execSync("ls -l") child_process.execSync()
postComment await postComment("**hey!**") (markdown: string) => Promise<void>, post GitHub issue/pull request comment
fetch await fetch("https://example.com") node-fetch/node-fetch: A light-weight module that brings window.fetch to Node.js
core core.debug('my message') toolkit/packages/core at master · actions/toolkit
exec await exec.exec("git status") toolkit/packages/exec at master · actions/toolkit
(deprecated) githubClient await githubClient.pulls.create(...), await githubClient.graphql(...) toolkit/packages/github at master · actions/toolkit

Other built-in variables and functions in Node.js such as process and require(...) are also available. This means you can use process.env for environment variables and require('fs') for file access.

Although other variables not in the list can be used on the comment, comment-run guarantees use of the variables list above and non-listed variables are not guaranteed to use.

Useful examples

LGTM Image

Post random LGTM image with LGTM.in/g.

LGTM.in

@github-actions run

<details>
<summary>LGTM 👍 </summary>

```js
const res = await fetch("https://lgtm.in/g", {
  redirect: 'manual'
});
const webSiteUrl = res.headers.get('location');
const picUrl = new URL(webSiteUrl);
picUrl.pathname = picUrl.pathname.replace("/i/", "/p/");
postComment(`![LGTM](${picUrl.href})`);
```
</details>

Update all npm packages

Although Dependabot is useful, sometimes you might want to bump all packages up. This comment allows you to do this.

@github-actions run

```js
function exec(cmd) {
  console.log(execSync(cmd).toString());
}

// Config
const gitUserEmail = "github-actions[bot]@users.noreply.github.com";
const gitUserName = "github-actions[bot]";
const prBranchName = "comment-run/npm-update";

const baseBranchName = context.payload.repository.default_branch";
exec(`git config --global user.email "${gitUserEmail}"`);
exec(`git config --global user.name "${gitUserName}"`);
exec(`git fetch --all`);
exec(`git checkout ${baseBranchName}`);
exec(`git checkout -b ${prBranchName}`);

const packageJson = JSON.parse(require('fs').readFileSync('package.json'));
const depStr = Object.keys(packageJson.dependencies || {}).join(' ');
const devDepStr = Object.keys(packageJson.devDependencies || {}).join(' ');
exec(`npm i ${depStr} ${devDepStr}`);

exec("git status");
exec("git add package*json");
exec(`git commit -m "chore(deps): update npm dependencies"`);
exec(`git push -fu origin ${prBranchName}`);

await githubClient.pulls.create({
  base: baseBranchName,
  head: prBranchName,
  owner: context.repo.owner,
  repo: context.repo.repo,
  title: "chore(deps): update npm dependencies",
  body: "update npm dependencies",
});
```

PR merge preview

GitHub Actions do not pass secrets to pull request from forked repositories. This security feature may restricts GitHub Actions usages. This comment is created to resolve the problem

@github-actions run

<details>
<summary>🚀 Merge preview</summary>

```js
// Get pull-req URL like "https://api.github.com/repos/nwtgck/actions-merge-preview/pulls/4"
const pullReqUrl = context.payload.issue.pull_request.url;
const githubUser = context.payload.repository.owner.login;
const res = await fetch(pullReqUrl, {
  headers: [
    ['Authorization', `Basic ${Buffer.from(`${githubUser}:${githubToken}`).toString('base64')}`]
  ]
});
const resJson = await res.json();
const prUserName = resJson.head.user.login;
const baseBranchName = resJson.base.ref;
const branchName = resJson.head.ref;
const fullRepoName = resJson.head.repo.full_name;
const previewBranchName = `actions-merge-preview/${prUserName}-${branchName}`;
execSync(`git config --global user.email "github-actions[bot]@users.noreply.github.com"`);
execSync(`git config --global user.name "github-actions[bot]"`);
// (from: https://stackoverflow.com/a/23987039/2885946)
execSync(`git fetch --all`);
console.log(execSync(`git checkout ${baseBranchName}`).toString());
console.log(execSync(`git checkout -b ${previewBranchName} ${baseBranchName}`).toString());
console.log(execSync(`git pull https://github.com/${fullRepoName}.git ${branchName}`).toString());
// Push preview branch
// NOTE: Force push (should be safe because preview branch always start with "actions-merge-preview/")
execSync(`git push -fu origin ${previewBranchName}`);
const baseRepoFullName = context.payload.repository.full_name;
// Comment body
const commentBody = `🚀 Preview branch:  \n<https://github.com/${baseRepoFullName}/tree/${previewBranchName}>`;
// Comment the deploy URL
await postComment(commentBody);
```
</details>

SSH in GitHub Actions over Piping Server

This comment allows you to go inside of GitHub Actions environment.

SSH over Piping Server

SSH over Piping Server terminal

@github-actions run

<details>
<summary>🌐 SSH debug over Piping Server</summary>

```js
const crypto = require('crypto');
const pathLen = 64;
const aPath = randomString(pathLen);
const bPath = randomString(pathLen);
const commentUserId = context.payload.comment.user.login;
const clientHostPort =  Math.floor(Math.random() * 55536) + 10000;

console.log(execSync(`
chmod 755 "$HOME"
ls -lA /home
authorized_keys_file="$(sshd -T 2>/dev/null | grep -E '^authorizedkeysfile ' | cut -d ' ' -f 2)"
authorized_keys_file="$(cd && realpath -m "$authorized_keys_file")"
sshd_config_dir="$(dirname "$authorized_keys_file")"
(umask 0077 && mkdir "$sshd_config_dir")
echo $authorized_keys_file;

# (from: https://qiita.com/zackey2/items/429c77e5780ba8bc1bf9#authorized_keys%E3%81%AB%E8%A8%AD%E5%AE%9A%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95)
(echo; curl https://github.com/${commentUserId}.keys; echo) >> ~/.ssh/authorized_keys

sudo apt install -y socat;
`).toString());

// Comment new session
const commentBody = `\
## 🌐 New SSH session
Run the command below.

\`\`\`bash
socat TCP-LISTEN:${clientHostPort} 'EXEC:curl -NsS https\\://ppng.io/${bPath}!!EXEC:curl -NsST - https\\://ppng.io/${aPath}'
\`\`\`

Run the command below in another terminal.

\`\`\`bash
ssh -p ${clientHostPort} runner@localhost
\`\`\`

`;
await githubClient.issues.createComment({
  issue_number: context.issue.number,
  owner: context.repo.owner,
  repo: context.repo.repo,
  body: commentBody
});

execSync(`socat 'EXEC:curl -NsS https\\://ppng.io/${aPath}!!EXEC:curl -NsST - https\\://ppng.io/${bPath}' TCP:127.0.0.1:22`);


function randomString(len){
  const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  const randomArr = new Uint32Array(new Uint8Array(crypto.randomBytes(len * 4)).buffer);
  return [...randomArr].map(n => chars.charAt(n % chars.length)).join('');
}
```

## References
* <https://github.com/Cryolite/gha-sandbox/blob/789130f01504a372775be9a2fe4d8df6c4e0ce5c/.github/workflows/ssh.yaml>)
* <https://qiita.com/Cryolite/items/ed8fa237dd8eab54ef2f>

Thanks Cryolite!

</details>

TIPS: Saved replies

"Saved replies" fits this action very much.
Saved replies

You can save "Saved replies" as follows.
Avatar icon > Settings > Saved replies

TIPS: Reactions

Reactions on comments represent the Action is working. Here is a list of the reactions and descriptions.

reaction reason
👀 The Action has started looking at your comment.
👍 The Action has completed.

TIPS: Run other languages

This action supports shebang (#!), so you can run shell and Python as follows.

@github-actions run

```sh
#! /bin/sh
pip install numpy
```

```py
#! /usr/bin/python
import numpy as np

print(np.array([1, 2, 3]))
```

Here are examples.

TIPS: Use existing package, TypeScript and manage on GitHub

When your comment-run scripts are matured, you might want to use TypeScript for maintainability. The following repository uses existing npm packages and TypeScript.
https://github.com/nwtgck/comment-run-scripts

Built bundle .js files are hosted on GitHub Pages. So, your comment will be as follows.

@github-actions run

```js
const url = "https://nwtgck.github.io/comment-run-scripts/hello-world-comment.js";
const js = await (await fetch(url)).text();
eval(js);
```

More Repositories

1

piping-server

Infinitely transfer between every device over pure HTTP with pipes or browsers
TypeScript
2,759
star
2

gh-card

:octocat: GitHub Repository Card for Any Web Site
TypeScript
1,310
star
3

actions-netlify

🚀 Netlify deploy from GitHub Actions
TypeScript
323
star
4

piping-server-rust

Infinitely transfer between every device over pure HTTP with pipes or browsers
Rust
247
star
5

gif-progress

🎬 Attach progress bar to animated GIF
Go
195
star
6

piping-ui-web

Easy and secure file transfer between every device over HTTPS with/without E2E encryption by ECDH and OpenPGP
Vue
134
star
7

fakelish-npm

Fake English word generator for JavaScript/TypeScript
TypeScript
95
star
8

piping-ssh-web

SSH over HTTPS via Piping Server on Web browser
Vue
94
star
9

ray-tracing-iow-rust

Ray Tracing in One Weekend written in Rust
Rust
81
star
10

piping-vnc-web

VNC client over pure HTTPS via Piping Server on Web browser
JavaScript
73
star
11

nipp

🎒 Programmable portable App hosted on URL: https://nipp.nwtgck.org
Vue
68
star
12

piping-screen-share-web

🖥️ Screen Share via Piping Server with End-to-End Encryption
Vue
58
star
13

ssh-keygen-web

Generate a key-pair of ssh-keygen on Web browser
Vue
46
star
14

stacklover-rust

Zero-cost type for stack without complicated type or Box
Rust
45
star
15

piping-server-streaming-upload-htmls

fetch()'s streaming upload feature over Piping Server
HTML
36
star
16

go-fakelish

Fake English word generator for Go and CLI
Go
35
star
17

http-knocking

🚪HTTP-Knocking hides a Web server and open it by knocking sequence: Hide Web server until your knocks
TypeScript
27
star
18

piping-draw-web

🎨 End-to-End Encryption Share Drawing via Piping Server
Vue
26
star
19

ts-json-validator

JSON Validator for TypeScript - Safer JSON.parse() validating by TypeScript types
TypeScript
26
star
20

typescript-on-browser-starter

Starter for TypeScript on Web Browser
JavaScript
24
star
21

piping-chat-web

💬 Chat via Piping Server with End-to-End Encryption
TypeScript
24
star
22

web-ssh-keygen

🔒🔑 Generate a key-pair of ssh-keygen for Web browser
TypeScript
23
star
23

go-piping-server

Piping Server written in Go language (original: https://github.com/nwtgck/piping-server)
Go
22
star
24

piping-server-pkg

Piping Server as portable executable
22
star
25

go-piping-tunnel

Tunneling from anywhere via Piping Server
Go
20
star
26

docker-nginx-http3

Docker image for Nginx + HTTP/3 powered by Quiche
Dockerfile
19
star
27

yamux-cli

TCP and UDP multiplexer using yamux
Go
17
star
28

rich-piping-server

Rich Piping Server
TypeScript
13
star
29

go-webrtc-piping

WebRTC P2P tunneling/duplex with Piping Server WebRTC signaling
Go
12
star
30

piping-phone-web

📞 Real-time Voice Messaging over HTTP/HTTPS for Web Browser via Piping Server
Vue
12
star
31

piping-vnc-server-for-windows

Instant remote desktop for Windows from anywhere powered by UltraVNC Server and Piping Server
Vue
12
star
32

trans-server-akka

A Server for Transmitting File by curl or wget: Transfer data over HTTP/HTTPS
Scala
11
star
33

ray-tracing-iow-scala

Ray Tracing in One Weekend written in Scala
Scala
11
star
34

multi-svr-python

SVR for multidimensional labels
Python
10
star
35

platy-lang-haskell

Platy Language Compiler by Haskell & LLVM: Declarative, Statically typed and Simple to implement language
Haskell
10
star
36

handy-sshd

Portable SSH Server
Go
9
star
37

piping-webcodecs-screen-share-prototype-web

Vue
9
star
38

piping-chunk-web

📦 Chunked Stream File Transfer for Web Browser with End-to-End Encrypted
Vue
9
star
39

ghost-nginx-http3-docker-compose

Ghost + Nginx + HTTP/3 powered by Quiche in Docker Compose, Example of https://github.com/nwtgck/docker-nginx-http3
8
star
40

math2image-npm

CLI for generating beautiful SVG/PNG mathematical image ∑ ∫ π² ∞
TypeScript
7
star
41

docker-mkp224o

Docker image for mkp224o - generate vanity onion v3 address
Dockerfile
6
star
42

piping-adb-web

Android Debug Bridge (ADB) over Piping Serer on Web browser
TypeScript
6
star
43

docker-node-quic

Docker image for Node.js with QUIC
Dockerfile
6
star
44

math2img

Convert LaTeX Math to image
Crystal
6
star
45

docker-rust-musl-builder

original: https://github.com/emk/rust-musl-builder
Dockerfile
6
star
46

ts-copyable-npm

Type-safe #copy() for TypeScript inspired by Scala case-class
TypeScript
6
star
47

cmat2scores-python

Calculate accuracy, precision, recall and f-measure from confusion matrix
Python
6
star
48

tableau-solver-haskell

Tableau method solver in Haskell
Haskell
6
star
49

neural-network-dot

Neural Network by Graphviz
5
star
50

sw-force-download-web

Force download cross-origin file with Service Worker
HTML
5
star
51

go-piping-sshd

SSH server from anywhere with Piping Server
Go
5
star
52

cosense-bookmark-bookmarklet

JavaScript
5
star
53

tcphttp-server

TCP-over-HTTP server: Clients can use it with curl and perhaps browser
TypeScript
5
star
54

aes128gcm-stream-npm

🛡128-bit AES-GCM Encryption Stream for Web Browsers
TypeScript
5
star
55

specit-rust

Smoothly writing test titles in Rust
Rust
5
star
56

piping-server-onion-service-replit

Super easy to host Piping Server as Onion Service
Shell
4
star
57

comment-run-scripts

Scripts for comment-run action
TypeScript
4
star
58

tiny-http-piping-server-rust

Piping Server written in Rust with tiny-http
Rust
3
star
59

docker-nghttp2

Docker image of nghttpx with HTTP/3
Dockerfile
3
star
60

piping-server-zig

Piping Server in Zig (experimental)
Zig
3
star
61

qrcode-typescript-react

Real-time QR code generator written in TypeScript + React
TypeScript
3
star
62

piping-ui-web-onion-service-docker-compose

Piping UI as Onion Service
Dockerfile
3
star
63

docker-piping-server-rust-multi-platform

Multi-platform Piping Server in Rust Docker images
Dockerfile
3
star
64

private-ip-getter-npm

Private IP Getter for Web Browser
TypeScript
3
star
65

jwk-thumbprint-npm

JWK Thumbprint for JavaScript/TypeScript on both Web Browser and Node.js
TypeScript
3
star
66

assertion-haskell

Assertion with condition string representation in Haskell.
Haskell
3
star
67

go-piping-duplex

Duplex communication over Piping Server
Go
3
star
68

piping-server-onion-service-docker-compose

Piping Server as Onion Service
Shell
3
star
69

nwtgck-hypermd

HyperMD Quick Start
HTML
3
star
70

ibk

💾 Incremental Backup CLI using well-matured technology: tar
Go
3
star
71

binconv-npm

Converters for Blob, Uint8Array, ReadableStream, ArrayBuffer, string in JavaScript/TypeScript
TypeScript
3
star
72

digestream

CLI for streaming message digest calculator - Insert into pipe, get the digest in tty
Go
3
star
73

trans-server-tor-docker-compose

Trans server as Tor Hidden Service
Dockerfile
3
star
74

mac-sandbox

[WIP] Sandbox for macOS
Ruby
2
star
75

data-url-server

A server providing Data URL resource
JavaScript
2
star
76

docker-graalvm-node-piping-server

Docker image for Piping Server on Node.js on GraalVM
Dockerfile
2
star
77

actions-merge-preview

GitHub Actions for pull-request merge preview
TypeScript
2
star
78

jwt-piping-server

Piping Server with JWT authentication such as Auth0
TypeScript
2
star
79

cloudflare-pages-with-github-actions-prac

HTML
2
star
80

gh-language-colors-npm

GitHub Language Colors for JavaScript/TypeScript
TypeScript
2
star
81

egghead-todo-typescript-react

Type-safe TODO list app in React + Redux + TypeScript
TypeScript
2
star
82

tmpl

General Template Engine for Repository: "Keep your best practice as template"
Go
2
star
83

whoogle-search-replit

Whoogle Search which is easy to update on Replit
2
star
84

mac-screen-stream

[WIP] Screen Record Streaming for macOS
2
star
85

8cc-elc-hs

C Compiler written in Haskell powered by 8cc and ELVM
Haskell
2
star
86

verbose

CLI which makes your input verbose, flooding buffer
Go
2
star
87

piping-server-check

Check quality of Piping Server
Go
2
star
88

piping-phone-android

WIP: 📞 Real-time Voice Messaging over HTTP/HTTPS for Android via Piping Server
Kotlin
2
star
89

go-socks

SOCKS4, SOCKS4a and SOCKS5 proxy server in Go
Go
2
star
90

knapsack-elvm-haskell

Knapsack problem solver converted from C language by ELVM.
Haskell
2
star
91

svg-badge-scala

SVG Badge maker in Scala
Scala
2
star
92

event-loop-imitation-scala

Imitation of Event Loop in Scala
Scala
2
star
93

github-back-chrome-extension

A Chrome Extension which allows you to get initial commit on GitHub
JavaScript
2
star
94

docker-host-web

Docker image of web server printing hostname of Docker container
JavaScript
2
star
95

whoogle-search-onion-service-replit

Shell
2
star
96

promise-http-server-npm

Promise-based HTTP server for JavaScript/TypeScript: using accept(), easy to use in async-await context
TypeScript
2
star
97

piping-server-nginx-docker-compose

Piping Server with Nginx using Docker Compose, which might be helpful to write nginx.conf for Piping Server.
2
star
98

http2-http1-server-node

HTTP/2-interface HTTP1 server for compatibility for Node.js/TypeScript
TypeScript
2
star
99

nwtgck

1
star
100

piping-server-command-web

Piping Server Command Cheatsheet
TypeScript
1
star