Skip to content
This repository has been archived by the owner on Jan 20, 2023. It is now read-only.

Commit

Permalink
fix: verify ATOM_ACCESS_TOKEN and apm CLI with JS
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 4, 2018
1 parent 8ad562f commit f7fc4fb
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 11 deletions.
18 changes: 11 additions & 7 deletions index.js
@@ -1,13 +1,17 @@
const execa = require('execa');
const SemanticReleaseError = require('@semantic-release/error');

module.exports = {
verifyConditions: [
{
path: '@semantic-release/exec',
cmd: 'if ! [ -x "$(command -v apm)" ]; then echo "The apm CLI must be installed."; exit 1; fi',
async () => {
if ((await execa('apm', ['-v'], {reject: false})).code !== 0) {
throw new SemanticReleaseError('The apm CLI must be installed.', 'ENOAPMCLI');
}
},
{
path: '@semantic-release/exec',
cmd:
'if [ -z "$ATOM_ACCESS_TOKEN" ]; then echo "The environment variable ATOM_ACCESS_TOKEN is required."; exit 1; fi',
() => {
if (!process.env.ATOM_ACCESS_TOKEN) {
throw new SemanticReleaseError('The environment variable ATOM_ACCESS_TOKEN is required.', 'ENOAPMTOKEN');
}
},
{path: '@semantic-release/npm', npmPublish: false},
'@semantic-release/changelog',
Expand Down
7 changes: 4 additions & 3 deletions package.json
Expand Up @@ -17,10 +17,12 @@
],
"dependencies": {
"@semantic-release/changelog": "^1.0.0",
"@semantic-release/error": "^2.1.0",
"@semantic-release/exec": "^1.0.1",
"@semantic-release/git": "^2.0.1",
"@semantic-release/github": "^3.0.0",
"@semantic-release/npm": "^2.4.0"
"@semantic-release/npm": "^2.4.0",
"execa": "^0.8.0"
},
"devDependencies": {
"ava": "^0.24.0",
Expand All @@ -30,8 +32,6 @@
"dockerode": "^2.5.3",
"eslint-config-prettier": "^2.3.0",
"eslint-plugin-prettier": "^2.3.0",
"execa": "^0.8.0",
"file-url": "^2.0.2",
"fs-extra": "^5.0.0",
"get-stream": "^3.0.0",
"git-log-parser": "^1.2.0",
Expand All @@ -44,6 +44,7 @@
"sinon": "^4.1.2",
"strip-ansi": "^4.0.0",
"tempy": "^0.2.1",
"which": "^1.3.0",
"xo": "^0.18.2"
},
"engines": {
Expand Down
31 changes: 30 additions & 1 deletion test/integration.test.js
@@ -1,8 +1,10 @@
import path from 'path';
import test from 'ava';
import {writeJson, readJson} from 'fs-extra';
import {writeJson, readJson, ensureSymlink} from 'fs-extra';
import {stub} from 'sinon';
import execa from 'execa';
import tempy from 'tempy';
import which from 'which';
import stripAnsi from 'strip-ansi';
import semanticRelease from 'semantic-release';
import {gitCommitedFiles, gitGetCommit} from './helpers/git-utils';
Expand Down Expand Up @@ -175,3 +177,30 @@ test.serial('Throw error if "ATOM_ACCESS_TOKEN" is not set', async t => {
t.is(error.name, 'SemanticReleaseError');
t.is(error.message.trim(), 'The environment variable ATOM_ACCESS_TOKEN is required.');
});

test.serial('Throw error if "apm" is not installed', async t => {
const packageName = 'missing-apm';
const branch = 'master';
const {repositoryUrl} = await gitbox.createRepo(packageName, branch);
process.env.GIT_CREDENTIALS = gitbox.gitCredential;
process.env.GH_TOKEN = 'github_token';
process.env.GITHUB_URL = mockServer.url;
process.env.ATOM_HOME = tempy.directory();
process.env.ATOM_API_URL = mockServer.url;
process.env.ATOM_RESOURCE_PATH = tempy.directory();
// Fake PATH with only git available to make sure apm is not in the PATH
const PATH = tempy.directory();
await ensureSymlink(which.sync('git'), path.join(PATH, 'git'));
process.env.PATH = PATH;
delete process.env.ATOM_ACCESS_TOKEN;
await writeJson('./package.json', {
name: packageName,
version: '0.0.0-dev',
repository: {url: repositoryUrl},
});

const error = await t.throws(semanticRelease({extends: apmConfig}));

t.is(error.name, 'SemanticReleaseError');
t.is(error.message.trim(), 'The apm CLI must be installed.');
});

0 comments on commit f7fc4fb

Please sign in to comment.