Skip to content

Commit 868ce7d

Browse files
committed
Retire the template Action's functionality
We want to implement a very different type of wait. While at it, clean up the test code that wants to spawn a full-fledged `node.exe` process in order to simulate a GitHub Action run. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent b746375 commit 868ce7d

File tree

4 files changed

+20
-41
lines changed

4 files changed

+20
-41
lines changed

.github/workflows/test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,3 @@ jobs:
2020
steps:
2121
- uses: actions/checkout@v2
2222
- uses: ./
23-
with:
24-
milliseconds: 1000

__tests__/main.test.ts

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
import {wait} from '../src/wait'
1+
/* eslint-disable no-console */
22
import * as process from 'process'
3-
import * as cp from 'child_process'
3+
import * as child_process from 'child_process'
44
import * as path from 'path'
55

6-
test('throws invalid number', async () => {
7-
const input = parseInt('foo', 10)
8-
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
9-
})
6+
async function runAction(
7+
options?: child_process.SpawnOptionsWithoutStdio
8+
): Promise<number> {
9+
return new Promise<number>((resolve, reject) => {
10+
const nodeExePath = process.execPath
11+
const scriptPath = path.join(__dirname, '..', 'lib', 'main.js')
1012

11-
test('wait 500 ms', async () => {
12-
const start = new Date()
13-
await wait(500)
14-
const end = new Date()
15-
var delta = Math.abs(end.getTime() - start.getTime())
16-
expect(delta).toBeGreaterThan(450)
17-
})
13+
const child = child_process
14+
.spawn(nodeExePath, [scriptPath], options)
15+
.on('error', reject)
16+
.on('close', resolve)
17+
18+
child.stderr.on('data', data => console.log(`${data}`))
19+
child.stdout.on('data', data => console.log(`${data}`))
20+
})
21+
}
1822

1923
// shows how the runner will run a javascript action with env / stdout protocol
20-
test('test runs', () => {
21-
process.env['INPUT_MILLISECONDS'] = '500'
22-
const np = process.execPath
23-
const ip = path.join(__dirname, '..', 'lib', 'main.js')
24-
const options: cp.ExecFileSyncOptions = {
25-
env: process.env
26-
}
27-
console.log(cp.execFileSync(np, [ip], options).toString())
24+
test('test this Action locally', async () => {
25+
expect(await runAction()).toEqual(0)
2826
})

src/main.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,8 @@
11
import * as core from '@actions/core'
2-
import {wait} from './wait'
32

43
async function run(): Promise<void> {
54
try {
6-
const ms: string = core.getInput('milliseconds')
7-
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
8-
9-
core.debug(new Date().toTimeString())
10-
await wait(parseInt(ms, 10))
11-
core.debug(new Date().toTimeString())
12-
13-
core.setOutput('time', new Date().toTimeString())
5+
core.debug('Running the Action')
146
} catch (error) {
157
core.setFailed(error.message)
168
}

src/wait.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)