Skip to content

Commit 6b7a9eb

Browse files
authored
@actions/core Platform Support (#138)
This PR adds support for the [`platform`](https://github.com/actions/toolkit/tree/main/packages/core#platform-helper) functionality in the `@actions/core` package. It also organizes the stubs to more closely reflect the `@actions/toolkit` repository structure, so that maintaining and updating stubs is a bit less of a nuisance.
2 parents 1b5783f + e52a4de commit 6b7a9eb

38 files changed

+475
-221
lines changed

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ actions can be run directly on your workstation.
1414
>
1515
> This tool currently only supports JavaScript and TypeScript actions!
1616
17+
The following table tracks the versions of the GitHub Actions Toolkit that are
18+
currently implemented by this tool.
19+
20+
| Package | Version |
21+
| ------------------- | -------- |
22+
| `@actions/artifact` | `2.2.0` |
23+
| `@actions/core` | `1.11.1` |
24+
1725
## v2 Changes
1826

1927
As of version `2.0.0`, the `local-action` tool has been updated to require

__fixtures__/exec.ts

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { jest } from '@jest/globals'
2+
3+
export const exec = jest.fn().mockImplementation(() => {})
4+
export const getExecOutput = jest.fn().mockImplementation(() => {})
5+
6+
export default {
7+
exec,
8+
getExecOutput
9+
}

__tests__/command.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals'
22
import { Command } from 'commander'
3-
import { ResetCoreMetadata } from '../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../src/stubs/core/core.js'
44
import { ResetEnvMetadata } from '../src/stubs/env.js'
55

66
const action = jest.fn()

__tests__/commands/run.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals'
22
import * as core from '../../__fixtures__/core.js'
3-
import { ResetCoreMetadata } from '../../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../../src/stubs/core/core.js'
44
import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env.js'
55

66
const quibbleEsm = jest.fn().mockImplementation(() => {})

__tests__/index.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { jest } from '@jest/globals'
2-
import { ResetCoreMetadata } from '../src/stubs/core.js'
2+
import { ResetCoreMetadata } from '../src/stubs/core/core.js'
33
import { ResetEnvMetadata } from '../src/stubs/env.js'
44

55
const makeProgram = jest.fn().mockResolvedValue({

__tests__/stubs/artifact/internal/client.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals'
22
import * as core from '../../../../__fixtures__/core.js'
3-
import { ResetCoreMetadata } from '../../../../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../../../../src/stubs/core/core.js'
44
import { EnvMeta, ResetEnvMetadata } from '../../../../src/stubs/env.js'
55

66
const isGhes = jest.fn().mockReturnValue(false)
@@ -58,7 +58,7 @@ jest.unstable_mockModule(
5858
deleteArtifactPublic
5959
})
6060
)
61-
jest.unstable_mockModule('../../../../src/stubs/core.js', () => core)
61+
jest.unstable_mockModule('../../../../src/stubs/core/core.js', () => core)
6262

6363
const { DefaultArtifactClient } = await import(
6464
'../../../../src/stubs/artifact/internal/client.js'

__tests__/stubs/artifact/internal/delete/delete-artifact.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { jest } from '@jest/globals'
22
import * as core from '../../../../../__fixtures__/core.js'
33
import * as fs from '../../../../../__fixtures__/fs.js'
4-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
4+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
55
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'
66

77
jest.unstable_mockModule('fs', () => fs)
8-
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
8+
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)
99

1010
const deleteArtifact = await import(
1111
'../../../../../src/stubs/artifact/internal/delete/delete-artifact.js'

__tests__/stubs/artifact/internal/download/download-artifact.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as core from '../../../../../__fixtures__/core.js'
33
import * as crypto from '../../../../../__fixtures__/crypto.js'
44
import * as fs from '../../../../../__fixtures__/fs.js'
55
import * as stream from '../../../../../__fixtures__/stream/promises.js'
6-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
6+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
77
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'
88

99
const readStream = {
@@ -14,7 +14,7 @@ const readStream = {
1414
jest.unstable_mockModule('crypto', () => crypto)
1515
jest.unstable_mockModule('fs', () => fs)
1616
jest.unstable_mockModule('stream/promises', () => stream)
17-
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
17+
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)
1818

1919
const downloadArtifact = await import(
2020
'../../../../../src/stubs/artifact/internal/download/download-artifact.js'

__tests__/stubs/artifact/internal/find/get-artifact.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { jest } from '@jest/globals'
22
import * as core from '../../../../../__fixtures__/core.js'
3-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
44
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'
55

6-
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
6+
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)
77

88
const getArtifact = await import(
99
'../../../../../src/stubs/artifact/internal/find/get-artifact.js'

__tests__/stubs/artifact/internal/find/list-artifacts.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals'
22
import * as core from '../../../../../__fixtures__/core.js'
3-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
44
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'
55

66
jest.unstable_mockModule('@actions/core', () => core)

__tests__/stubs/artifact/internal/shared/config.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals'
22
import { getGitHubWorkspaceDir } from '../../../../../src/stubs/artifact/internal/shared/config.js'
3-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
44
import { ResetEnvMetadata } from '../../../../../src/stubs/env.js'
55

66
describe('config', () => {

__tests__/stubs/artifact/internal/shared/user-agent.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { jest } from '@jest/globals'
22
import { getUserAgentString } from '../../../../../src/stubs/artifact/internal/shared/user-agent.js'
3-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
3+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
44
import { ResetEnvMetadata } from '../../../../../src/stubs/env.js'
55

66
describe('user-agent', () => {

__tests__/stubs/artifact/internal/upload/upload-artifact.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as core from '../../../../../__fixtures__/core.js'
44
import * as crypto from '../../../../../__fixtures__/crypto.js'
55
import * as fs from '../../../../../__fixtures__/fs.js'
66
import * as stream from '../../../../../__fixtures__/stream/promises.js'
7-
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
7+
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
88
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'
99

1010
const validateArtifactName = jest.fn()
@@ -27,7 +27,7 @@ const writeStream = {
2727
jest.unstable_mockModule('crypto', () => crypto)
2828
jest.unstable_mockModule('fs', () => fs)
2929
jest.unstable_mockModule('stream/promises', () => stream)
30-
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
30+
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)
3131
jest.unstable_mockModule(
3232
'../../../../../src/stubs/artifact/internal/upload/upload-zip-specification.js',
3333
() => ({

__tests__/stubs/core-stubs.test.ts __tests__/stubs/core/core.test.ts

+3-35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { jest } from '@jest/globals'
2-
import path from 'path'
32
import {
43
CoreMeta,
54
ResetCoreMetadata,
@@ -24,13 +23,10 @@ import {
2423
setOutput,
2524
setSecret,
2625
startGroup,
27-
toPlatformPath,
28-
toPosixPath,
29-
toWin32Path,
3026
warning
31-
} from '../../src/stubs/core.js'
32-
import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env.js'
33-
import type { CoreMetadata } from '../../src/types.js'
27+
} from '../../../src/stubs/core/core.js'
28+
import { EnvMeta, ResetEnvMetadata } from '../../../src/stubs/env.js'
29+
import type { CoreMetadata } from '../../../src/types.js'
3430

3531
/** Empty CoreMetadata Object */
3632
const empty: CoreMetadata = {
@@ -597,33 +593,5 @@ describe('Core', () => {
597593
await expect(getIDToken()).rejects.toThrow('Not implemented')
598594
})
599595
})
600-
601-
describe('toPosixPath()', () => {
602-
it('Returns a POSIX path', () => {
603-
expect(toPosixPath('C:\\Users\\mona\\Desktop')).toEqual(
604-
'C:/Users/mona/Desktop'
605-
)
606-
})
607-
})
608-
609-
describe('toWin32Path()', () => {
610-
it('Returns a WIN32 path', () => {
611-
expect(toWin32Path('C:/Users/mona/Desktop')).toEqual(
612-
'C:\\Users\\mona\\Desktop'
613-
)
614-
})
615-
})
616-
617-
describe('toPlatformPath()', () => {
618-
it('Returns a platform-specific path', () => {
619-
expect(toPlatformPath('C:/Users/mona/Desktop')).toEqual(
620-
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
621-
)
622-
623-
expect(toPosixPath('C:\\Users\\mona\\Desktop')).toEqual(
624-
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
625-
)
626-
})
627-
})
628596
})
629597
})
+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { jest } from '@jest/globals'
2+
import path from 'path'
3+
import { ResetCoreMetadata } from '../../../src/stubs/core/core.js'
4+
import {
5+
toPlatformPath,
6+
toPosixPath,
7+
toWin32Path
8+
} from '../../../src/stubs/core/path-utils.js'
9+
import { ResetEnvMetadata } from '../../../src/stubs/env.js'
10+
11+
// Prevent output during tests
12+
jest.spyOn(console, 'log').mockImplementation(() => {})
13+
jest.spyOn(console, 'table').mockImplementation(() => {})
14+
15+
describe('path-utils', () => {
16+
beforeEach(() => {
17+
// Reset metadata
18+
ResetEnvMetadata()
19+
ResetCoreMetadata()
20+
})
21+
22+
afterEach(() => {
23+
// Reset all spies
24+
jest.resetAllMocks()
25+
})
26+
27+
describe('toWin32Path()', () => {
28+
it('Returns a WIN32 path', () => {
29+
expect(toWin32Path('C:/Users/mona/Desktop')).toEqual(
30+
'C:\\Users\\mona\\Desktop'
31+
)
32+
})
33+
})
34+
35+
describe('toPlatformPath()', () => {
36+
it('Returns a platform-specific path', () => {
37+
expect(toPlatformPath('C:/Users/mona/Desktop')).toEqual(
38+
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
39+
)
40+
41+
expect(toPosixPath('C:\\Users\\mona\\Desktop')).toEqual(
42+
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
43+
)
44+
})
45+
})
46+
})

__tests__/stubs/summary-stubs.test.ts __tests__/stubs/core/summary.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { jest } from '@jest/globals'
22
import fs from 'fs'
33
import { EOL } from 'os'
44
import path from 'path'
5-
import { CoreMeta, ResetCoreMetadata } from '../../src/stubs/core.js'
6-
import { Summary } from '../../src/stubs/summary.js'
5+
import { CoreMeta, ResetCoreMetadata } from '../../../src/stubs/core/core.js'
6+
import { Summary } from '../../../src/stubs/core/summary.js'
77

88
let summary: Summary = new Summary()
99

__tests__/stubs/env-stubs.test.ts __tests__/stubs/env.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { jest } from '@jest/globals'
2-
import { ResetCoreMetadata } from '../../src/stubs/core.js'
2+
import { ResetCoreMetadata } from '../../src/stubs/core/core.js'
33
import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env.js'
44
import type { EnvMetadata } from '../../src/types.js'
55

__tests__/utils/output.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { jest } from '@jest/globals'
2-
import { ResetCoreMetadata } from '../../src/stubs/core.js'
2+
import { ResetCoreMetadata } from '../../src/stubs/core/core.js'
33
import { ResetEnvMetadata } from '../../src/stubs/env.js'
44
import { printTitle } from '../../src/utils/output.js'
55

docs/supported-functionality.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ to the `local-action` command.
6666
| `toPosixPath()` | :white_check_mark: | |
6767
| `toWin32Path()` | :white_check_mark: | |
6868
| `toPlatformPath()` | :white_check_mark: | |
69-
| `platform.*` | :no_entry: | |
69+
| `platform.*` | :white_check_mark: | |
7070

7171
## Under Investigation
7272

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@github/local-action",
33
"description": "Local Debugging for GitHub Actions",
4-
"version": "2.3.0",
4+
"version": "2.4.0",
55
"type": "module",
66
"author": "Nick Alteen <ncalteen@github.com>",
77
"private": false,

src/commands/run.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { config } from 'dotenv'
22
import { createRequire } from 'module'
33
import quibble from 'quibble'
44
import { ARTIFACT_STUBS } from '../stubs/artifact/artifact.js'
5-
import { CORE_STUBS, CoreMeta } from '../stubs/core.js'
5+
import { CORE_STUBS, CoreMeta } from '../stubs/core/core.js'
66
import { EnvMeta } from '../stubs/env.js'
77
import type { Action } from '../types.js'
88
import { printTitle } from '../utils/output.js'

src/stubs/artifact/internal/client.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { warning } from '../../core.js'
1+
import { warning } from '../../core/core.js'
22
import {
33
deleteArtifactInternal,
44
deleteArtifactPublic

src/stubs/artifact/internal/delete/delete-artifact.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { retry } from '@octokit/plugin-retry'
66
import fs from 'fs'
77
import path from 'path'
88
import { EnvMeta } from '../../../../stubs/env.js'
9-
import * as core from '../../../core.js'
9+
import * as core from '../../../core/core.js'
1010
import { getArtifactPublic } from '../find/get-artifact.js'
1111
import { getRetryOptions } from '../find/retry-options.js'
1212
import {

src/stubs/artifact/internal/download/download-artifact.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import path from 'path'
55
import { finished } from 'stream/promises'
66
import unzip from 'unzip-stream'
77
import { EnvMeta } from '../../../../stubs/env.js'
8-
import * as core from '../../../core.js'
8+
import * as core from '../../../core/core.js'
99
import { getGitHubWorkspaceDir } from '../shared/config.js'
1010
import { ArtifactNotFoundError } from '../shared/errors.js'
1111
import type {

src/stubs/artifact/internal/find/get-artifact.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { OctokitOptions } from '@octokit/core'
44
import { requestLog } from '@octokit/plugin-request-log'
55
import { retry } from '@octokit/plugin-retry'
66
import { EnvMeta } from '../../../../stubs/env.js'
7-
import * as core from '../../../core.js'
7+
import * as core from '../../../core/core.js'
88
import {
99
ArtifactNotFoundError,
1010
InvalidResponseError

src/stubs/artifact/internal/find/list-artifacts.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import type { OctokitOptions } from '@octokit/core'
44
import { requestLog } from '@octokit/plugin-request-log'
55
import { retry } from '@octokit/plugin-retry'
66
import { EnvMeta } from '../../../../stubs/env.js'
7-
import * as core from '../../../core.js'
7+
import * as core from '../../../core/core.js'
88
import type { Artifact, ListArtifactsResponse } from '../shared/interfaces.js'
99
import { getUserAgentString } from '../shared/user-agent.js'
1010
import { getRetryOptions } from './retry-options.js'

src/stubs/artifact/internal/find/retry-options.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import type { OctokitOptions } from '@octokit/core'
77
import type { RequestRequestOptions } from '@octokit/types'
8-
import * as core from '../../../core.js'
8+
import * as core from '../../../core/core.js'
99

1010
export type RetryOptions = {
1111
doNotRetry?: number[]

src/stubs/artifact/internal/upload/path-and-artifact-name-validation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44
/* istanbul ignore file */
55

6-
import { info } from '../../../core.js'
6+
import { info } from '../../../core/core.js'
77

88
/**
99
* Invalid characters that cannot be in the artifact name or an uploaded file. Will be rejected

src/stubs/artifact/internal/upload/upload-artifact.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import fs from 'fs'
33
import path from 'path'
44
import { finished } from 'stream/promises'
55
import { EnvMeta } from '../../../../stubs/env.js'
6-
import * as core from '../../../core.ts'
6+
import * as core from '../../../core/core.ts'
77
import { FilesNotFoundError, InvalidResponseError } from '../shared/errors.js'
88
import type {
99
Artifact,

src/stubs/artifact/internal/upload/upload-zip-specification.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as fs from 'fs'
77
import { normalize, resolve } from 'path'
8-
import * as core from '../../../core.js'
8+
import * as core from '../../../core/core.js'
99
import { validateFilePath } from './path-and-artifact-name-validation.js'
1010

1111
export interface UploadZipSpecification {

0 commit comments

Comments
 (0)