Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config to provide git push options #3159

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ async function run(context, plugins) {
cwd,
env,
});
await push(options.repositoryUrl, { cwd, env });
await pushNotes(options.repositoryUrl, nextRelease.gitTag, {
await push(options.repositoryUrl, options.gitPushOptions, { cwd, env });
await pushNotes(options.repositoryUrl, options.gitPushOptions, nextRelease.gitTag, {
cwd,
env,
});
Expand Down Expand Up @@ -207,8 +207,8 @@ async function run(context, plugins) {
// Create the tag before calling the publish plugins as some require the tag to exists
await tag(nextRelease.gitTag, nextRelease.gitHead, { cwd, env });
await addNote({ channels: [nextRelease.channel] }, nextRelease.gitTag, { cwd, env });
await push(options.repositoryUrl, { cwd, env });
await pushNotes(options.repositoryUrl, nextRelease.gitTag, { cwd, env });
await push(options.repositoryUrl, options.gitPushOptions, { cwd, env });
await pushNotes(options.repositoryUrl, options.gitPushOptions, nextRelease.gitTag, { cwd, env });
logger.success(`Created tag ${nextRelease.gitTag}`);
}

Expand Down
1 change: 1 addition & 0 deletions lib/get-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export default async (context, cliOptions) => {
"@semantic-release/npm",
"@semantic-release/github",
],
gitPushOptions: [],
// Remove `null` and `undefined` options, so they can be replaced with default ones
...pickBy(options, (option) => !isNil(option)),
...(options.branches ? { branches: castArray(options.branches) } : {}),
Expand Down
16 changes: 12 additions & 4 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,12 @@ export async function tag(tagName, ref, execaOptions) {
*
* @throws {Error} if the push failed.
*/
export async function push(repositoryUrl, execaOptions) {
await execa("git", ["push", "--tags", repositoryUrl], execaOptions);
export async function push(repositoryUrl, gitPushOptions, execaOptions) {
let localGitPushOptions = [];
for (let gitPushOption of gitPushOptions) {
localGitPushOptions.push('-o', gitPushOption);
}
await execa("git", ["push", "--tags", ...localGitPushOptions, repositoryUrl], execaOptions);
}

/**
Expand All @@ -243,8 +247,12 @@ export async function push(repositoryUrl, execaOptions) {
*
* @throws {Error} if the push failed.
*/
export async function pushNotes(repositoryUrl, ref, execaOptions) {
await execa("git", ["push", repositoryUrl, `refs/notes/${GIT_NOTE_REF}-${ref}`], execaOptions);
export async function pushNotes(repositoryUrl, gitPushOptions, ref, execaOptions) {
let localGitPushOptions = [];
for (let gitPushOption of gitPushOptions) {
localGitPushOptions.push('-o', gitPushOption);
}
await execa("git", ["push", ...localGitPushOptions, repositoryUrl, `refs/notes/${GIT_NOTE_REF}-${ref}`], execaOptions);
}

/**
Expand Down