Skip to content

Commit

Permalink
Fix GitHub action tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattgauntseo-sentry committed Sep 29, 2022
1 parent 224a32d commit e6fd2d4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ jobs:
node-version: 12
- run: yarn install
- run: yarn lint
- run: yarn build
- run: yarn test
28 changes: 26 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,35 @@ test('wait 500 ms', async () => {
});

// shows how the runner will run a javascript action with env / stdout protocol
test('test runs', () => {
test('test runs', async () => {
process.env['INPUT_MILLISECONDS'] = '500';
const ip = path.join(__dirname, '..', 'lib', 'main.js');
const options: cp.ExecSyncOptions = {
env: process.env,
};
console.log(cp.execSync(`node ${ip}`, options).toString());

const result = await new Promise<{stdout: string, stderr: string, err: cp.ExecException|null}>((resolve) => {
// cp.execSync will throw an error if the command returns a non-zeo
// status, which may or may no happen depending on the environment
// this test is run (i.e. locally vs on a GitHub Action).
cp.exec(`node ${ip}`, options, (err, stdout, stderr) => {
resolve({
stdout,
stderr,
err,
});
});
});
// The error returned locally is different from the error we get when running in an action.
// However, both will be prefixed with `::error::` by the @actions/core library.
expect(result.stdout).toContain('::error::');
expect(result.stderr).toContain('');

// Depending on whether we run locally or on a GitHub action we get
// different results.
if (result.err) {
console.log('An error was returned by lib/main.js:', result.err);
} else {
console.log(`No error returned by lib/main.js`)
}
});
8 changes: 4 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13330,12 +13330,12 @@ function run() {
new RegExp('requires.*https://github.com/([^/]+)/([^/]+)/pull/(\\d+)', 'im');
const matches = (_a = sourcePullRequest === null || sourcePullRequest === void 0 ? void 0 : sourcePullRequest.data.body) === null || _a === void 0 ? void 0 : _a.match(textPatternRegex);
if (!matches) {
core.debug('No match, nothing to do here...');
core.info('No match, nothing to do here...');
return;
}
// If exactRepo was passed, then ensure that the link that was parsed matches it
if (exactRepo && `${matches[1]}/${matches[2]}` !== exactRepo) {
core.debug(`Exact repo does not match. '${exactRepo}' vs '${matches[1]}/${matches[2]}'`);
core.info(`Exact repo does not match. '${exactRepo}' vs '${matches[1]}/${matches[2]}'`);
return;
}
const [, targetOwner, targetRepo, targetPullRequestNumber] = matches;
Expand All @@ -13351,11 +13351,11 @@ function run() {
number: pullRequest.data.number,
pullRequest: JSON.stringify(pullRequest.data),
};
core.debug('Set the following outputs:');
core.info('Set the following outputs:');
// Can't use merge commit here because of `bin/bump-sentry`
for (const k of Object.keys(outputs)) {
const v = outputs[k];
core.debug(`${k}: '${v}'`);
core.info(`${k}: '${v}'`);
core.setOutput(k, v);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ async function run(): Promise<void> {
const matches = sourcePullRequest?.data.body?.match(textPatternRegex);

if (!matches) {
core.debug('No match, nothing to do here...');
core.info('No match, nothing to do here...');
return;
}

// If exactRepo was passed, then ensure that the link that was parsed matches it
if (exactRepo && `${matches[1]}/${matches[2]}` !== exactRepo) {
core.debug(
core.info(
`Exact repo does not match. '${exactRepo}' vs '${matches[1]}/${matches[2]}'`
);
return;
Expand All @@ -69,11 +69,11 @@ async function run(): Promise<void> {
pullRequest: JSON.stringify(pullRequest.data),
} as {[key: string]: string | number};

core.debug('Set the following outputs:');
core.info('Set the following outputs:');
// Can't use merge commit here because of `bin/bump-sentry`
for (const k of Object.keys(outputs)) {
const v = outputs[k];
core.debug(`${k}: '${v}'`);
core.info(`${k}: '${v}'`);
core.setOutput(k, v);
}
} catch (error) {
Expand Down

0 comments on commit e6fd2d4

Please sign in to comment.