Skip to content

Commit

Permalink
Support GitHub Actions (#621)
Browse files Browse the repository at this point in the history
  • Loading branch information
vinsidious authored and webpro committed Mar 23, 2020
1 parent 260efed commit 6a41042
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/plugin/github/GitHub.js
Expand Up @@ -32,6 +32,14 @@ class GitHub extends Release {

async init() {
await super.init();

// 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) {
this.setContext({ github: { username: process.env.GITHUB_ACTOR } });
return;
}

if (!(await this.isAuthenticated())) {
throw new GitHubClientError(
`Could not authenticate with GitHub using environment variable "${this.options.tokenRef}".`
Expand Down
19 changes: 19 additions & 0 deletions test/github.js
Expand Up @@ -137,6 +137,25 @@ 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';

const options = { github: { tokenRef, remoteUrl, host } };
const github = factory(GitHub, { options });
const authStub = sinon.stub(github, 'isAuthenticated');
const collaboratorStub = sinon.stub(github, 'isCollaborator');

await t.notThrowsAsync(github.init());

t.is(authStub.callCount, 0);
t.is(collaboratorStub.callCount, 0);

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

process.env.GITHUB_ACTION = '';
});

test('should handle octokit client error (without retries)', async t => {
const github = factory(GitHub, { options: { github: { tokenRef, remoteUrl, host } } });
const stub = sinon.stub(github.client.repos, 'createRelease');
Expand Down
1 change: 1 addition & 0 deletions test/util/setup.js
Expand Up @@ -12,4 +12,5 @@ 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 = '';
});

0 comments on commit 6a41042

Please sign in to comment.