Skip to content
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
10 changes: 10 additions & 0 deletions __mocks__/@actions/core.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
exportVariable: jest.fn(),
getInput: jest.fn(),
info: jest.fn(),
isDebug: jest.fn(() => process.env['RUNNER_DEBUG'] === '1'),
notice: jest.fn(),
setFailed: jest.fn(),
setOutput: jest.fn(),
warning: jest.fn()
}
30 changes: 30 additions & 0 deletions __mocks__/@actions/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const cp = require('child_process')

module.exports = {
exec: jest.fn(async (command, args = [], options = {}) => {
const {cwd, listeners = {}, ignoreReturnCode = false} = options
const fullCommand =
args && args.length ? `${command} ${args.join(' ')}` : command
return new Promise((resolve, reject) => {
const child = cp.spawn(fullCommand, {
cwd: cwd || process.cwd(),
shell: true,
stdio: ['inherit', 'pipe', 'pipe']
})
child.stdout.on('data', data => {
if (listeners.stdout) listeners.stdout(data)
})
child.stderr.on('data', data => {
if (listeners.stderr) listeners.stderr(data)
})
child.on('close', code => {
if (code !== 0 && !ignoreReturnCode) {
reject(new Error(`Command failed: ${command} (exit ${code})`))
} else {
resolve(code || 0)
}
})
child.on('error', reject)
})
})
}
5 changes: 5 additions & 0 deletions __mocks__/@actions/github.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
context: {
payload: {}
}
}
10 changes: 10 additions & 0 deletions __mocks__/@actions/io.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
mkdirP: jest.fn(dir =>
require('fs/promises')
.mkdir(dir, {recursive: true})
.catch(() => {})
),
rmRF: jest.fn(p =>
require('fs/promises').rm(p, {recursive: true, force: true})
)
}
3 changes: 3 additions & 0 deletions __mocks__/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"type": "commonjs"
}
6 changes: 2 additions & 4 deletions __tests__/execute.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {execute, stdout} from '../src/execute'
import {execute, stdout} from '../src/execute.js'
import {exec} from '@actions/exec'

jest.mock('@actions/exec', () => ({
exec: jest.fn()
}))
jest.mock('@actions/exec')

describe('execute', () => {
it('should be called with the correct arguments when silent mode is enabled', async () => {
Expand Down
19 changes: 5 additions & 14 deletions __tests__/git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ process.env['INPUT_FOLDER'] = 'build'
process.env['GITHUB_SHA'] = '123'

import {mkdirP, rmRF} from '@actions/io'
import {action, Status, TestFlag} from '../src/constants'
import {execute} from '../src/execute'
import {deploy, init} from '../src/git'
import {action, Status, TestFlag} from '../src/constants.js'
import {execute} from '../src/execute.js'
import {deploy, init} from '../src/git.js'
import fs from 'fs'

const originalAction = JSON.stringify(action)
Expand All @@ -14,18 +14,9 @@ jest.mock('fs', () => ({
existsSync: jest.fn()
}))

jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
setOutput: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
}))
jest.mock('@actions/core')

jest.mock('@actions/io', () => ({
rmRF: jest.fn(),
mkdirP: jest.fn()
}))
jest.mock('@actions/io')

jest.mock('../src/execute', () => ({
__esModule: true,
Expand Down
22 changes: 6 additions & 16 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ process.env['GITHUB_REF_NAME'] = 'test'
process.env['RUNNER_OS'] = 'Linux'
process.env['CI'] = 'true'

import '../src/main'
import {action, TestFlag} from '../src/constants'
import run from '../src/lib'
import {execute} from '../src/execute'
import '../src/main.js'
import {action, TestFlag} from '../src/constants.js'
import run from '../src/lib.js'
import {execute} from '../src/execute.js'
import {rmRF} from '@actions/io'
import {setFailed, exportVariable} from '@actions/core'

Expand All @@ -19,19 +19,9 @@ jest.mock('../src/execute', () => ({
execute: jest.fn(() => ({stdout: '', stderr: ''}))
}))

jest.mock('@actions/io', () => ({
rmRF: jest.fn()
}))
jest.mock('@actions/io')

jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
setOutput: jest.fn(),
exportVariable: jest.fn(),
isDebug: jest.fn(),
info: jest.fn(),
notice: jest.fn()
}))
jest.mock('@actions/core')

describe('main', () => {
afterEach(() => {
Expand Down
20 changes: 5 additions & 15 deletions __tests__/ssh.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import {exportVariable} from '@actions/core'
import {mkdirP} from '@actions/io'
import child_process, {execFileSync, execSync} from 'child_process'
import {appendFileSync} from 'fs'
import {action, TestFlag} from '../src/constants'
import {execute} from '../src/execute'
import {configureSSH} from '../src/ssh'
import {action, TestFlag} from '../src/constants.js'
import {execute} from '../src/execute.js'
import {configureSSH} from '../src/ssh.js'

const originalAction = JSON.stringify(action)

Expand All @@ -18,19 +18,9 @@ jest.mock('child_process', () => ({
execSync: jest.fn()
}))

jest.mock('@actions/io', () => ({
rmRF: jest.fn(),
mkdirP: jest.fn()
}))
jest.mock('@actions/io')

jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
setOutput: jest.fn(),
isDebug: jest.fn(),
info: jest.fn(),
exportVariable: jest.fn()
}))
jest.mock('@actions/core')

jest.mock('../src/execute', () => ({
execute: jest.fn(() => ({stdout: '', stderr: ''}))
Expand Down
4 changes: 2 additions & 2 deletions __tests__/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {ActionInterface, TestFlag} from '../src/constants'
import {ActionInterface, TestFlag} from '../src/constants.js'
import {
isNullOrUndefined,
generateTokenType,
Expand All @@ -8,7 +8,7 @@ import {
checkParameters,
stripProtocolFromUrl,
extractErrorMessage
} from '../src/util'
} from '../src/util.js'

describe('util', () => {
describe('isNullOrUndefined', () => {
Expand Down
6 changes: 3 additions & 3 deletions __tests__/worktree.error.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {TestFlag} from '../src/constants'
import {execute} from '../src/execute'
import {generateWorktree} from '../src/worktree'
import {TestFlag} from '../src/constants.js'
import {execute} from '../src/execute.js'
import {generateWorktree} from '../src/worktree.js'

jest.mock('../src/execute', () => ({
__esModule: true,
Expand Down
13 changes: 4 additions & 9 deletions __tests__/worktree.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import {rmRF} from '@actions/io'
import {TestFlag} from '../src/constants'
import {generateWorktree} from '../src/worktree'
import {execute} from '../src/execute'
import {TestFlag} from '../src/constants.js'
import {generateWorktree} from '../src/worktree.js'
import {execute} from '../src/execute.js'
import fs from 'fs'
import os from 'os'
import path from 'path'

jest.mock('@actions/core', () => ({
setFailed: jest.fn(),
getInput: jest.fn(),
isDebug: jest.fn(),
info: jest.fn()
}))
jest.mock('@actions/core')

/*
Test generateWorktree against a known git repository.
Expand Down
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import jest from 'eslint-plugin-jest'

export default tseslint.config(
{
ignores: ['lib/**']
ignores: ['lib/**', '__mocks__/**']
},
eslintConfigPrettier,
jest.configs['flat/recommended'],
Expand Down
12 changes: 10 additions & 2 deletions jest.config.js → jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
moduleNameMapper: {
// Map .js relative imports back to source .ts files for ts-jest
'^(\\.{1,2}/.*)\\.js$': '$1'
},
transform: {
'^.+\\.ts$': 'ts-jest'
'^.+\\.ts$': [
'ts-jest',
{
tsconfig: {module: 'commonjs', moduleResolution: 'node'}
}
]
},
verbose: true,
setupFiles: ['<rootDir>/__tests__/env.js'],
Expand Down
36 changes: 18 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"author": "James Ives <iam@jamesiv.es> (https://jamesiv.es)",
"version": "4.8.0",
"license": "MIT",
"type": "module",
"main": "lib/lib.js",
"types": "lib/lib.d.ts",
"scripts": {
Expand Down Expand Up @@ -35,27 +36,26 @@
"deployment"
],
"dependencies": {
"@actions/core": "2.0.2",
"@actions/exec": "2.0.0",
"@actions/github": "7.0.0",
"@actions/io": "2.0.0",
"@eslint/js": "^9.0.0",
"@actions/core": "3.0.0",
"@actions/exec": "3.0.0",
"@actions/github": "9.0.0",
"@actions/io": "3.0.2",
"@eslint/js": "^10.0.1",
"typescript-eslint": "^8.13.0"
},
"devDependencies": {
"@types/jest": "29.5.14",
"@types/node": "22.15.30",
"@typescript-eslint/eslint-plugin": "8.52.0",
"@typescript-eslint/parser": "8.52.0",
"eslint": "9.28.0",
"@types/jest": "30.0.0",
"@types/node": "25.5.0",
"@typescript-eslint/eslint-plugin": "8.58.0",
"@typescript-eslint/parser": "8.58.0",
"eslint": "10.1.0",
"eslint-config-prettier": "10.1.8",
"eslint-plugin-jest": "29.12.1",
"eslint-plugin-prettier": "5.5.4",
"jest": "29.7.0",
"jest-circus": "30.3.0",
"prettier": "3.5.3",
"rimraf": "6.0.1",
"ts-jest": "29.3.4",
"typescript": "5.8.3"
"eslint-plugin-jest": "29.15.1",
"eslint-plugin-prettier": "5.5.5",
"jest": "30.3.0",
"prettier": "3.8.1",
"rimraf": "6.1.3",
"ts-jest": "29.4.9",
"typescript": "6.0.2"
}
}
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {getInput} from '@actions/core'
import * as github from '@actions/github'
import {isNullOrUndefined, stripProtocolFromUrl} from './util'
import {isNullOrUndefined, stripProtocolFromUrl} from './util.js'

const {pusher, repository} = github.context.payload

Expand Down
14 changes: 8 additions & 6 deletions src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import {
DefaultExcludedFiles,
Status,
TestFlag
} from './constants'
import {execute} from './execute'
import {generateWorktree} from './worktree'
} from './constants.js'
import {execute} from './execute.js'
import {generateWorktree} from './worktree.js'
import {
extractErrorMessage,
isNullOrUndefined,
suppressSensitiveInformation,
getRsyncVersion
} from './util'
} from './util.js'

/**
* Initializes git in the workspace.
Expand Down Expand Up @@ -97,7 +97,8 @@ export async function init(action: ActionInterface): Promise<void | Error> {
`There was an error initializing the repository: ${suppressSensitiveInformation(
extractErrorMessage(error),
action
)} ❌`
)} ❌`,
{cause: error}
)
}
}
Expand Down Expand Up @@ -356,7 +357,8 @@ export async function deploy(action: ActionInterface): Promise<Status> {
`The deploy step encountered an error: ${suppressSensitiveInformation(
extractErrorMessage(error),
action
)} ❌`
)} ❌`,
{cause: error}
)
} finally {
// Cleans up temporary files/folders and restores the git state.
Expand Down
14 changes: 10 additions & 4 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
import {exportVariable, info, notice, setFailed, setOutput} from '@actions/core'
import {action, ActionInterface, NodeActionInterface, Status} from './constants'
import {deploy, init} from './git'
import {configureSSH} from './ssh'
import {
action,
ActionInterface,
NodeActionInterface,
Status
} from './constants.js'
import {deploy, init} from './git.js'
import {configureSSH} from './ssh.js'
import {
checkParameters,
extractErrorMessage,
generateFolderPath,
generateRepositoryPath,
generateTokenType,
isNullOrUndefined
} from './util'
} from './util.js'

/**
* Initializes and runs the action.
*/
export default async function run(
configuration?: ActionInterface | NodeActionInterface
): Promise<void> {
// eslint-disable-next-line no-useless-assignment
let status: Status = Status.RUNNING

try {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import run from './lib'
import run from './lib.js'

run()
Loading
Loading