Skip to content
Open
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
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: 'Push git subdirectory as branch'
description: 'Push a subdirectory as a branch to any git repo over SSH (or to the local repo)'
author: 'Sam Lanning <sam@samlanning.com>'
runs:
using: 'node20'
using: 'node24'
main: 'action/dist/index.js'
branding:
icon: 'upload-cloud'
Expand Down
24,422 changes: 15,172 additions & 9,250 deletions action/dist/index.js

Large diffs are not rendered by default.

7,693 changes: 2,223 additions & 5,470 deletions action/package-lock.json

Large diffs are not rendered by default.

30 changes: 16 additions & 14 deletions action/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@
"test": "./test/bin/run-tests.sh --colors"
},
"devDependencies": {
"@types/git-url-parse": "^9.0.1",
"@types/jest": "^27.4.0",
"@types/node": "^17.0.16",
"@vercel/ncc": "^0.38.1",
"dotenv": "^16.0.0",
"git-url-parse": "^13.1.0",
"jest": "^27.5.1",
"prettier": "^2.3.0",
"ts-jest": "^27.1.3",
"ts-node": "^10.5.0",
"typescript": "^4.5.5"
"@types/git-url-parse": "^16.0.0",
"@types/jest": "^29.5.14",
"@types/node": "^25.9.3",
"@types/normalize-url": "^4.1.0",
"@vercel/ncc": "^0.44.0",
"dotenv": "^17.4.2",
"git-url-parse": "^16.1.0",
"jest": "^29.7.0",
"prettier": "^3.8.4",
"ts-jest": "^29.4.11",
"ts-node": "^10.9.2",
"typescript": "^6.0.3"
},
"dependencies": {
"@actions/io": "^1.1.1",
"fast-glob": "^3.2.11",
"isomorphic-git": "^1.11.2"
"@actions/io": "^2.0.0",
"fast-glob": "^3.3.3",
"isomorphic-git": "^1.38.5",
"normalize-url": "^9.0.1"
}
}
28 changes: 15 additions & 13 deletions action/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const exec = async (
env?: any;
cwd?: string;
log: Console;
}
},
) => {
const { log } = opts;
const env = opts?.env || {};
Expand Down Expand Up @@ -58,12 +58,14 @@ export const exec = async (
ps.on('close', (code) => {
if (code !== 0) {
reject(
new Error('Process exited with code: ' + code + ':\n' + output.stderr)
new Error(
'Process exited with code: ' + code + ':\n' + output.stderr,
),
);
} else {
resolve(output);
}
})
}),
);
};

Expand Down Expand Up @@ -226,7 +228,7 @@ export interface Event {
}

const genConfig: (env?: EnvironmentVariables) => Config = (
env = process.env
env = process.env,
) => {
if (!env.REPO) throw new Error('REPO must be specified');
if (!env.BRANCH) throw new Error('BRANCH must be specified');
Expand Down Expand Up @@ -289,7 +291,7 @@ const writeToProcess = (
env: { [id: string]: string | undefined };
data: string;
log: Console;
}
},
) =>
new Promise<void>((resolve, reject) => {
const child = child_process.spawn(command, args, {
Expand Down Expand Up @@ -331,15 +333,15 @@ export const main = async ({
// Calculate paths that use temp diractory

const TMP_PATH = await fs.mkdtemp(
path.join(tmpdir(), 'git-publish-subdir-action-')
path.join(tmpdir(), 'git-publish-subdir-action-'),
);
const REPO_TEMP = path.join(TMP_PATH, 'repo');
const SSH_AUTH_SOCK = path.join(TMP_PATH, 'ssh_agent.sock');

if (!env.GITHUB_EVENT_PATH) throw new Error('Expected GITHUB_EVENT_PATH');

const event: Event = JSON.parse(
(await fs.readFile(env.GITHUB_EVENT_PATH)).toString()
(await fs.readFile(env.GITHUB_EVENT_PATH)).toString(),
);

const name =
Expand Down Expand Up @@ -382,7 +384,7 @@ export const main = async ({
const next = path.dirname(dir);
if (next === dir) {
log.log(
`##[info] Not running in git directory, unable to get information about source commit`
`##[info] Not running in git directory, unable to get information about source commit`,
);
return {
commitMessage: '',
Expand Down Expand Up @@ -439,7 +441,7 @@ export const main = async ({
log.log(`Setting up ssh-agent on ${SSH_AUTH_SOCK}`);
const sshAgentMatch = SSH_AGENT_PID_EXTRACT.exec(
(await exec(`ssh-agent -a ${SSH_AUTH_SOCK}`, { log, env: childEnv }))
.stdout
.stdout,
);
/* istanbul ignore if */
if (!sshAgentMatch) throw new Error('Unexpected output from ssh-agent');
Expand Down Expand Up @@ -482,7 +484,7 @@ export const main = async ({
/* istanbul ignore if */
if (s.indexOf("Couldn't find remote ref") === -1) {
log.error(
"##[warning] Failed to fetch target branch, probably doesn't exist"
"##[warning] Failed to fetch target branch, probably doesn't exist",
);
log.error(err);
}
Expand Down Expand Up @@ -543,7 +545,7 @@ export const main = async ({
if (env.CLEAR_GLOBS_FILE) {
// We need to use a custom mechanism to clear the files
log.log(
`##[info] Using custom glob file to clear target branch ${env.CLEAR_GLOBS_FILE}`
`##[info] Using custom glob file to clear target branch ${env.CLEAR_GLOBS_FILE}`,
);
const globList = (await fs.readFile(env.CLEAR_GLOBS_FILE))
.toString()
Expand All @@ -553,7 +555,7 @@ export const main = async ({
return globList;
} else if (env.TARGET_DIR) {
log.log(
`##[info] Removing all files from target dir ${env.TARGET_DIR} on target branch`
`##[info] Removing all files from target dir ${env.TARGET_DIR} on target branch`,
);
return [`${env.TARGET_DIR}/**/*`, '!.git'];
} else {
Expand Down Expand Up @@ -635,7 +637,7 @@ export const main = async ({
const tagsArg = tag ? '--tags' : '';
const push = await exec(
`git push ${forceArg} origin "${config.branch}" ${tagsArg}`,
{ log, env: childEnv, cwd: REPO_TEMP }
{ log, env: childEnv, cwd: REPO_TEMP },
);
log.log(push.stdout);
log.log(`##[info] Deployment Successful`);
Expand Down
2 changes: 1 addition & 1 deletion action/test/jest-global-setup-hooks.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
jest.setTimeout(1000 * 60 * 60);
jest.setTimeout(1000 * 60 * 60);
9 changes: 3 additions & 6 deletions action/test/jest-global-setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ import * as path from 'path';
import * as util from './util';

export = async () => {

// Generate known-hosts
await util.exec(
path.join(util.TEST_DIR, 'bin/generate-known-hosts.sh'),
{ cwd: util.DATA_DIR }
);

await util.exec(path.join(util.TEST_DIR, 'bin/generate-known-hosts.sh'), {
cwd: util.DATA_DIR,
});
};
42 changes: 21 additions & 21 deletions action/test/specs/misconfiguration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -81,7 +81,7 @@ describe('Misconfigurations', () => {
try {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes('REPO must be specified')
err.output?.stderr.includes('REPO must be specified'),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand All @@ -106,7 +106,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -115,7 +115,7 @@ describe('Misconfigurations', () => {
try {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes('FOLDER must be specified')
err.output?.stderr.includes('FOLDER must be specified'),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand All @@ -140,7 +140,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -149,7 +149,7 @@ describe('Misconfigurations', () => {
try {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes('BRANCH must be specified')
err.output?.stderr.includes('BRANCH must be specified'),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand Down Expand Up @@ -179,7 +179,7 @@ describe('Misconfigurations', () => {
{
captureOutput: true,
excludeEventPath: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -188,7 +188,7 @@ describe('Misconfigurations', () => {
try {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes('Expected GITHUB_EVENT_PATH')
err.output?.stderr.includes('Expected GITHUB_EVENT_PATH'),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand All @@ -214,7 +214,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -224,8 +224,8 @@ describe('Misconfigurations', () => {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes(
'SSH_PRIVATE_KEY must be specified when REPO uses ssh'
)
'SSH_PRIVATE_KEY must be specified when REPO uses ssh',
),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand All @@ -251,7 +251,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -260,7 +260,7 @@ describe('Misconfigurations', () => {
try {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes('Unsupported REPO URL')
err.output?.stderr.includes('Unsupported REPO URL'),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand Down Expand Up @@ -289,7 +289,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand Down Expand Up @@ -321,7 +321,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -331,8 +331,8 @@ describe('Misconfigurations', () => {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes(
'GITHUB_TOKEN must be specified when REPO == self'
)
'GITHUB_TOKEN must be specified when REPO == self',
),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand All @@ -359,7 +359,7 @@ describe('Misconfigurations', () => {
's0',
{
captureOutput: true,
}
},
)
.then(() => {
throw new Error('Expected error');
Expand All @@ -369,8 +369,8 @@ describe('Misconfigurations', () => {
expect(err.output).toBeDefined();
expect(
err.output?.stderr.includes(
'GITHUB_REPOSITORY must be specified when REPO == self'
)
'GITHUB_REPOSITORY must be specified when REPO == self',
),
).toBeTruthy();
} catch (e) {
console.log(err);
Expand Down
6 changes: 3 additions & 3 deletions action/test/specs/self.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ itGithubOnly('Deploy to another branch on self repo', async () => {
const repo = process.env.GITHUB_SELF_TEST_REPO;
if (!repo)
throw new Error(
'Environment variable GITHUB_SELF_TEST_REPO not set, needed for tests'
'Environment variable GITHUB_SELF_TEST_REPO not set, needed for tests',
);

const token = process.env.GITHUB_SELF_TEST_TOKEN;
if (!token)
throw new Error(
'Environment variable GITHUB_SELF_TEST_TOKEN not set, needed for tests'
'Environment variable GITHUB_SELF_TEST_TOKEN not set, needed for tests',
);

// Create dummy data
Expand All @@ -43,7 +43,7 @@ itGithubOnly('Deploy to another branch on self repo', async () => {
},
repo,
{},
's0'
's0',
);

// Check that the log of the repo is as expected
Expand Down
Loading