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 6eaa5c1 commit 3d67bdc
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
15 changes: 10 additions & 5 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 16 additions & 12 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ 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, working_directory } = fetchInputs();
const { workspaces, fallback, token, base_ref, head_ref, working_directory } =
fetchInputs();

const octokit = github.getOctokit(token);
const context = github.context;
Expand Down Expand Up @@ -63,14 +64,12 @@ async function fetchTree(
return tree;
}

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);
})
);
function filterTree(
tree: string[],
workspaces: string[],
working_directory: string
): string[] {
const filtered_tree = tree.filter(x => workspaces.some(w => x.startsWith(w)));
const crate_paths = filtered_tree
.filter(x => x.endsWith('Cargo.toml'))
.map(x => {
Expand Down Expand Up @@ -101,11 +100,18 @@ function fetchInputs() {
if (!token) {
throw new Error('No Github token provided');
}
const working_directory = core.getInput('working-directory') || '';

const workspaces: string[] = JSON.parse(core.getInput('workspaces'));
let workspaces: string[] = JSON.parse(core.getInput('workspaces'));
if (!workspaces || !Array.isArray(workspaces)) {
throw new Error('workspaces is not a valid JSON array');
}
// Add working-directory to workspaces
workspaces = workspaces.map(w =>
working_directory.length > 0
? `${working_directory}/${w}`.replace(/\/$/, '')
: w
);

const fallback_input = core.getInput('fallback');
let fallback: string[];
Expand All @@ -119,8 +125,6 @@ function fetchInputs() {
const base_ref = core.getInput('base_ref');
const head_ref = core.getInput('head_ref');

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

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

Expand Down

0 comments on commit 3d67bdc

Please sign in to comment.