Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
feat(publishing): extend config to support custom remote origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergei Orlov committed Mar 1, 2020
1 parent 0565223 commit c032f4e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ PREFIX=v priestine-semantics
* `--publish-tag[=<true|false>]` - if true, @priestine/semantics will attempt to publish release tag to the platform. Defaults to **true**.
* `--oldest-commits-first[=<true|false>]` - if true, commits in the release notes will be sorted chronologically, oldest to latest. Defaults to **true**.
* `--tag-message[=<true|false>]` - if true, tag release notes will be generated and added as release message when publishing. Defaults to **true**.
* `--prefix=<value>` - set prefix for newly created version (e.g. `--prefix=v -> v1.0.0`)
* `--postfix=<value>` - set postfix for newly created version (e.g. `--postfix=-beta -> 1.0.0-beta`)
* `--prefix=<value>` - set prefix for newly created version (e.g. `--prefix=v -> v1.0.0`).
* `--postfix=<value>` - set postfix for newly created version (e.g. `--postfix=-beta -> 1.0.0-beta`).
* `--write-to-changelog[=<true|false>]` - if true, tag release notes will be prepended to ./CHANGELOG.md. Defaults to **true**.
* `--origin=<value>` - custom remote origin to push release tag to. If not specified, updates are pushed to the current repository.
* `--write-temporary-files[=<true|false>]` - if true, @priestine/semantics will create temporary files containing the data gathered during its execution (**NOTE**: temporary files are not generated if there are no reasons for version bumping)
* `--precise-version-matching[=<true|false>]` - if true, @priestine/semantics will look for previous versions with given prefix and/or postfix instead of just looking for any previous SemVer-like tag. This is helpful for leading several changelogs for various types of releases.
* `--exclude-merges[=<true|false>]` - if true, merge request commits will be excluded when evaluating changes since latest version. Defaults to **true**.
Expand All @@ -137,8 +139,10 @@ PREFIX=v priestine-semantics
* `PUBLISH_TAG=<true|false>` - if true, @priestine/semantics will attempt to publish release tag to the platform. Defaults to **true**.
* `OLDEST_COMMITS_FIRST=<true|false>` - if true, commits in the release notes will be sorted chronologically, oldest to latest. Defaults to **true**.
* `TAG_MESSAGE=<true|false>` - if true, tag release notes will be generated and added as release message when publishing. Defaults to **true**.
* `PREFIX=<value>` - set prefix for newly created version (e.g. `PREFIX=v -> v1.0.0`)
* `POSTFIX=<value>` - set postfix for newly created version (e.g. `POSTFIX=-beta -> 1.0.0-beta`)
* `PREFIX=<value>` - set prefix for newly created version (e.g. `PREFIX=v -> v1.0.0`).
* `POSTFIX=<value>` - set postfix for newly created version (e.g. `POSTFIX=-beta -> 1.0.0-beta`).
* `WRITE_TO_CHANGELOG=<true|false>` - if true, tag release notes will be prepended to ./CHANGELOG.md. Defaults to **true**.
* `ORIGIN=<value>` - custom remote origin to push release tag to. If not specified, updates are pushed to the current repository.
* `WRITE_TEMPORARY_FILES=<true|false>` - if true, @priestine/semantics will create temporary files containing the data gathered during its execution (**NOTE**: temporary files are not generated if there are no reasons for version bumping)
* `PRECISE_VERSION_MATCHING=<true|false>` - if true, @priestine/semantics will look for previous versions with given prefix and/or postfix instead of just looking for any previous SemVer-like tag. This is helpful for leading several changelogs for various types of releases.
* `EXCLUDE_MERGES=<true|false>` - if true, merge request commits will be excluded when evaluating changes since latest version. Defaults to **true**.
Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ GatherConfigPipeline.concat(GitCommandsPipeline)
preciseVersionMatching: true,
excludeMerges: true,
writeToChangelog: true,
origin: '',
} as SemanticsIntermediate)
.catch((e) => {
Log.error(e);
Expand Down
9 changes: 9 additions & 0 deletions src/interfaces/config.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ export interface ConfigInterface {
*/
postfix: string;

/**
* Custom remote git origin to push tags to. If it is not specified, updates are pushed to the current
* repository. This option may be useful when mirroring repositories, e.g. using Gitlab CI for a Github
* project. Providing authentication credentials is optional. The origin MUST be using HTTP, not SSH.
*
* @default ""
*/
origin: string;

/**
* Relative or absolute path to the directory where @priestine/semantics should look for config files.
*
Expand Down
9 changes: 6 additions & 3 deletions src/middleware/publish-tag-if-required.middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export function publishTagIfRequired({ intermediate }: SemanticsCtx) {
return intermediate;
}

const origin = execSync('git config --get remote.origin.url', { encoding: 'utf8' });
const origin = intermediate.origin
? intermediate.origin
: execSync('git config --get remote.origin.url', { encoding: 'utf8' });
const branch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' });

if (!origin.includes('@')) {
Expand All @@ -39,6 +41,7 @@ export function publishTagIfRequired({ intermediate }: SemanticsCtx) {
execSync(`git push origin ${branch}`);
}

execPromise(`git tag -am "${intermediate.tagMessageContents}" ${intermediate.newVersion}`)
.then(() => execPromise(`git push origin ${intermediate.newVersion}`));
execPromise(`git tag -am "${intermediate.tagMessageContents}" ${intermediate.newVersion}`).then(() =>
execPromise(`git push origin ${intermediate.newVersion}`)
);
}

0 comments on commit c032f4e

Please sign in to comment.