From 0c45a72f1e7d6f24f93cdf1bd5d2a2cdb2c59757 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sat, 3 Jul 2021 02:07:37 +0900 Subject: [PATCH] feat: build for release --- README.ja.md | 31 ++++++++++++++++++++++++++++++- README.md | 2 ++ build.json | 2 +- lib/utils/command.js | 12 ++++++------ 4 files changed, 39 insertions(+), 8 deletions(-) diff --git a/README.ja.md b/README.ja.md index 98731790..8c9384f3 100644 --- a/README.ja.md +++ b/README.ja.md @@ -270,12 +270,41 @@ jobs: Result: ```shell -Run echo '["yarn.lock"]' | jq . +> Run echo '["yarn.lock"]' | jq . [ "yarn.lock" ] ``` +### 相対パスを指定 + +GitHub Actions は `uses` に `working-directory` を指定できないため、モノレポ構成などで個別に実行したい場合に対応できませんが、`RELATIVE` オプションを指定すると `git diff` の `--relative=` として使用されます。 + +https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---relativeltpathgt + +```yaml +on: pull_request +name: CI +jobs: + dump: + name: Dump + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: technote-space/get-diff-action@v4 + with: + PATTERNS: '*.ts' + RELATIVE: 'src/abc' + - run: echo ${{ env.GIT_DIFF }} +``` + +`src/abc/test1.ts`, `src/abc/test2.ts`, `src/abc/test3.txt`, `src/test4.ts` のファイルがある場合、結果は以下のようになります。 + +```shell +> Run echo 'test1.ts' 'test2.ts' +test1.ts test2.ts +``` + ## Author [GitHub (Technote)](https://github.com/technote-space) diff --git a/README.md b/README.md index df2dd3e7..fa10308b 100644 --- a/README.md +++ b/README.md @@ -276,6 +276,8 @@ Run echo '["yarn.lock"]' | jq . ] ``` +### + ## Author [GitHub (Technote)](https://github.com/technote-space) diff --git a/build.json b/build.json index 503efc8e..2e658a4e 100644 --- a/build.json +++ b/build.json @@ -1 +1 @@ -{"owner":"technote-space","repo":"get-diff-action","sha":"FETCH_HEAD","ref":"refs/heads/master","tagName":"test/v4.1.3","branch":"gh-actions","tags":["test/v4.1.3","test/v4.1","test/v4"],"updated_at":"2021-07-02T15:26:30.615Z"} \ No newline at end of file +{"owner":"technote-space","repo":"get-diff-action","sha":"FETCH_HEAD","ref":"refs/heads/master","tagName":"test/v4.1.3","branch":"gh-actions","tags":["test/v4.1.3","test/v4.1","test/v4"],"updated_at":"2021-07-02T17:07:36.607Z"} \ No newline at end of file diff --git a/lib/utils/command.js b/lib/utils/command.js index 5fe7bd4c..bdb68e4e 100644 --- a/lib/utils/command.js +++ b/lib/utils/command.js @@ -13,7 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); exports.sumResults = exports.getMatchedFiles = exports.getDiffFiles = exports.getGitDiff = exports.getFileDiff = void 0; -const path_1 = __importDefault(require("path")); +const path_1 = require("path"); const core_1 = require("@actions/core"); const multimatch_1 = __importDefault(require("multimatch")); const github_action_helper_1 = require("@technote-space/github-action-helper"); @@ -30,11 +30,11 @@ const escapeWhenJsonFormat = () => github_action_helper_1.Utils.getBoolValue(get const getSeparator = () => getRawInput('SEPARATOR'); const getPatterns = () => github_action_helper_1.Utils.getArrayInput('PATTERNS', undefined, ''); const getFiles = () => github_action_helper_1.Utils.getArrayInput('FILES', undefined, ''); -const getWorkspace = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('ABSOLUTE')) ? (github_action_helper_1.Utils.getWorkspace() + '/') : ''; +const getWorkspace = (relative) => github_action_helper_1.Utils.getBoolValue(core_1.getInput('ABSOLUTE')) ? (path_1.join(github_action_helper_1.Utils.getWorkspace(), relative) + '/') : ''; const getSummaryIncludeFilesFlag = () => github_action_helper_1.Utils.getBoolValue(core_1.getInput('SUMMARY_INCLUDE_FILES')); -const isFilterIgnored = (item, files) => !!(files.length && files.includes(path_1.default.basename(item))); +const isFilterIgnored = (item, files) => !!(files.length && files.includes(path_1.basename(item))); const isMatched = (item, patterns, options) => !patterns.length || !!multimatch_1.default(item, patterns, options).length; -const toAbsolute = (item, workspace) => workspace + item; +const toAbsolute = (item, workspace) => path_1.join(workspace, item); const getMatchOptions = () => ({ nobrace: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NOBRACE')), noglobstar: github_action_helper_1.Utils.getBoolValue(core_1.getInput('MINIMATCH_OPTION_NOGLOBSTAR')), @@ -91,11 +91,11 @@ const getGitDiff = (logger, context) => __awaiter(void 0, void 0, void 0, functi ], github_action_helper_1.Utils.uniqueArray(refs).map(ref => github_action_helper_1.Utils.getRefspec(ref, constant_1.REMOTE_NAME))); const dot = getDot(); const files = getFiles(); - const workspace = getWorkspace(); + const relative = getRelativePath(); + const workspace = getWorkspace(relative); const patterns = getPatterns(); const options = getMatchOptions(); const filter = getFilter(); - const relative = getRelativePath(); return (yield github_action_helper_1.Utils.split((yield command.execAsync({ command: 'git diff', args: [