Skip to content

Commit

Permalink
v9 (#639)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `@semantic-release/github` is now a native ES Module

BREAKING CHANGE: Node 14 and 16 are no longer supported
  • Loading branch information
gr2m committed Jun 2, 2023
1 parent d78b44a commit a589e18
Show file tree
Hide file tree
Showing 43 changed files with 14,548 additions and 13,900 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/test.yml
Expand Up @@ -13,8 +13,9 @@ jobs:
strategy:
matrix:
node-version:
- '14.17'
- 16
- 18.0.0
- 19
- 20
os:
- ubuntu-latest
runs-on: "${{ matrix.os }}"
Expand All @@ -25,19 +26,22 @@ jobs:
with:
node-version: "${{ matrix.node-version }}"
cache: npm
- run: npm ci
- run: "npm run test:ci"
- run: npm clean-install
- run: npm test
test:
runs-on: ubuntu-latest
needs: test_matrix
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3
- uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3
with:
node-version: 16
node-version: "lts/*"
cache: npm
- run: npm ci
- run: npm clean-install
- run: npm audit signatures
- name: Ensure dependencies are compatible with the version of node
run: npx ls-engines
- run: npm run lint
- run: npx lockfile-lint --path package-lock.json
# https://github.com/lirantal/lockfile-lint#readme
- name: Scan lockfile for security issues
run: npx lockfile-lint --path package-lock.json
56 changes: 29 additions & 27 deletions README.md

Large diffs are not rendered by default.

90 changes: 62 additions & 28 deletions index.js
@@ -1,67 +1,101 @@
/* eslint require-atomic-updates: off */

const {defaultTo, castArray} = require('lodash');
const verifyGitHub = require('./lib/verify');
const addChannelGitHub = require('./lib/add-channel');
const publishGitHub = require('./lib/publish');
const successGitHub = require('./lib/success');
const failGitHub = require('./lib/fail');
import { defaultTo, castArray } from "lodash-es";

import verifyGitHub from "./lib/verify.js";
import addChannelGitHub from "./lib/add-channel.js";
import publishGitHub from "./lib/publish.js";
import successGitHub from "./lib/success.js";
import failGitHub from "./lib/fail.js";
import { SemanticReleaseOctokit } from "./lib/octokit.js";

let verified;

async function verifyConditions(pluginConfig, context) {
const {options} = context;
export async function verifyConditions(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {}
) {
const { options } = context;
// If the GitHub publish plugin is used and has `assets`, `successComment`, `failComment`, `failTitle`, `labels` or `assignees` configured, validate it now in order to prevent any release if the configuration is wrong
if (options.publish) {
const publishPlugin =
castArray(options.publish).find((config) => config.path && config.path === '@semantic-release/github') || {};
castArray(options.publish).find(
(config) => config.path && config.path === "@semantic-release/github"
) || {};

pluginConfig.assets = defaultTo(pluginConfig.assets, publishPlugin.assets);
pluginConfig.successComment = defaultTo(pluginConfig.successComment, publishPlugin.successComment);
pluginConfig.failComment = defaultTo(pluginConfig.failComment, publishPlugin.failComment);
pluginConfig.failTitle = defaultTo(pluginConfig.failTitle, publishPlugin.failTitle);
pluginConfig.successComment = defaultTo(
pluginConfig.successComment,
publishPlugin.successComment
);
pluginConfig.failComment = defaultTo(
pluginConfig.failComment,
publishPlugin.failComment
);
pluginConfig.failTitle = defaultTo(
pluginConfig.failTitle,
publishPlugin.failTitle
);
pluginConfig.labels = defaultTo(pluginConfig.labels, publishPlugin.labels);
pluginConfig.assignees = defaultTo(pluginConfig.assignees, publishPlugin.assignees);
pluginConfig.assignees = defaultTo(
pluginConfig.assignees,
publishPlugin.assignees
);
}

await verifyGitHub(pluginConfig, context);
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}

async function publish(pluginConfig, context) {
export async function publish(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {}
) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}

return publishGitHub(pluginConfig, context);
return publishGitHub(pluginConfig, context, { Octokit });
}

async function addChannel(pluginConfig, context) {
export async function addChannel(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {}
) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}

return addChannelGitHub(pluginConfig, context);
return addChannelGitHub(pluginConfig, context, { Octokit });
}

async function success(pluginConfig, context) {
export async function success(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {}
) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}

await successGitHub(pluginConfig, context);
await successGitHub(pluginConfig, context, { Octokit });
}

async function fail(pluginConfig, context) {
export async function fail(
pluginConfig,
context,
{ Octokit = SemanticReleaseOctokit } = {}
) {
if (!verified) {
await verifyGitHub(pluginConfig, context);
await verifyGitHub(pluginConfig, context, { Octokit });
verified = true;
}

await failGitHub(pluginConfig, context);
await failGitHub(pluginConfig, context, { Octokit });
}

module.exports = {verifyConditions, addChannel, publish, success, fail};
85 changes: 57 additions & 28 deletions lib/add-channel.js
@@ -1,52 +1,81 @@
const debug = require('debug')('semantic-release:github');
const {RELEASE_NAME} = require('./definitions/constants');
const parseGithubUrl = require('./parse-github-url');
const resolveConfig = require('./resolve-config');
const getClient = require('./get-client');
const isPrerelease = require('./is-prerelease');

module.exports = async (pluginConfig, context) => {
import debugFactory from "debug";

import { RELEASE_NAME } from "./definitions/constants.js";
import parseGithubUrl from "./parse-github-url.js";
import resolveConfig from "./resolve-config.js";
import isPrerelease from "./is-prerelease.js";
import { toOctokitOptions } from "./octokit.js";

const debug = debugFactory("semantic-release:github");

export default async function addChannel(pluginConfig, context, { Octokit }) {
const {
options: {repositoryUrl},
options: { repositoryUrl },
branch,
nextRelease: {name, gitTag, notes},
nextRelease: { name, gitTag, notes },
logger,
} = context;
const {githubToken, githubUrl, githubApiPathPrefix, proxy} = resolveConfig(pluginConfig, context);
const {owner, repo} = parseGithubUrl(repositoryUrl);
const octokit = getClient({githubToken, githubUrl, githubApiPathPrefix, proxy});
const { githubToken, githubUrl, githubApiPathPrefix, proxy } = resolveConfig(
pluginConfig,
context
);
const { owner, repo } = parseGithubUrl(repositoryUrl);
const octokit = new Octokit(
toOctokitOptions({
githubToken,
githubUrl,
githubApiPathPrefix,
proxy,
})
);
let releaseId;

const release = {owner, repo, name, prerelease: isPrerelease(branch), tag_name: gitTag};
const release = {
owner,
repo,
name,
prerelease: isPrerelease(branch),
tag_name: gitTag,
};

debug('release object: %O', release);
debug("release object: %O", release);

try {
({
data: {id: releaseId},
} = await octokit.request('GET /repos/{owner}/{repo}/releases/tags/{tag}', {owner, repo, tag: gitTag}));
data: { id: releaseId },
} = await octokit.request("GET /repos/{owner}/{repo}/releases/tags/{tag}", {
owner,
repo,
tag: gitTag,
}));
} catch (error) {
if (error.status === 404) {
logger.log('There is no release for tag %s, creating a new one', gitTag);
logger.log("There is no release for tag %s, creating a new one", gitTag);

const {
data: {html_url: url},
} = await octokit.request('POST /repos/{owner}/{repo}/releases', {...release, body: notes});
data: { html_url: url },
} = await octokit.request("POST /repos/{owner}/{repo}/releases", {
...release,
body: notes,
});

logger.log('Published GitHub release: %s', url);
return {url, name: RELEASE_NAME};
logger.log("Published GitHub release: %s", url);
return { url, name: RELEASE_NAME };
}

throw error;
}

debug('release release_id: %o', releaseId);
debug("release release_id: %o", releaseId);

const {
data: {html_url: url},
} = await octokit.request('PATCH /repos/{owner}/{repo}/releases/{release_id}', {...release, release_id: releaseId});
data: { html_url: url },
} = await octokit.request(
"PATCH /repos/{owner}/{repo}/releases/{release_id}",
{ ...release, release_id: releaseId }
);

logger.log('Updated GitHub release: %s', url);
logger.log("Updated GitHub release: %s", url);

return {url, name: RELEASE_NAME};
};
return { url, name: RELEASE_NAME };
}
6 changes: 2 additions & 4 deletions lib/definitions/constants.js
@@ -1,5 +1,3 @@
const ISSUE_ID = '<!-- semantic-release:github -->';
export const ISSUE_ID = "<!-- semantic-release:github -->";

const RELEASE_NAME = 'GitHub release';

module.exports = {ISSUE_ID, RELEASE_NAME};
export const RELEASE_NAME = "GitHub release";

0 comments on commit a589e18

Please sign in to comment.