Skip to content

Commit

Permalink
@actions/core Platform Support (#138)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ncalteen authored Jan 7, 2025
2 parents 1b5783f + e52a4de commit 6b7a9eb
Show file tree
Hide file tree
Showing 38 changed files with 475 additions and 221 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ actions can be run directly on your workstation.
>
> This tool currently only supports JavaScript and TypeScript actions!
The following table tracks the versions of the GitHub Actions Toolkit that are
currently implemented by this tool.

| Package | Version |
| ------------------- | -------- |
| `@actions/artifact` | `2.2.0` |
| `@actions/core` | `1.11.1` |

## v2 Changes

As of version `2.0.0`, the `local-action` tool has been updated to require
Expand Down
9 changes: 9 additions & 0 deletions __fixtures__/exec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { jest } from '@jest/globals'

export const exec = jest.fn().mockImplementation(() => {})
export const getExecOutput = jest.fn().mockImplementation(() => {})

export default {
exec,
getExecOutput
}
2 changes: 1 addition & 1 deletion __tests__/command.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals'
import { Command } from 'commander'
import { ResetCoreMetadata } from '../src/stubs/core.js'
import { ResetCoreMetadata } from '../src/stubs/core/core.js'
import { ResetEnvMetadata } from '../src/stubs/env.js'

const action = jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion __tests__/commands/run.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals'
import * as core from '../../__fixtures__/core.js'
import { ResetCoreMetadata } from '../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env.js'

const quibbleEsm = jest.fn().mockImplementation(() => {})
Expand Down
2 changes: 1 addition & 1 deletion __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest } from '@jest/globals'
import { ResetCoreMetadata } from '../src/stubs/core.js'
import { ResetCoreMetadata } from '../src/stubs/core/core.js'
import { ResetEnvMetadata } from '../src/stubs/env.js'

const makeProgram = jest.fn().mockResolvedValue({
Expand Down
4 changes: 2 additions & 2 deletions __tests__/stubs/artifact/internal/client.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals'
import * as core from '../../../../__fixtures__/core.js'
import { ResetCoreMetadata } from '../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../../src/stubs/env.js'

const isGhes = jest.fn().mockReturnValue(false)
Expand Down Expand Up @@ -58,7 +58,7 @@ jest.unstable_mockModule(
deleteArtifactPublic
})
)
jest.unstable_mockModule('../../../../src/stubs/core.js', () => core)
jest.unstable_mockModule('../../../../src/stubs/core/core.js', () => core)

const { DefaultArtifactClient } = await import(
'../../../../src/stubs/artifact/internal/client.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { jest } from '@jest/globals'
import * as core from '../../../../../__fixtures__/core.js'
import * as fs from '../../../../../__fixtures__/fs.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'

jest.unstable_mockModule('fs', () => fs)
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)

const deleteArtifact = await import(
'../../../../../src/stubs/artifact/internal/delete/delete-artifact.js'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as core from '../../../../../__fixtures__/core.js'
import * as crypto from '../../../../../__fixtures__/crypto.js'
import * as fs from '../../../../../__fixtures__/fs.js'
import * as stream from '../../../../../__fixtures__/stream/promises.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'

const readStream = {
Expand All @@ -14,7 +14,7 @@ const readStream = {
jest.unstable_mockModule('crypto', () => crypto)
jest.unstable_mockModule('fs', () => fs)
jest.unstable_mockModule('stream/promises', () => stream)
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)

const downloadArtifact = await import(
'../../../../../src/stubs/artifact/internal/download/download-artifact.js'
Expand Down
4 changes: 2 additions & 2 deletions __tests__/stubs/artifact/internal/find/get-artifact.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { jest } from '@jest/globals'
import * as core from '../../../../../__fixtures__/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'

jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)

const getArtifact = await import(
'../../../../../src/stubs/artifact/internal/find/get-artifact.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals'
import * as core from '../../../../../__fixtures__/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'

jest.unstable_mockModule('@actions/core', () => core)
Expand Down
2 changes: 1 addition & 1 deletion __tests__/stubs/artifact/internal/shared/config.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals'
import { getGitHubWorkspaceDir } from '../../../../../src/stubs/artifact/internal/shared/config.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { ResetEnvMetadata } from '../../../../../src/stubs/env.js'

describe('config', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jest } from '@jest/globals'
import { getUserAgentString } from '../../../../../src/stubs/artifact/internal/shared/user-agent.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { ResetEnvMetadata } from '../../../../../src/stubs/env.js'

describe('user-agent', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as core from '../../../../../__fixtures__/core.js'
import * as crypto from '../../../../../__fixtures__/crypto.js'
import * as fs from '../../../../../__fixtures__/fs.js'
import * as stream from '../../../../../__fixtures__/stream/promises.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../../../src/stubs/env.js'

const validateArtifactName = jest.fn()
Expand All @@ -27,7 +27,7 @@ const writeStream = {
jest.unstable_mockModule('crypto', () => crypto)
jest.unstable_mockModule('fs', () => fs)
jest.unstable_mockModule('stream/promises', () => stream)
jest.unstable_mockModule('../../../../../src/stubs/core.js', () => core)
jest.unstable_mockModule('../../../../../src/stubs/core/core.js', () => core)
jest.unstable_mockModule(
'../../../../../src/stubs/artifact/internal/upload/upload-zip-specification.js',
() => ({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { jest } from '@jest/globals'
import path from 'path'
import {
CoreMeta,
ResetCoreMetadata,
Expand All @@ -24,13 +23,10 @@ import {
setOutput,
setSecret,
startGroup,
toPlatformPath,
toPosixPath,
toWin32Path,
warning
} from '../../src/stubs/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env.js'
import type { CoreMetadata } from '../../src/types.js'
} from '../../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../../src/stubs/env.js'
import type { CoreMetadata } from '../../../src/types.js'

/** Empty CoreMetadata Object */
const empty: CoreMetadata = {
Expand Down Expand Up @@ -597,33 +593,5 @@ describe('Core', () => {
await expect(getIDToken()).rejects.toThrow('Not implemented')
})
})

describe('toPosixPath()', () => {
it('Returns a POSIX path', () => {
expect(toPosixPath('C:\\Users\\mona\\Desktop')).toEqual(
'C:/Users/mona/Desktop'
)
})
})

describe('toWin32Path()', () => {
it('Returns a WIN32 path', () => {
expect(toWin32Path('C:/Users/mona/Desktop')).toEqual(
'C:\\Users\\mona\\Desktop'
)
})
})

describe('toPlatformPath()', () => {
it('Returns a platform-specific path', () => {
expect(toPlatformPath('C:/Users/mona/Desktop')).toEqual(
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
)

expect(toPosixPath('C:\\Users\\mona\\Desktop')).toEqual(
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
)
})
})
})
})
46 changes: 46 additions & 0 deletions __tests__/stubs/core/path-utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { jest } from '@jest/globals'
import path from 'path'
import { ResetCoreMetadata } from '../../../src/stubs/core/core.js'
import {
toPlatformPath,
toPosixPath,
toWin32Path
} from '../../../src/stubs/core/path-utils.js'
import { ResetEnvMetadata } from '../../../src/stubs/env.js'

// Prevent output during tests
jest.spyOn(console, 'log').mockImplementation(() => {})
jest.spyOn(console, 'table').mockImplementation(() => {})

describe('path-utils', () => {
beforeEach(() => {
// Reset metadata
ResetEnvMetadata()
ResetCoreMetadata()
})

afterEach(() => {
// Reset all spies
jest.resetAllMocks()
})

describe('toWin32Path()', () => {
it('Returns a WIN32 path', () => {
expect(toWin32Path('C:/Users/mona/Desktop')).toEqual(
'C:\\Users\\mona\\Desktop'
)
})
})

describe('toPlatformPath()', () => {
it('Returns a platform-specific path', () => {
expect(toPlatformPath('C:/Users/mona/Desktop')).toEqual(
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
)

expect(toPosixPath('C:\\Users\\mona\\Desktop')).toEqual(
`C:${path.sep}Users${path.sep}mona${path.sep}Desktop`
)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { jest } from '@jest/globals'
import fs from 'fs'
import { EOL } from 'os'
import path from 'path'
import { CoreMeta, ResetCoreMetadata } from '../../src/stubs/core.js'
import { Summary } from '../../src/stubs/summary.js'
import { CoreMeta, ResetCoreMetadata } from '../../../src/stubs/core/core.js'
import { Summary } from '../../../src/stubs/core/summary.js'

let summary: Summary = new Summary()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest } from '@jest/globals'
import { ResetCoreMetadata } from '../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../src/stubs/core/core.js'
import { EnvMeta, ResetEnvMetadata } from '../../src/stubs/env.js'
import type { EnvMetadata } from '../../src/types.js'

Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/output.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { jest } from '@jest/globals'
import { ResetCoreMetadata } from '../../src/stubs/core.js'
import { ResetCoreMetadata } from '../../src/stubs/core/core.js'
import { ResetEnvMetadata } from '../../src/stubs/env.js'
import { printTitle } from '../../src/utils/output.js'

Expand Down
2 changes: 1 addition & 1 deletion docs/supported-functionality.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ to the `local-action` command.
| `toPosixPath()` | :white_check_mark: | |
| `toWin32Path()` | :white_check_mark: | |
| `toPlatformPath()` | :white_check_mark: | |
| `platform.*` | :no_entry: | |
| `platform.*` | :white_check_mark: | |

## Under Investigation

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@github/local-action",
"description": "Local Debugging for GitHub Actions",
"version": "2.3.0",
"version": "2.4.0",
"type": "module",
"author": "Nick Alteen <[email protected]>",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { config } from 'dotenv'
import { createRequire } from 'module'
import quibble from 'quibble'
import { ARTIFACT_STUBS } from '../stubs/artifact/artifact.js'
import { CORE_STUBS, CoreMeta } from '../stubs/core.js'
import { CORE_STUBS, CoreMeta } from '../stubs/core/core.js'
import { EnvMeta } from '../stubs/env.js'
import type { Action } from '../types.js'
import { printTitle } from '../utils/output.js'
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { warning } from '../../core.js'
import { warning } from '../../core/core.js'
import {
deleteArtifactInternal,
deleteArtifactPublic
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/delete/delete-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { retry } from '@octokit/plugin-retry'
import fs from 'fs'
import path from 'path'
import { EnvMeta } from '../../../../stubs/env.js'
import * as core from '../../../core.js'
import * as core from '../../../core/core.js'
import { getArtifactPublic } from '../find/get-artifact.js'
import { getRetryOptions } from '../find/retry-options.js'
import {
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/download/download-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path'
import { finished } from 'stream/promises'
import unzip from 'unzip-stream'
import { EnvMeta } from '../../../../stubs/env.js'
import * as core from '../../../core.js'
import * as core from '../../../core/core.js'
import { getGitHubWorkspaceDir } from '../shared/config.js'
import { ArtifactNotFoundError } from '../shared/errors.js'
import type {
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/find/get-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { OctokitOptions } from '@octokit/core'
import { requestLog } from '@octokit/plugin-request-log'
import { retry } from '@octokit/plugin-retry'
import { EnvMeta } from '../../../../stubs/env.js'
import * as core from '../../../core.js'
import * as core from '../../../core/core.js'
import {
ArtifactNotFoundError,
InvalidResponseError
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/find/list-artifacts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { OctokitOptions } from '@octokit/core'
import { requestLog } from '@octokit/plugin-request-log'
import { retry } from '@octokit/plugin-retry'
import { EnvMeta } from '../../../../stubs/env.js'
import * as core from '../../../core.js'
import * as core from '../../../core/core.js'
import type { Artifact, ListArtifactsResponse } from '../shared/interfaces.js'
import { getUserAgentString } from '../shared/user-agent.js'
import { getRetryOptions } from './retry-options.js'
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/find/retry-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import type { OctokitOptions } from '@octokit/core'
import type { RequestRequestOptions } from '@octokit/types'
import * as core from '../../../core.js'
import * as core from '../../../core/core.js'

export type RetryOptions = {
doNotRetry?: number[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/
/* istanbul ignore file */

import { info } from '../../../core.js'
import { info } from '../../../core/core.js'

/**
* Invalid characters that cannot be in the artifact name or an uploaded file. Will be rejected
Expand Down
2 changes: 1 addition & 1 deletion src/stubs/artifact/internal/upload/upload-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import fs from 'fs'
import path from 'path'
import { finished } from 'stream/promises'
import { EnvMeta } from '../../../../stubs/env.js'
import * as core from '../../../core.ts'
import * as core from '../../../core/core.ts'
import { FilesNotFoundError, InvalidResponseError } from '../shared/errors.js'
import type {
Artifact,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import * as fs from 'fs'
import { normalize, resolve } from 'path'
import * as core from '../../../core.js'
import * as core from '../../../core/core.js'
import { validateFilePath } from './path-and-artifact-name-validation.js'

export interface UploadZipSpecification {
Expand Down
Loading

0 comments on commit 6b7a9eb

Please sign in to comment.