Skip to content

Release/v0.7.7 #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 22, 2020
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
20 changes: 10 additions & 10 deletions .github/workflows/sync-workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ jobs:
with:
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
EXECUTE_COMMANDS: |
rm -rdf ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp
mkdir -p ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp
cp -f ${{ env.GITHUB_WORKSPACE }}/.github/workflows/sync-workflows.yml ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp/ > /dev/null 2>&1 || :
rm -f ${{ env.GITHUB_WORKSPACE }}/.github/workflows/*.yml
git clone --depth=1 https://github.com/technote-space/github-actions-workflows.git ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp/workflows
cp ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp/workflows/ts-repo/*.yml ${{ env.GITHUB_WORKSPACE }}/.github/workflows/
cp -f ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp/sync-workflows.yml ${{ env.GITHUB_WORKSPACE }}/.github/workflows/sync-workflows.yml > /dev/null 2>&1 || :
sed -i 's/cron:.\+$/cron: 0 17 * * */' ${{ env.GITHUB_WORKSPACE }}/.github/workflows/update-dependencies.yml
rm -rdf ${{ env.GITHUB_WORKSPACE }}/.github/workflows/.tmp
rm -rdf .github/workflows/.tmp
mkdir -p .github/workflows/.tmp
cp -f .github/workflows/sync-workflows.yml .github/workflows/.tmp/ > /dev/null 2>&1 || :
rm -f .github/workflows/*.yml
git clone --depth=1 https://github.com/technote-space/github-actions-workflows.git .github/workflows/.tmp/workflows
cp .github/workflows/.tmp/workflows/ts-repo/*.yml .github/workflows/
cp -f .github/workflows/.tmp/sync-workflows.yml .github/workflows/sync-workflows.yml > /dev/null 2>&1 || :
sed -i 's/cron:.\+$/cron: 0 17 * * */' .github/workflows/update-dependencies.yml
rm -rdf .github/workflows/.tmp
COMMIT_MESSAGE: 'chore: sync workflows'
PR_BRANCH_PREFIX: chore/
PR_BRANCH_NAME: 'chore-sync-workflows-${PR_ID}'
PR_BRANCH_NAME: 'chore-sync-workflows'
PR_TITLE: 'chore: sync workflows'
ONLY_DEFAULT_BRANCH: true
12 changes: 12 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,18 @@ describe('getArrayInput', () => {
expect(getArrayInput('test', false, '')).toEqual(['test1', 'test2 && test3', 'test4']);
});

it('should unique', () => {
process.env.INPUT_TEST = 'test1\ntest2 && test3\n\ntest2';

expect(getArrayInput('test', false, '&&')).toEqual(['test1', 'test2', 'test3']);
});

it('should not unique', () => {
process.env.INPUT_TEST = 'test1\ntest2 && test3\n\ntest2';

expect(getArrayInput('test', false, '&&', false)).toEqual(['test1', 'test2', 'test3', 'test2']);
});

it('should throw error', () => {
expect(() => {
getArrayInput('test', true);
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/github-action-helper",
"version": "0.7.6",
"version": "0.7.7",
"description": "Helper to filter GitHub Action.",
"author": "Technote <[email protected]> (https://technote.space)",
"license": "MIT",
Expand Down
7 changes: 6 additions & 1 deletion src/git-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,12 @@ export default class GitHelper {
if (!isCloned(workDir)) {
return '';
}
return (await this.runCommand(workDir, {command: 'git rev-parse', args: ['--abbrev-ref', 'HEAD']}))[0].stdout[0]?.trim() ?? '';
return (await this.runCommand(workDir, {
command: 'git rev-parse',
args: ['--abbrev-ref', 'HEAD'],
suppressError: true,
stderrToStdout: true,
}))[0].stdout[0]?.trim() ?? '';
};

/**
Expand Down
11 changes: 7 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ export const getWorkspace = (): string => process.env.GITHUB_WORKSPACE || '';

export const split = (value: string, separator: string | RegExp = /\r?\n/, limit?: number): string[] => value.length ? value.split(separator, limit) : [];

export const getArrayInput = (name: string, required = false, separator = ','): string[] => uniqueArray<string>(getInput(name, {required}).split(/\r?\n/).reduce<string[]>(
(acc, line) => acc.concat(separator ? line.split(separator) : line).filter(item => item).map(item => item.trim()),
[],
));
export const getArrayInput = (name: string, required = false, separator = ',', unique = true): string[] => {
const arrayInput = getInput(name, {required}).split(/\r?\n/).reduce<string[]>(
(acc, line) => acc.concat(separator ? line.split(separator) : line).filter(item => item).map(item => item.trim()),
[],
);
return unique ? uniqueArray<string>(arrayInput) : arrayInput;
};

export const sleep = async(millisecond: number): Promise<void> => new Promise(resolve => setTimeout(resolve, millisecond));

Expand Down