Skip to content

Commit

Permalink
feat: GitHub Actions support
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m authored and pvdlg committed Jun 7, 2019
1 parent 543e7d6 commit 30d5175
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/verify.js
Expand Up @@ -27,6 +27,7 @@ const VALIDATORS = {

module.exports = async (pluginConfig, context) => {
const {
env,
options: {repositoryUrl},
logger,
} = context;
Expand All @@ -52,6 +53,14 @@ module.exports = async (pluginConfig, context) => {
} else if (githubToken && !errors.find(({code}) => code === 'EINVALIDPROXY')) {
const github = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});

// https://github.com/semantic-release/github/issues/182
// Do not check for permissions in GitHub actions, as the provided token is an installation access token.
// github.repos.get({repo, owner}) does not return the "permissions" key in that case. But GitHub Actions
// have all permissions required for @semantic-release/github to work
if (env.GITHUB_ACTION) {
return;
}

try {
const {
data: {
Expand Down
20 changes: 20 additions & 0 deletions test/verify.test.js
Expand Up @@ -323,6 +323,26 @@ test.serial('Verify "assignees" is a String', async t => {
t.true(github.isDone());
});

// https://github.com/semantic-release/github/issues/182
test.serial('Verify if run in GitHub Action', async t => {
const owner = 'test_user';
const repo = 'test_repo';
const env = {GITHUB_TOKEN: 'v1.1234567890123456789012345678901234567890', GITHUB_ACTION: 'Release'};
const proxy = 'https://localhost';
const assets = [{path: 'lib/file.js'}, 'file.js'];
const successComment = 'Test comment';
const failTitle = 'Test title';
const failComment = 'Test comment';
const labels = ['semantic-release'];

await t.notThrowsAsync(
verify(
{proxy, assets, successComment, failTitle, failComment, labels},
{env, options: {repositoryUrl: `git+https://othertesturl.com/${owner}/${repo}.git`}, logger: t.context.logger}
)
);
});

test('Throw SemanticReleaseError for missing github token', async t => {
const [error] = await t.throwsAsync(
verify(
Expand Down

0 comments on commit 30d5175

Please sign in to comment.