Skip to content

Commit

Permalink
feat(build-workspace-matrix): add 'relative_to_path' argument (#31)
Browse files Browse the repository at this point in the history
This allows the returned results to be made relative to a particular path, instead of the repository root
  • Loading branch information
mdobosz-isp authored Sep 2, 2020
1 parent 19fe31b commit 3be5120
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
5 changes: 5 additions & 0 deletions build-workspace-matrix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ A particular workspace to return when the event type is `workflow_dispatch`.

A newline-separated list of globs representing dependencies of each workspace. If any of the dependencies have changed then all workspaces will be returned.

### `relative_to_path`

If provided, results will be relative to the given path

## Outputs

### `matrix`
Expand Down Expand Up @@ -124,3 +128,4 @@ jobs:
github-token: ${{secrets.GITHUB_TOKEN}}
# A matrix with a single value provided by the input is returned
workflow_dispatch_workspace: ${{ github.event.inputs.workspace }}
```
3 changes: 3 additions & 0 deletions build-workspace-matrix/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ inputs:
global_dependencies:
description: "A newline-separated list of globs representing dependencies of each workspace. If any of the dependencies have changed then all workspaces will be returned. Applies only to 'push' and 'pull_request' events."
required: false
relative_to_path:
description: "If provided, results will be relative to the given path"
required: false
outputs:
matrix:
description: "The matrix object of the shape: { workspace: [] }"
Expand Down
2 changes: 1 addition & 1 deletion build-workspace-matrix/dist/index.js

Large diffs are not rendered by default.

17 changes: 12 additions & 5 deletions build-workspace-matrix/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import * as minimatch from "minimatch";

(async function run() {
try {
const result = await getWorkspaces();
let result = await getWorkspaces();
console.log(
`Found ${result.length} impacted workspaces: ${result.join(", ")}`
);

const relativeToPath = getInput("relative_to_path");
if (relativeToPath) {
console.log(`Making relative to ${relativeToPath}`);
result = result.map(makeRelative(relativeToPath));
}
setOutput("matrix", { workspace: result });
} catch (error) {
setFailed(error.message);
Expand All @@ -29,7 +35,9 @@ async function getWorkspaces(): Promise<string[]> {
const workspaceGlobber = await glob.create(workspaceGlobs, {
implicitDescendants: false,
});
const workspaces = (await workspaceGlobber.glob()).map(makeRelative());
const workspaces = (await workspaceGlobber.glob()).map(
makeRelative(process.cwd())
);

info(`Found matching workspaces: ${workspaces.join(", ")}`);

Expand Down Expand Up @@ -101,9 +109,8 @@ async function changedFiled(): Promise<string[]> {
return response.data.files.map((file) => file.filename);
}

function makeRelative() {
const cwd = process.cwd();
function makeRelative(from: string) {
return function (path: string) {
return relative(cwd, path);
return relative(from, path);
};
}

0 comments on commit 3be5120

Please sign in to comment.