Skip to content

Commit

Permalink
Use GITHUB_ACTIONS env var + un/set in test setup
Browse files Browse the repository at this point in the history
  • Loading branch information
webpro committed Mar 19, 2020
1 parent b6dc6ff commit 262b9d0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion lib/plugin/github/GitHub.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class GitHub extends Release {

// If we're running on GitHub Actions, we can skip the authentication and
// collaborator checks. Ref: https://bit.ly/2vsyRzu
if (process.env.GITHUB_ACTION) {
if (process.env.GITHUB_ACTIONS) {
this.setContext({ github: { username: process.env.GITHUB_ACTOR } });
return;
}
Expand Down
14 changes: 8 additions & 6 deletions test/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const tokenRef = 'GITHUB_TOKEN';
const remoteUrl = 'git://github.com:user/repo';
const host = 'github.com';

test('should validate token', async t => {
test.serial('should validate token', async t => {
const tokenRef = 'MY_GITHUB_TOKEN';
const options = { github: { release: true, tokenRef, remoteUrl } };
const github = factory(GitHub, { options });
Expand Down Expand Up @@ -137,10 +137,11 @@ test('should throw for non-collaborator', async t => {
stub.restore();
});

test('should skip authentication and collaborator checks when running on GitHub Actions', async t => {
process.env.GITHUB_ACTION = 'run4';
test.serial('should skip authentication and collaborator checks when running on GitHub Actions', async t => {
process.env.GITHUB_ACTIONS = 1;
process.env.GITHUB_ACTOR = 'release-it';

const options = { github: { tokenRef, remoteUrl, host } };
const options = { github: { tokenRef } };
const github = factory(GitHub, { options });
const authStub = sinon.stub(github, 'isAuthenticated');
const collaboratorStub = sinon.stub(github, 'isCollaborator');
Expand All @@ -149,11 +150,12 @@ test('should skip authentication and collaborator checks when running on GitHub

t.is(authStub.callCount, 0);
t.is(collaboratorStub.callCount, 0);
t.is(github.getContext('github.username'), 'release-it');

authStub.restore();
collaboratorStub.restore();

process.env.GITHUB_ACTION = '';
delete process.env.GITHUB_ACTIONS;
delete process.env.GITHUB_ACTOR;
});

test('should handle octokit client error (without retries)', async t => {
Expand Down
5 changes: 3 additions & 2 deletions test/util/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ const test = require('ava');
shelljs.config.silent = true;
nock.disableNetConnect();

const { GITHUB_TOKEN, GITLAB_TOKEN } = process.env;
const { GITHUB_TOKEN, GITLAB_TOKEN, GITHUB_ACTIONS, GITHUB_ACTOR } = process.env;

process.env.GITHUB_TOKEN = process.env.GITLAB_TOKEN = 1;

test.after.always(() => {
process.env.GITHUB_TOKEN = GITHUB_TOKEN;
process.env.GITLAB_TOKEN = GITLAB_TOKEN;
process.env.GITHUB_ACTION = '';
process.env.GITHUB_ACTIONS = GITHUB_ACTIONS;
process.env.GITHUB_ACTOR = GITHUB_ACTOR;
});

0 comments on commit 262b9d0

Please sign in to comment.