Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed Oct 7, 2022
1 parent b4a38ef commit edcd7ee
Show file tree
Hide file tree
Showing 72 changed files with 2,184 additions and 4,344 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,33 @@ $ npm install --save env-ci
## Usage

```js
const envCi = require("env-ci");

const { name, service, isCi, branch, commit, tag, build, buildUrl, job, jobUrl, isPr, pr, prBranch, slug, root } =
envCi();
import envCi from "env-ci";

const {
name,
service,
isCi,
branch,
commit,
tag,
build,
buildUrl,
job,
jobUrl,
isPr,
pr,
prBranch,
slug,
root,
} = envCi();

if (isCI) {
console.log(`Building repo ${slug} on ${name} service`);

if (isPr) {
console.log(`Building Pull Request #${pr} originating from branch ${prBranch} and targeting branch ${branch}`);
console.log(
`Building Pull Request #${pr} originating from branch ${prBranch} and targeting branch ${branch}`
);
} else {
console.log(`Building branch ${branch}`);
}
Expand Down
92 changes: 60 additions & 32 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,67 @@
const process = require("process");
const git = require("./services/git.js");
import appveyor from "./services/appveyor.js";
import azurePipelines from "./services/azure-pipelines.js";
import bamboo from "./services/bamboo.js";
import bitbucket from "./services/bitbucket.js";
import bitrise from "./services/bitrise.js";
import buddy from "./services/buddy.js";
import buildkite from "./services/buildkite.js";
import circleci from "./services/circleci.js";
import cirrus from "./services/cirrus.js";
import cloudflarePages from "./services/cloudflare-pages.js";
import codebuild from "./services/codebuild.js";
import codefresh from "./services/codefresh.js";
import codeship from "./services/codeship.js";
import drone from "./services/drone.js";
import git from "./services/git.js";
import github from "./services/github.js";
import gitlab from "./services/gitlab.js";
import jenkins from "./services/jenkins.js";
import netlify from "./services/netlify.js";
import puppet from "./services/puppet.js";
import sail from "./services/sail.js";
import scrutinizer from "./services/scrutinizer.js";
import semaphore from "./services/semaphore.js";
import shippable from "./services/shippable.js";
import teamcity from "./services/teamcity.js";
import travis from "./services/travis.js";
import vela from "./services/vela.js";
import vercel from "./services/vercel.js";
import wercker from "./services/wercker.js";
import woodpecker from "./services/woodpecker.js";

const services = {
appveyor: require("./services/appveyor.js"),
azurePipelines: require("./services/azure-pipelines.js"),
bamboo: require("./services/bamboo.js"),
bitbucket: require("./services/bitbucket.js"),
bitrise: require("./services/bitrise.js"),
buddy: require("./services/buddy.js"),
buildkite: require("./services/buildkite.js"),
circleci: require("./services/circleci.js"),
cirrus: require("./services/cirrus.js"),
cloudflarePages: require("./services/cloudflare-pages.js"),
codebuild: require("./services/codebuild.js"),
codefresh: require("./services/codefresh.js"),
codeship: require("./services/codeship.js"),
drone: require("./services/drone.js"),
github: require("./services/github.js"),
gitlab: require("./services/gitlab.js"),
jenkins: require("./services/jenkins.js"),
netlify: require("./services/netlify.js"),
puppet: require("./services/puppet.js"),
sail: require("./services/sail.js"),
scrutinizer: require("./services/scrutinizer.js"),
semaphore: require("./services/semaphore.js"),
shippable: require("./services/shippable.js"),
teamcity: require("./services/teamcity.js"),
travis: require("./services/travis.js"),
vela: require("./services/vela.js"),
vercel: require("./services/vercel.js"),
wercker: require("./services/wercker.js"),
woodpecker: require("./services/woodpecker.js"),
appveyor,
azurePipelines,
bamboo,
bitbucket,
bitrise,
buddy,
buildkite,
circleci,
cirrus,
cloudflarePages,
codebuild,
codefresh,
codeship,
drone,
github,
gitlab,
jenkins,
netlify,
puppet,
sail,
scrutinizer,
semaphore,
shippable,
teamcity,
travis,
vela,
vercel,
wercker,
woodpecker,
};

module.exports = ({ env = process.env, cwd = process.cwd() } = {}) => {
export default ({ env = process.env, cwd = process.cwd() } = {}) => {
for (const name of Object.keys(services)) {
if (services[name].detect({ env, cwd })) {
return { isCi: true, ...services[name].configuration({ env, cwd }) };
Expand Down
14 changes: 8 additions & 6 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
const execa = require("execa");
import { execa } from "execa";

function head(options) {
export function head(options) {
try {
return execa.sync("git", ["rev-parse", "HEAD"], options).stdout;
} catch {
return undefined;
}
}

function branch(options) {
export function branch(options) {
try {
const headRef = execa.sync("git", ["rev-parse", "--abbrev-ref", "HEAD"], options).stdout;
const headRef = execa.sync(
"git",
["rev-parse", "--abbrev-ref", "HEAD"],
options
).stdout;

if (headRef === "HEAD") {
const branch = execa
Expand All @@ -26,5 +30,3 @@ function branch(options) {
return undefined;
}
}

module.exports = { head, branch };
10 changes: 5 additions & 5 deletions lib/utils.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function prNumber(pr) {
export function prNumber(pr) {
return (/\d+(?!.*\d+)/.exec(pr) || [])[0];
}

function parseBranch(branch) {
return branch ? /^(?:refs\/heads\/)?(?<branch>.+)$/i.exec(branch)[1] : undefined;
export function parseBranch(branch) {
return branch
? /^(?:refs\/heads\/)?(?<branch>.+)$/i.exec(branch)[1]
: undefined;
}

module.exports = { prNumber, parseBranch };
Loading

0 comments on commit edcd7ee

Please sign in to comment.