Skip to content

Commit f25428c

Browse files
author
Robin Bilgil
committed
prod dependencies
1 parent 9ee0fa9 commit f25428c

4 files changed

Lines changed: 57 additions & 55 deletions

File tree

__tests__/main.test.ts

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,5 @@
1-
import {wait} from '../src/wait'
2-
import * as process from 'process'
3-
import * as cp from 'child_process'
4-
import * as path from 'path'
5-
import {expect, test} from '@jest/globals'
1+
import { expect, test } from '@jest/globals'
62

7-
test('throws invalid number', async () => {
8-
const input = parseInt('foo', 10)
9-
await expect(wait(input)).rejects.toThrow('milliseconds not a number')
10-
})
11-
12-
test('wait 500 ms', async () => {
13-
const start = new Date()
14-
await wait(500)
15-
const end = new Date()
16-
var delta = Math.abs(end.getTime() - start.getTime())
17-
expect(delta).toBeGreaterThan(450)
18-
})
19-
20-
// shows how the runner will run a javascript action with env / stdout protocol
21-
test('test runs', () => {
22-
process.env['INPUT_MILLISECONDS'] = '500'
23-
const np = process.execPath
24-
const ip = path.join(__dirname, '..', 'lib', 'main.js')
25-
const options: cp.ExecFileSyncOptions = {
26-
env: process.env
27-
}
28-
console.log(cp.execFileSync(np, [ip], options).toString())
29-
})
3+
test('No test implemented', () => {
4+
expect('tests').not.toBe('implemented')
5+
})

action.yml

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
1-
name: 'Your name here'
2-
description: 'Provide a description here'
3-
author: 'Your name or organization here'
1+
name: 'Turbo Changed Packages'
2+
description: 'A Github Action to return the changed packages from a Turborepo project'
3+
author: 'Packfleet'
4+
branding:
5+
icon: git-branch
6+
color: green
47
inputs:
5-
milliseconds: # change this
8+
prefix:
9+
required: false
10+
description: 'Prefix to filter the packages'
11+
from:
612
required: true
7-
description: 'input description here'
8-
default: 'default value if applicable'
13+
description: 'Start of the commit range to check (can be a commit hash or a branch name).'
14+
to:
15+
required: false
16+
description: 'End of the commit range to check (can be a commit hash or branch). If not provided, will be the current commit of the head branch on a `pull_request` event. For a push event, it will be the current commit of the current branch.'
17+
working-directory:
18+
required: false
19+
description: 'Path to the root of the turborepo project.'
20+
default: './'
21+
outputs:
22+
changed:
23+
description: 'True if the workspace changed, otherwise false.'
24+
925
runs:
1026
using: 'node16'
11-
main: 'dist/index.js'
27+
main: 'dist/index.js'

src/main.ts

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
1-
import * as core from '@actions/core'
2-
import {wait} from './wait'
1+
import { execSync } from 'child_process'
2+
import { join } from 'path'
3+
import { getInput, debug, setFailed, setOutput } from '@actions/core'
34

4-
async function run(): Promise<void> {
5+
const run = async (): Promise<void> => {
56
try {
6-
const ms: string = core.getInput('milliseconds')
7-
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_STEP_DEBUG` to true
7+
// Get Inputs
8+
const prefix = getInput('prefix', { required: false })
9+
const from = getInput('from', { required: true })
10+
const to = getInput('to', { required: true })
11+
const workingDirectory = getInput('working-directory', { required: true })
812

9-
core.debug(new Date().toTimeString())
10-
await wait(parseInt(ms, 10))
11-
core.debug(new Date().toTimeString())
13+
debug(`Inputs: ${JSON.stringify({ prefix, from, to, workingDirectory })}`)
1214

13-
core.setOutput('time', new Date().toTimeString())
15+
const json = execSync(
16+
`npx turbo run build --filter="[${from}...${to}]" --dry-run=json`,
17+
{
18+
cwd: join(process.cwd(), workingDirectory),
19+
encoding: 'utf-8',
20+
},
21+
)
22+
23+
debug(`Output from Turborepo: ${json}`)
24+
25+
const parsedOutput = JSON.parse(json)
26+
const changedPackages = parsedOutput.packages.filter((p: string) => !prefix || p.startsWith(prefix));
27+
28+
setOutput('changed', changedPackages)
1429
} catch (error) {
15-
if (error instanceof Error) core.setFailed(error.message)
30+
if (error instanceof Error || typeof error === 'string') {
31+
setFailed(error)
32+
} else {
33+
setFailed('Unknown error occured.')
34+
}
1635
}
1736
}
1837

19-
run()
38+
void run()

src/wait.ts

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

0 commit comments

Comments
 (0)