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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@
/coverage
/lib
.eslintcache
.work
3 changes: 2 additions & 1 deletion README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@

### オプション
#### branch
ビルドに使用するブランチ名
ビルドに使用するブランチ名
このオプションが指定されていない場合、現在のソースコードが使用されます。

例:
```
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ e.g.
### Option
#### branch
Branch name to use for build.
If this option is not specified, the current source code will be used.

e.g.
```
Expand Down
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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@technote-space/release-github-actions-cli",
"version": "1.0.1",
"version": "1.1.0",
"description": "Release GitHub Actions Cli",
"author": {
"name": "Technote",
Expand Down
17 changes: 8 additions & 9 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ export const normalizeConfigKeys = (config: { [key: string]: string }): { [key:
})));

/* istanbul ignore next */
const getActionSettingFile = (): string =>
existsSync(resolve(__dirname, '../../release-github-actions/action.yml')) ?
resolve(__dirname, '../../release-github-actions/action.yml') :
resolve(__dirname, '../node_modules/@technote-space/release-github-actions/action.yml');
const getActionSettingFile = (): string => existsSync(resolve(__dirname, '../../release-github-actions/action.yml')) ?
resolve(__dirname, '../../release-github-actions/action.yml') :
resolve(__dirname, '../node_modules/@technote-space/release-github-actions/action.yml');

export const getActionDefaultInputs = (): { [key: string]: string } => {
const actionSetting = yaml.safeLoad(readFileSync(getActionSettingFile(), 'utf8'));
Expand All @@ -35,18 +34,18 @@ export const getConfig = (dir: string): Config | never => {
delete config.OWNER;
}

if ('REPO' in config) {
config.repo = config.REPO;
delete config.REPO;
}

if (!('owner' in config)) {
config.owner = owner;
}

if (!('repo' in config)) {
config.repo = repo;
}

if ('REPO' in config) {
config.repo = config.REPO;
delete config.REPO;
}
}

return {...config, inputs: {...getActionDefaultInputs(), ...normalizeConfigKeys(config.inputs ?? config.INPUTS ?? {})}};
Expand Down
1 change: 0 additions & 1 deletion src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Config } from './types';
export const setEnv = (config: Config, token: string, workspace: string): void => {
process.env.INPUT_GITHUB_TOKEN = token;
process.env.GITHUB_ACTOR = config.owner;
// eslint-disable-next-line no-magic-numbers
process.env.GITHUB_WORKSPACE = resolve(process.cwd(), workspace);

if (config.inputs) {
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