Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rework project structure #15

Merged
merged 10 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions .github/workflows/checkin.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,23 @@
name: "PR Checks"
on: [pull_request, push]

name: Node.js CI
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
check_pr:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1

- name: "npm ci"
run: npm ci

- name: "npm run build"
run: npm run build

- name: "npm run test"
run: npm run test

- name: "check for uncommitted changes"
# Ensure no changes, but ignore node_modules dir since dev/fresh ci deps installed.
run: |
git diff --exit-code --stat -- . ':!node_modules' \
|| (echo "##[error] found changed files after build. please 'npm run build && npm run format'" \
"and check in all changes" \
&& exit 1)
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: 12.x
- name: Install dependencies
run: npm install
- name: Run tests
run: npm run test
env:
CI: "true"
- name: Build project
run: npm run build
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
node_modules/
__tests__/runner/*
package-lock.json
coverage/
lib/
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

This GitHub Action offers you a direct way to interact with the host system on which the actual scripts (Actions) will run.

## Features

- Debug your GitHub Actions by using SSH
- Continue your Workflows afterwards

## Supported Operating Systems

- `Linux`
- `macOS`
- (`Window` is **not** supported. It will be skipped so that the Pipeline does not fail)

## Getting Started

Expand All @@ -18,11 +24,19 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Setup tmate session
uses: mxschmitt/action-tmate@v1
uses: mxschmitt/action-tmate@v2
```

To get the connection string, just open the `Checks` tab in your Pull Request and scroll to the bottom. There you can connect either directly per SSH or via a web based terminal.

![alt text](./docs/checks-tab.png "Logo Title Text 1")

## Continue a workflow

If you want to continue a workflow and you are inside a tmate session, just create a empty `continue` file either in the root directory or in the project directory by running `touch continue`.

## Connection string / URL is not visible

The connection string will be written in the logs every 5 seconds. For more information checkout issue [#1](https://github.com/mxschmitt/action-tmate/issues/1).
3 changes: 0 additions & 3 deletions __tests__/main.test.ts

This file was deleted.

6 changes: 2 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: 'Debugging with tmate'
description: 'Debug your GitHub Actions Environment'
description: 'Debug your GitHub Actions Environment interactively by using SSH or a Web shell'
author: 'Max Schmitt'
runs:
using: 'node12'
main: 'lib/main.js'
icon: settings
color: gray-dark
main: 'lib/index.js'
12 changes: 12 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
presets: [
[
'@babel/preset-env',
{
targets: {
node: 'current',
},
},
],
],
}
9 changes: 2 additions & 7 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
verbose: true,
collectCoverage: true
}
139 changes: 0 additions & 139 deletions package-lock.json

This file was deleted.

17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"description": "Node 12 template action",
"main": "lib/main.js",
"scripts": {
"build": "tsc",
"start": "node src/index.js",
"build": "ncc build src/main.js -o lib",
"test": "jest"
},
"repository": {
Expand All @@ -20,14 +21,14 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.0.0"
"@actions/core": "^1.2.3"
},
"devDependencies": {
"@types/jest": "^24.0.18",
"@types/node": "^12.12.17",
"jest": "^24.9.0",
"jest-circus": "^24.9.0",
"ts-jest": "^24.0.2",
"typescript": "^3.5.3"
"@babel/core": "^7.8.7",
"@babel/preset-env": "^7.8.7",
"@zeit/ncc": "^0.21.1",
"babel-jest": "^25.1.0",
"jest": "^25.1.0",
"jest-circus": "^25.1.0"
}
}
23 changes: 23 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { spawn } from 'child_process'

export const execShellCommand = (cmd) => {
return new Promise((resolve, reject) => {
const process = spawn(cmd, [], { shell: true })
let stdout = ""
process.stdout.on('data', (data) => {
console.log(data.toString());
stdout += data.toString();
});

process.stderr.on('data', (data) => {
console.error(data.toString());
});

process.on('exit', (code) => {
if (code !== 0) {
reject(new Error(code ? code.toString() : undefined))
}
resolve(stdout)
});
});
}
55 changes: 55 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import fs from "fs"
import path from "path"
import * as core from "@actions/core"

import { execShellCommand } from "./helpers"

const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));

export async function run() {
try {
if (process.platform === "win32") {
core.info("Windows is not supported by tmate, skipping...")
return
}

core.debug("Installing dependencies")
if (process.platform === "darwin") {
await execShellCommand('brew install tmate');
} else {
await execShellCommand('sudo apt-get update');
await execShellCommand('sudo apt-get install -y tmate openssh-client');
}
core.debug("Installed dependencies successfully");

core.debug("Generating SSH keys")
try {
await execShellCommand(`echo -e 'y\n'|ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa`);
} catch { }
core.debug("Generated SSH-Key successfully")

core.debug("Creating new session")
await execShellCommand('tmate -S /tmp/tmate.sock new-session -d');
await execShellCommand('tmate -S /tmp/tmate.sock wait tmate-ready');
console.debug("Created new session successfully")

core.debug("Fetching connection strings")
const tmateSSH = await execShellCommand(`tmate -S /tmp/tmate.sock display -p '#{tmate_ssh}'`);
const tmateWeb = await execShellCommand(`tmate -S /tmp/tmate.sock display -p '#{tmate_web}'`);

console.debug("Entering main loop")
while (true) {
core.info(`WebURL: ${tmateWeb}`);
core.info(`SSH: ${tmateSSH}`);

const skip = fs.existsSync("/continue") || fs.existsSync(path.join(process.env.GITHUB_WORKSPACE, "continue"))
if (skip) {
core.info("Existing debugging session because '/continue' file was created")
break
}
await sleep(5000)
}
} catch (error) {
core.setFailed(error.message);
}
}
Loading