Skip to content

Commit

Permalink
feat: add working_directory
Browse files Browse the repository at this point in the history
  • Loading branch information
loispostula committed Feb 2, 2024
1 parent 06748a8 commit 6eaa5c1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ inputs:
description:
'Fallback value in case no file inside the given workspaces were changed'
required: false
working-directory:
description:
'Subdirectory where the root Cargo.toml is'
required: false

outputs:
matrix:
Expand Down
19 changes: 14 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ type OctoKit = InstanceType<typeof GitHub>;
* @returns {Promise<void>} Resolves when the action is complete.
*/
async function run() {
const { workspaces, fallback, token, base_ref, head_ref } = fetchInputs();
const { workspaces, fallback, token, base_ref, head_ref, working_directory } = fetchInputs();

const octokit = github.getOctokit(token);
const context = github.context;
Expand All @@ -28,7 +28,7 @@ async function run() {

const tree = await fetchTree(octokit, context, head_ref);
debugArray('Tree:', tree);
const crate_paths = filterTree(tree, workspaces);
const crate_paths = filterTree(tree, workspaces, working_directory);
debugArray('Crate paths:', crate_paths);
const diff = await fetchDiff(octokit, context, base_ref, head_ref);
debugArray('Changed files:', diff);
Expand Down Expand Up @@ -63,8 +63,14 @@ async function fetchTree(
return tree;
}

function filterTree(tree: string[], workspaces: string[]): string[] {
const filtered_tree = tree.filter(x => workspaces.some(w => x.startsWith(w)));
function filterTree(tree: string[], workspaces: string[], working_directory: string): string[] {
const filtered_tree = tree.filter(x =>
workspaces.some(w => {
const workspace_path =
working_directory.length > 0 ? `${working_directory}/${w}` : w;
return x.startsWith(workspace_path);
})
);
const crate_paths = filtered_tree
.filter(x => x.endsWith('Cargo.toml'))
.map(x => {
Expand Down Expand Up @@ -112,7 +118,10 @@ function fetchInputs() {
// todo: we can fetch these 2 ourselves
const base_ref = core.getInput('base_ref');
const head_ref = core.getInput('head_ref');
return { workspaces, fallback, token, base_ref, head_ref };

const working_directory = core.getInput('working-directory');

return { workspaces, fallback, token, base_ref, head_ref, working_directory };
}

function setOutput(matrix: string[], fallback = false) {
Expand Down

0 comments on commit 6eaa5c1

Please sign in to comment.