Skip to content

Commit

Permalink
feat: update to cjs modern format
Browse files Browse the repository at this point in the history
  • Loading branch information
0-vortex committed May 16, 2023
1 parent 56a1f81 commit fc897e4
Show file tree
Hide file tree
Showing 5 changed files with 209 additions and 213 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ COPY package.json /
RUN npm i -g npm@latest
RUN npm i -g $( jq -j '.dependencies|to_entries|map("\(.key)@\(.value) ")|.[]' /package.json )

COPY release.config.js /usr/local/lib/release.config.js
COPY release.config.cjs /usr/local/lib/release.config.cjs

RUN apk add --update make \
&& rm -rf /var/cache/apk/* \
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"version": "10.1.0",
"license": "MIT",
"files": [
"release.config.js"
"release.config.cjs"
],
"main": "release.config.js",
"main": "release.config.cjs",
"author": "TED Vortex <ted.vortex@gmail.com>",
"engines": {
"node": ">=18",
Expand All @@ -17,7 +17,7 @@
"url": "git+ssh://git@github.com/0-vortex/open-sauced-semantic-config-test.git"
},
"peerDependencies": {
"semantic-release": ">=19.0.0"
"semantic-release": ">=21.0.0"
},
"dependencies": {
"@google/semantic-release-replace-plugin": "^1.2.0",
Expand Down
204 changes: 204 additions & 0 deletions release.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,204 @@
(async function () {
const { existsSync } = (await import("fs"));
const { execaSync, execaCommandSync } = (await import("execa"))
const { resolve } = (await import("path"));
const log = require("npmlog");

const plugins = [];
const noteKeywords = [
"BREAKING CHANGE",
"BREAKING CHANGES",
"BREAKING"
];
const {
GITHUB_SHA,
GITHUB_REPOSITORY,
GIT_COMMITTER_NAME,
GIT_COMMITTER_EMAIL,
GIT_AUTHOR_NAME,
GIT_AUTHOR_EMAIL,
} = process.env;
const successCmd = `echo 'RELEASE_TAG=v\${nextRelease.version}' >> "$GITHUB_ENV"
echo 'RELEASE_VERSION=\${nextRelease.version}' >> "$GITHUB_ENV"
echo 'release-tag=v\${nextRelease.version}' >> "$GITHUB_OUTPUT"
echo 'release-version=\${nextRelease.version}' >> "$GITHUB_OUTPUT"`;
const [owner, repo] = String(GITHUB_REPOSITORY).toLowerCase().split("/");
const addPlugin = (plugin, options) => {
log.info(`${plugin} enabled ${options && 'with options:'}`);
options && log.info(null, options);
return plugins.push([plugin, options]);
};

log.info(`Executing semantic-release config setup`);

!GIT_COMMITTER_NAME && (process.env.GIT_COMMITTER_NAME = "open-sauced[bot]");
!GIT_COMMITTER_EMAIL && (process.env.GIT_COMMITTER_EMAIL = "63161813+open-sauced[bot]@users.noreply.github.com");

try {
const {stdout: authorName} = execaSync("git", ["log", "-1", "--pretty=format:%an", GITHUB_SHA]);
const {stdout: authorEmail} = execaSync("git", ["log", "-1", "--pretty=format:%ae", GITHUB_SHA]);
authorName && !GIT_AUTHOR_NAME && (process.env.GIT_AUTHOR_NAME = `${authorName}`);
authorEmail && !GIT_AUTHOR_EMAIL && (process.env.GIT_AUTHOR_EMAIL = `${authorEmail}`);
} catch (e) {
log.error(`Unable to set GIT_COMMITTER_NAME and GIT_COMMITTER_EMAIL`, e);
}

addPlugin("@semantic-release/commit-analyzer", {
"preset": "conventionalcommits",
"releaseRules": [
{breaking: true, release: "major"},
{type: "feat", release: "minor"},
{type: "fix", release: "patch"},
{type: "perf", release: "patch"},
{type: "revert", release: "patch"},
{type: "docs", release: "minor"},
{type: "style", release: "patch"},
{type: "refactor", release: "patch"},
{type: "test", release: "patch"},
{type: "build", release: "patch"},
{type: "ci", release: "patch"},
{type: "chore", release: false}
],
"parserOpts": {
noteKeywords
}
});

addPlugin("@semantic-release/release-notes-generator", {
"preset": "conventionalcommits",
"parserOpts": {
noteKeywords
},
"writerOpts": {
"commitsSort": ["subject", "scope"]
},
"presetConfig": {
types: [
{type: "feat", section: "🍕 Features"},
{type: "feature", section: "🍕 Features"},
{type: "fix", section: "🐛 Bug Fixes"},
{type: "perf", section: "🔥 Performance Improvements"},
{type: "revert", section: "⏩ Reverts"},
{type: "docs", section: "📝 Documentation"},
{type: "style", section: "🎨 Styles"},
{type: "refactor", section: "🧑‍💻 Code Refactoring"},
{type: "test", section: "✅ Tests"},
{type: "build", section: "🤖 Build System"},
{type: "ci", section: "🔁 Continuous Integration"}
]
}
});

addPlugin("@semantic-release/changelog", {
"changelogTitle": `# 📦 ${owner}/${repo} changelog
[![conventional commits](https://img.shields.io/badge/conventional%20commits-1.0.0-yellow.svg)](https://conventionalcommits.org)
[![semantic versioning](https://img.shields.io/badge/semantic%20versioning-2.0.0-green.svg)](https://semver.org)
> All notable changes to this project will be documented in this file`
});

addPlugin("@semantic-release/npm", {
"tarballDir": "pack"
});

const actionExists = existsSync("./action.yml");
if (actionExists) {
addPlugin("@google/semantic-release-replace-plugin", {
"replacements": [{
"files": [
"action.yml"
],
"from": `image: 'docker://ghcr.io/${owner}/${repo}:.*'`,
"to": `image: 'docker://ghcr.io/${owner}/${repo}:\${nextRelease.version}'`,
"results": [{
"file": "action.yml",
"hasChanged": true,
"numMatches": 1,
"numReplacements": 1
}],
"countMatches": true
}]
});
}

try {
const {stdout} = execaCommandSync("ls -A1 LICENSE*", {
shell: true,
});

addPlugin("semantic-release-license", {
license: {
path: resolve(stdout)
}
});
} catch (e) {
log.error(`Unable to run detect license command`, e);
}

addPlugin("@semantic-release/git", {
"assets": [
"LICENSE*",
"CHANGELOG.md",
"package.json",
"package-lock.json",
"npm-shrinkwrap.json",
"yarn.lock",
"pnpm-lock.yaml",
"public/**/*",
"supabase/**/*",
"action.yml"
],
"message": `chore(<%= nextRelease.type %>): release <%= nextRelease.version %> <%= nextRelease.channel !== null ? \`on \${nextRelease.channel} channel \` : '' %>[skip ci]\n\n<%= nextRelease.notes %>`
});

addPlugin("@semantic-release/github", {
"addReleases": "bottom",
"assets": [
{
"path": "pack/*.tgz",
"label": "Static distribution"
}
]
});

const dockerExists = existsSync("./Dockerfile");
if (dockerExists) {
addPlugin("eclass-docker-fork", {
"baseImageName": `${owner}/${repo}`,
"registries": [
{
"url": "ghcr.io",
"imageName": `ghcr.io/${owner}/${repo}`,
"user": "GITHUB_REPOSITORY_OWNER",
"password": "GITHUB_TOKEN"
}
]
});
}

if (process.env.GITHUB_ACTIONS !== undefined) {
addPlugin("@semantic-release/exec", {
successCmd,
});
}

module.exports = {
"branches": [
"+([0-9])?(.{+([0-9]),x}).x",
"main",
"next",
"next-major",
{
name: "beta",
prerelease: true
},
{
name: "alpha",
prerelease: true
}
],
plugins,
}

})();

0 comments on commit fc897e4

Please sign in to comment.