Skip to content
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

fix: Ensure working directory always starts out at repo root #250

Merged
merged 2 commits into from
Feb 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@ jobs:
MOCK: true
with:
environment: production
working_directory: ../test
working_directory: ./test
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- fix(action): Ensure working directory always starts out at repo root (#250)

## 1.10.1

This release contains changes concerning maintainers of the repo and has no user-facing changes.
Expand Down
21 changes: 21 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
getSetCommitsOption,
getProjects,
getUrlPrefixOption,
getWorkingDirectory,
} from '../src/options';

describe('options', () => {
Expand Down Expand Up @@ -209,6 +210,26 @@ describe('options', () => {
expect(getUrlPrefixOption()).toEqual('build');
});
});

describe('getWorkingDirectory', () => {
afterEach(() => {
delete process.env['GITHUB_WORKSPACE'];
delete process.env['INPUT_WORKING_DIRECTORY'];
});

it('gets the working directory url and prefixes it with the `GITHUB_WORKSPACE`', () => {
process.env['GITHUB_WORKSPACE'] = '/repo/root';
process.env['INPUT_WORKING_DIRECTORY'] = '/some/working/directory';
expect(getWorkingDirectory()).toEqual(
'/repo/root/some/working/directory'
);
});

it('should default to `GITHUB_WORKSPACE` even if no direcotry is passed', () => {
process.env['GITHUB_WORKSPACE'] = '/repo/root';
expect(getWorkingDirectory()).toEqual('/repo/root');
});
});
});

// shows how the runner will run a javascript action with env / stdout protocol
Expand Down
9 changes: 6 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -122852,9 +122852,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getWorkingDirectory = exports.getUrlPrefixOption = exports.getProjects = exports.checkEnvironmentVariables = exports.getSetCommitsOption = exports.getBooleanOption = exports.getDist = exports.getSourcemaps = exports.getStartedAt = exports.getEnvironment = exports.getVersion = void 0;
const core = __importStar(__nccwpck_require__(42186));
const path_1 = __importDefault(__nccwpck_require__(71017));
const cli_1 = __nccwpck_require__(56733);
/**
* Get the release version string from parameter or propose one.
Expand Down Expand Up @@ -123029,9 +123033,8 @@ exports.getUrlPrefixOption = getUrlPrefixOption;
const getWorkingDirectory = () => {
// The action runs inside `github.action_path` and as such
// doesn't automatically have access to the user's git
// In case users don't provide their own `working_directory`
// we use `GITHUB_WORKSPACE` which is at the top of the repo.
return (core.getInput('working_directory') || process.env.GITHUB_WORKSPACE || '');
// We prefix all paths with `GITHUB_WORKSPACE` which is at the top of the repo.
return path_1.default.join(process.env.GITHUB_WORKSPACE || '', core.getInput('working_directory'));
};
exports.getWorkingDirectory = getWorkingDirectory;

Expand Down
9 changes: 5 additions & 4 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as core from '@actions/core';
import path from 'path';
import {getCLI} from './cli';

/**
Expand Down Expand Up @@ -195,9 +196,9 @@ export const getUrlPrefixOption = (): string => {
export const getWorkingDirectory = (): string => {
// The action runs inside `github.action_path` and as such
// doesn't automatically have access to the user's git
// In case users don't provide their own `working_directory`
// we use `GITHUB_WORKSPACE` which is at the top of the repo.
return (
core.getInput('working_directory') || process.env.GITHUB_WORKSPACE || ''
// We prefix all paths with `GITHUB_WORKSPACE` which is at the top of the repo.
return path.join(
process.env.GITHUB_WORKSPACE || '',
core.getInput('working_directory')
);
};