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
8 changes: 8 additions & 0 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@
-t v1.2.3
```

[`test`](#test) オプションを設定している場合は不要です。

### オプション
#### branch
ビルドに使用するブランチ名
Expand Down Expand Up @@ -124,6 +126,12 @@
-p /tmp/test-repo
```

#### test
テストモード

タグ名は最新のタグから決まります。
テスト用タグプリフィックスに `test/` が設定されます。

## 設定
`Release GitHub Actions CLI` は `.releasegarc`, `.releasegarc.json`, `.releasegarc.js`, `.releasega.config.js` または `package.json` の `releasega` プロパティで設定できます。

Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ e.g.
-t v1.2.3
```

Not required if [`test`](# test) option is set.

### Option
#### branch
Branch name to use for build.
Expand Down Expand Up @@ -124,6 +126,12 @@ e.g.
-p /tmp/test-repo
```

#### test
Test mode

The tag name is determined from the latest tag.
`test/` is set as the test tag prefix.

## Settings
`Release GitHub Actions CLI` can be configured using `.releasegarc`, `.releasegarc.json`, `.releasegarc.js`, `.releasega.config.js` or `releasega` property in `package.json`.

Expand Down
12 changes: 6 additions & 6 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ describe('getActionDefaultInputs', () => {

describe('getConfig', () => {
it('should get config 1', () => {
expect(getConfig(resolve(fixturesDir, 'test7'))).toEqual({
expect(getConfig(resolve(fixturesDir, 'test7'), undefined)).toEqual({
'inputs': {
'BRANCH_NAME': 'gh-actions',
'BUILD_COMMAND': '',
Expand All @@ -80,7 +80,7 @@ describe('getConfig', () => {
});

it('should get config 2', () => {
expect(getConfig(resolve(fixturesDir, 'test8'))).toEqual({
expect(getConfig(resolve(fixturesDir, 'test8'), false)).toEqual({
'inputs': {
'BRANCH_NAME': 'gh-actions',
'BUILD_COMMAND': '',
Expand All @@ -105,7 +105,7 @@ describe('getConfig', () => {
});

it('should get config 3', () => {
expect(getConfig(resolve(fixturesDir, 'test9'))).toEqual({
expect(getConfig(resolve(fixturesDir, 'test9'), true)).toEqual({
'inputs': {
'BRANCH_NAME': 'gh-actions',
'BUILD_COMMAND': '',
Expand All @@ -122,15 +122,15 @@ describe('getConfig', () => {
'ORIGINAL_TAG_PREFIX': '',
'OUTPUT_BUILD_INFO_FILENAME': '',
'PACKAGE_MANAGER': '',
'TEST_TAG_PREFIX': '',
'TEST_TAG_PREFIX': 'test/',
},
'owner': 'owner9',
'repo': 'repo9',
});
});

it('should get config 4', () => {
expect(getConfig(resolve(fixturesDir, 'test10'))).toEqual({
expect(getConfig(resolve(fixturesDir, 'test10'), undefined)).toEqual({
'inputs': {
'BRANCH_NAME': 'gh-actions',
'BUILD_COMMAND': '',
Expand All @@ -155,7 +155,7 @@ describe('getConfig', () => {
});

it('should get config 5', () => {
expect(getConfig(resolve(fixturesDir, 'test12'))).toEqual({
expect(getConfig(resolve(fixturesDir, 'test12'), undefined)).toEqual({
'inputs': {
'BRANCH_NAME': 'gh-actions',
'BUILD_COMMAND': '',
Expand Down
8 changes: 2 additions & 6 deletions __tests__/env.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ describe('setEnv', () => {
testEnv();

it('should set env 1', () => {
delete process.env.INPUT_GITHUB_TOKEN;
delete process.env.GITHUB_ACTOR;
delete process.env.GITHUB_WORKSPACE;

setEnv({
owner: 'test-owner',
repo: 'test-repo',
}, 'token', '.');
}, '.');

expect(process.env).toHaveProperty('INPUT_GITHUB_TOKEN');
expect(process.env).toHaveProperty('GITHUB_ACTOR');
expect(process.env).toHaveProperty('GITHUB_WORKSPACE');
expect(process.env).not.toHaveProperty('INPUT_COMMIT_NAME');
expect(process.env).not.toHaveProperty('INPUT_FETCH_DEPTH');
});

it('should set env 2', () => {
delete process.env.INPUT_GITHUB_TOKEN;
delete process.env.GITHUB_ACTOR;
delete process.env.GITHUB_WORKSPACE;

Expand All @@ -37,9 +34,8 @@ describe('setEnv', () => {
COMMIT_NAME: 'test name',
FETCH_DEPTH: '5',
},
}, 'token', 'test');
}, 'test');

expect(process.env).toHaveProperty('INPUT_GITHUB_TOKEN');
expect(process.env).toHaveProperty('GITHUB_ACTOR');
expect(process.env).toHaveProperty('GITHUB_WORKSPACE');
expect(process.env).toHaveProperty('INPUT_COMMIT_NAME');
Expand Down
160 changes: 155 additions & 5 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,23 @@ import {
testChildProcess,
spyOnExec,
execCalledWith,
testFs,
testFs, setChildProcessParams,
} from '@technote-space/github-action-test-helper';
import { Logger } from '@technote-space/github-action-helper';
import commander from 'commander';
import { execute } from '../src';

testFs(false);
const saveArgv = process.argv;
const setExists = testFs(false);
const saveArgv = process.argv;
beforeEach(() => {
Logger.resetForTesting();
delete commander.token;
delete commander.package;
delete commander.test;
delete commander.tag;
delete commander.branch;
delete commander.workspace;
delete commander.dryRun;
});

describe('execute', () => {
Expand All @@ -24,7 +32,7 @@ describe('execute', () => {
process.argv = saveArgv;
});

it('should throw error', async() => {
it('should throw error 1', async() => {
process.argv = [
'node',
'index.js',
Expand All @@ -35,6 +43,17 @@ describe('execute', () => {
await expect(execute()).rejects.toThrow('<token> is required.');
});

it('should throw error 2', async() => {
process.argv = [
'node',
'index.js',
'--token',
'token',
];

await expect(execute()).rejects.toThrow('<tag> is required.');
});

it('should do nothing', async() => {
const mockExec = spyOnExec();
const mockStdout = spyOnStdout();
Expand All @@ -55,7 +74,7 @@ describe('execute', () => {
]);
});

it('should push', async() => {
it('should push 1', async() => {
const mockExec = spyOnExec();
const mockStdout = spyOnStdout();
const cwd = process.cwd();
Expand Down Expand Up @@ -201,6 +220,137 @@ describe('execute', () => {
]);
});

it('should push 2', async() => {
const mockExec = spyOnExec();
const mockStdout = spyOnStdout();
const cwd = process.cwd();
process.argv = [
'node',
'index.js',
'--token',
'token',
'-p',
'__tests__/fixtures/test11',
'-w',
'__tests__/tmp',
'--test',
];
setChildProcessParams({
stdout: (command) => {
if (command === 'git tag') {
return 'v1\nv1.2.3\n1.2';
}

return '';
},
});
setExists([false, true, false]);

await execute();

execCalledWith(mockExec, [
'git tag',
`rm -rdf ${cwd}/__tests__/tmp/.work/build ${cwd}/__tests__/tmp/.work/push`,
'git init \'.\'',
'git remote add origin \'https://test-owner:[email protected]/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',
`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 || :`,
`mv -f '${cwd}/__tests__/tmp/.work/build/action.yml' '${cwd}/__tests__/tmp/.work/push/action.yml' > /dev/null 2>&1 || :`,
'rm -rdf .[!.]*',
'rm -rdf *.js',
'rm -rdf *.ts',
'rm -rdf *.json',
'rm -rdf *.lock',
'rm -rdf *.yml',
'rm -rdf *.yaml',
'rm -rdf __tests__ src',
`mv -f '${cwd}/__tests__/tmp/.work/push/action.yml' '${cwd}/__tests__/tmp/.work/build/action.yml' > /dev/null 2>&1 || :`,
`rsync -rl --exclude '.git' --delete '${cwd}/__tests__/tmp/.work/build/' '${cwd}/__tests__/tmp/.work/push'`,
'git config \'user.name\' \'github-actions[bot]\'',
'git config \'user.email\' \'41898282+github-actions[bot]@users.noreply.github.com\'',
'git add --all',
'git commit --allow-empty -qm \'feat: Build for release\'',
'git show \'--stat-count=10\' HEAD',
'git tag',
'git tag -d v1 \'v1.2.3\' \'1.2\' > /dev/null 2>&1',
'git fetch \'https://test-owner:[email protected]/test-owner/test-repo.git\' --tags > /dev/null 2>&1',
'git push \'https://test-owner:[email protected]/test-owner/test-repo.git\' --delete \'tags/test/v1.2.4\' > /dev/null 2>&1 || :',
'git push \'https://test-owner:[email protected]/test-owner/test-repo.git\' --delete \'tags/test/v1.2\' > /dev/null 2>&1 || :',
'git push \'https://test-owner:[email protected]/test-owner/test-repo.git\' --delete tags/test/v1 > /dev/null 2>&1 || :',
'git tag -d \'test/v1.2.4\' || :',
'git tag -d \'test/v1.2\' || :',
'git tag -d test/v1 || :',
'git tag \'test/v1.2.4\'',
'git tag \'test/v1.2\'',
'git tag test/v1',
'git push --tags \'https://test-owner:[email protected]/test-owner/test-repo.git\' \'gh-actions:refs/heads/gh-actions\' > /dev/null 2>&1 || :',
]);
stdoutCalledWith(mockStdout, [
'[command]git tag',
' >> v1',
' >> v1.2.3',
' >> 1.2',
'[command]rm -rdf <Build Directory> <Push Directory>',
'::group::Fetching...',
'[command]git init \'.\'',
'[command]git remote add origin',
'[command]git fetch --no-tags origin \'refs/heads/gh-actions:refs/remotes/origin/gh-actions\'',
'::endgroup::',
'::group::Switching branch to [gh-actions]...',
'[command]git checkout -b gh-actions origin/gh-actions',
'> remote branch gh-actions not found.',
'> now branch: ',
'::endgroup::',
'::group::Initializing local git repo [gh-actions]...',
'[command]git init \'.\'',
'[command]git checkout --orphan gh-actions',
'::endgroup::',
'::group::Copying current source to build directory...',
'[command]rsync -ac -C \'--filter=:- .gitignore\' --exclude \'.git\' --exclude \'.work\' --exclude \'.github\' --delete \'./\' \'<Build Directory>\'',
'::endgroup::',
'::group::Running build for release...',
'[command]rm -rdf node_modules',
'[command]npm install --production',
'[command]rm -rdf .[!.]*',
'[command]rm -rdf *.js',
'[command]rm -rdf *.ts',
'[command]rm -rdf *.json',
'[command]rm -rdf *.lock',
'[command]rm -rdf *.yml',
'[command]rm -rdf *.yaml',
'[command]rm -rdf __tests__ src',
'::endgroup::',
'::group::Copying <Build Directory> contents to <Push Directory>...',
'[command]rsync -rl --exclude \'.git\' --delete \'<Build Directory>/\' \'<Push Directory>\'',
'::endgroup::',
'::group::Configuring git committer to be github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>...',
'[command]git config \'user.name\' \'github-actions[bot]\'',
'[command]git config \'user.email\' \'41898282+github-actions[bot]@users.noreply.github.com\'',
'[command]git add --all',
'[command]git commit --allow-empty -qm \'feat: Build for release\'',
'[command]git show \'--stat-count=10\' HEAD',
'::endgroup::',
'::group::Pushing to test-owner/test-repo@gh-actions (tag: test/v1.2.4)...',
'[command]git fetch origin --tags',
'[command]git push origin --delete tags/test/v1.2.4',
'[command]git push origin --delete tags/test/v1.2',
'[command]git push origin --delete tags/test/v1',
'[command]git tag -d \'test/v1.2.4\'',
'[command]git tag -d \'test/v1.2\'',
'[command]git tag -d test/v1',
'[command]git tag \'test/v1.2.4\'',
'[command]git tag \'test/v1.2\'',
'[command]git tag test/v1',
'[command]git push --tags origin gh-actions:refs/heads/gh-actions',
]);
});

it('should dry run', async() => {
const mockExec = spyOnExec();
const mockStdout = spyOnStdout();
Expand Down
Loading