Skip to content

Commit

Permalink
feat: native ES Module (#236)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This package is now pure ESM

BREAKING CHANGE: Minimal required Node.js version is now 16.10
  • Loading branch information
gr2m committed Oct 7, 2022
1 parent 566f465 commit 189b621
Show file tree
Hide file tree
Showing 74 changed files with 2,252 additions and 4,385 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- uses: actions/setup-node@v3
with:
cache: npm
node-version: 16
node-version: "lts/*"
- run: npm ci
- run: npx semantic-release
env:
Expand Down
9 changes: 3 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,8 @@ jobs:
matrix:
node-version:
# minimal required version
- "12.20"
# minimal required version for latest semantic-release
- 14.17
# latest LTS version
- 16
- 16.10
- 18

runs-on: ubuntu-latest

Expand All @@ -45,7 +42,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: "lts/*"
cache: npm
- run: npm clean-install
- name: Ensure dependencies are compatible with the version of node
Expand Down
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
23 changes: 14 additions & 9 deletions lib/git.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,27 @@
const execa = require("execa");
import { execaSync } from "execa";

function head(options) {
export function head(options) {
try {
return execa.sync("git", ["rev-parse", "HEAD"], options).stdout;
return execaSync("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 = execaSync(
"git",
["rev-parse", "--abbrev-ref", "HEAD"],
options
).stdout;

if (headRef === "HEAD") {
const branch = execa
.sync("git", ["show", "-s", "--pretty=%d", "HEAD"], options)
const branch = execaSync(
"git",
["show", "-s", "--pretty=%d", "HEAD"],
options
)
.stdout.replace(/^\(|\)$/g, "")
.split(", ")
.find((branch) => branch.startsWith("origin/"));
Expand All @@ -26,5 +33,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 };

0 comments on commit 189b621

Please sign in to comment.