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
26 changes: 13 additions & 13 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,14 @@ describe('execute', () => {
await execute();

execCalledWith(mockExec, [
`rm -rdf ${cwd}/__tests__/tmp/.work/build ${cwd}/__tests__/tmp/.work/push`,
'git init \'.\'',
'git remote add origin \'https://test-owner:token@github.com/test-owner/test-repo.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/heads/gh-actions:refs/remotes/origin/gh-actions\' || :',
'git checkout -b gh-actions origin/gh-actions || :',
'git init \'.\'',
'git checkout --orphan gh-actions',
'git init \'.\'',
'git remote add origin \'https://test-owner:token@github.com/test-owner/test-repo.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/heads/master:refs/remotes/origin/master\' || :',
'git checkout -qf FETCH_HEAD',
`rsync -ac -C '--filter=:- .gitignore' --exclude '.git' --exclude '.work' --exclude '.github' --delete './' '${cwd}/__tests__/tmp/.work/build'`,
'rm -rdf node_modules',
'npm install --production',
`mv -f '${cwd}/__tests__/tmp/.work/build/action.yaml' '${cwd}/__tests__/tmp/.work/push/action.yml' > /dev/null 2>&1 || :`,
Expand Down Expand Up @@ -108,6 +106,8 @@ describe('execute', () => {
'git push --tags \'https://test-owner:token@github.com/test-owner/test-repo.git\' \'gh-actions:refs/heads/gh-actions\' > /dev/null 2>&1 || :',
]);
stdoutCalledWith(mockStdout, [
'[command]rm -rdf <Build Directory> <Push Directory>',
' >> stdout',
'::group::Fetching...',
'[command]git init \'.\'',
' >> stdout',
Expand All @@ -127,13 +127,8 @@ describe('execute', () => {
'[command]git checkout --orphan gh-actions',
' >> stdout',
'::endgroup::',
'::group::Cloning the remote repo for build...',
'[command]git init \'.\'',
' >> stdout',
'[command]git remote add origin',
'[command]git fetch --no-tags origin \'refs/heads/master:refs/remotes/origin/master\'',
' >> stdout',
'[command]git checkout -qf FETCH_HEAD',
'::group::Copying current source to build directory...',
'[command]rsync -ac -C \'--filter=:- .gitignore\' --exclude \'.git\' --exclude \'.work\' --exclude \'.github\' --delete \'./\' \'<Build Directory>\'',
' >> stdout',
'::endgroup::',
'::group::Running build for release...',
Expand Down Expand Up @@ -206,6 +201,8 @@ describe('execute', () => {
'token',
'-t',
'test/v1.2.3',
'-b',
'release/v1.2.3',
'-p',
'__tests__/fixtures/test11',
'-w',
Expand All @@ -216,6 +213,7 @@ describe('execute', () => {
await execute();

execCalledWith(mockExec, [
`rm -rdf ${cwd}/__tests__/tmp/.work/build ${cwd}/__tests__/tmp/.work/push`,
'git init \'.\'',
'git remote add origin \'https://test-owner:token@github.com/test-owner/test-repo.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/heads/gh-actions:refs/remotes/origin/gh-actions\' || :',
Expand All @@ -224,7 +222,7 @@ describe('execute', () => {
'git checkout --orphan gh-actions',
'git init \'.\'',
'git remote add origin \'https://test-owner:token@github.com/test-owner/test-repo.git\' > /dev/null 2>&1 || :',
'git fetch --no-tags origin \'refs/heads/master:refs/remotes/origin/master\' || :',
'git fetch --no-tags origin \'refs/heads/release/v1.2.3:refs/remotes/origin/release/v1.2.3\' || :',
'git checkout -qf FETCH_HEAD',
'rm -rdf node_modules',
'npm install --production',
Expand All @@ -247,6 +245,8 @@ describe('execute', () => {
'git show \'--stat-count=10\' HEAD',
]);
stdoutCalledWith(mockStdout, [
'[command]rm -rdf <Build Directory> <Push Directory>',
' >> stdout',
'::group::Fetching...',
'[command]git init \'.\'',
' >> stdout',
Expand All @@ -270,7 +270,7 @@ describe('execute', () => {
'[command]git init \'.\'',
' >> stdout',
'[command]git remote add origin',
'[command]git fetch --no-tags origin \'refs/heads/master:refs/remotes/origin/master\'',
'[command]git fetch --no-tags origin \'refs/heads/release/v1.2.3:refs/remotes/origin/release/v1.2.3\'',
' >> stdout',
'[command]git checkout -qf FETCH_HEAD',
' >> stdout',
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const execute = async(): Promise<void> => {
commander
.requiredOption('--token <token>', 'token')
.requiredOption('-t, --tag <tag>', 'tag name')
.option('-b, --branch [branch]', 'branch name', 'master')
.option('-b, --branch [branch]', 'branch name')
.option('-w, --workspace [workspace]', 'working directory name', '.')
.option('-p, --package [package]', 'package file directory name', process.cwd())
.option('-n, --dry-run', 'show what would have been pushed')
Expand Down
7 changes: 4 additions & 3 deletions src/misc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { readFileSync } from 'fs';
import { resolve } from 'path';
import { Context } from '@actions/github/lib/context';
import { GitHelper, Logger } from '@technote-space/github-action-helper';
import { Config, ContextArgs } from './types';

Expand All @@ -21,17 +22,17 @@ export const getRepository = (dir: string): { owner: string; repo: string } | ne
};
};

export const getContextArgs = (tagName: string, branch: string, config: Config): ContextArgs => ({...config, tagName, branch});
export const getContextArgs = (tagName: string, branch: string | undefined, config: Config): ContextArgs => ({...config, tagName, branch});

export const getContext = (args: ContextArgs): object => ({
export const getContext = (args: ContextArgs): Context => ({
payload: {
action: 'published',
release: {
'tag_name': args.tagName,
},
},
eventName: 'release',
ref: `refs/heads/${args.branch}`,
ref: `refs/heads/${args.branch || 'master'}`,
sha: 'FETCH_HEAD',
workflow: '',
action: '',
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export type ContextArgs = Readonly<{
owner: string;
repo: string;
tagName: string;
branch: string;
branch?: string;
}>;

export type Config = Readonly<{
Expand Down
50 changes: 48 additions & 2 deletions src/wrapper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,58 @@
import { GitHelper } from '@technote-space/github-action-helper';
import { mkdirSync } from 'fs';
import { Context } from '@actions/github/lib/context';
import { GitHelper, Logger, Command } from '@technote-space/github-action-helper';
import * as command from '@technote-space/release-github-actions/lib/utils/command';
import * as misc from '@technote-space/release-github-actions/lib/utils/misc';
import { getContext } from './misc';
import { ContextArgs } from './types';

export const isValidContext = (args: ContextArgs): boolean => misc.isValidContext(getContext(args));

export const prepare = async(helper: GitHelper, args: ContextArgs): Promise<void> => command.prepareCommit(helper, getContext(args));
export const prepareFiles = async(logger: Logger, com: Command, helper: GitHelper, args: ContextArgs, context: Context): Promise<void> => {
const {buildDir, pushDir} = misc.getParams();
mkdirSync(buildDir, {recursive: true});

if (args.branch) {
logger.startProcess('Cloning the remote repo for build...');
await helper.checkout(buildDir, context);
} else {
logger.startProcess('Copying current source to build directory...');
await com.execAsync({
command: 'rsync',
args: [
'-ac',
'-C',
'--filter=:- .gitignore',
'--exclude',
'.git',
'--exclude',
'.work',
'--exclude',
'.github',
'--delete',
'./',
buildDir,
],
});
}

logger.startProcess('Running build for release...');
await helper.runCommand(buildDir, misc.getBuildCommands(buildDir, pushDir));
};

export const prepare = async(helper: GitHelper, args: ContextArgs): Promise<void> => {
const context = getContext(args);
const {buildDir, pushDir} = misc.getParams();
const logger = new Logger(command.replaceDirectory);
const com = new Command(logger);

await com.execAsync({command: `rm -rdf ${buildDir} ${pushDir}`});
await command.clone(helper, context);
await command.checkBranch(await helper.getCurrentBranchName(misc.getParams().pushDir), helper);
await prepareFiles(logger, com, helper, args, context);
await command.createBuildInfoFile(context);
await command.copyFiles();
};

export const commit = async(helper: GitHelper): Promise<void> => {
await command.config(helper);
Expand Down