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

Support GitHub Actions #621

Merged
merged 8 commits into from Mar 19, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 = '';
});