Skip to content

Commit

Permalink
refactor: dist tags to git tags opt
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Feb 19, 2020
1 parent b09c2c5 commit bbf5c71
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/cli/commands/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,14 +109,12 @@ export class Preview extends Command {
distTag: 'next',
version: release.version.version,
},
{ skipNPM: flags['skip-npm'] }
{
skipNPM: flags['skip-npm'],
gitTagForDistTags: true,
}
)

// force update so the tag moves to a new commit
await git.raw(['tag', '-f', 'next'])
await git.raw(['push', 'origin', ':refs/tags/next'])
await git.raw(['push', '--tags'])
console.log('updated git-tag "next"')
return
}

Expand Down
13 changes: 4 additions & 9 deletions src/cli/commands/stable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,11 @@ export class Stable extends Command {
distTag: 'latest',
additiomalDistTags: ['next'],
},
{ skipNPM: flags['skip-npm'] }
{
skipNPM: flags['skip-npm'],
gitTagForDistTags: true,
}
)

// force update so the tag moves to a new commit
await git.raw(['tag', '-f', 'latest'])
await git.raw(['tag', '-f', 'next'])
// https://stackoverflow.com/questions/8044583/how-can-i-move-a-tag-on-a-git-branch-to-a-different-commit
await git.raw(['push', 'origin', ':refs/tags/latest', ':refs/tags/next'])
await git.raw(['push', '--tags'])
console.log('updated git-tags "latest" "next"')
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/utils/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@ type Options = {
*/
gitTagVPrefix?: boolean
skipNPM?: boolean
/**
* Should each given dist tag have a corresponding git tag made?
*/
gitTagForDistTags?: boolean
}

const defaultOpts: Options = {
gitTagVPrefix: false,
skipNPM: false,
gitTagForDistTags: true,
}

type Release = {
Expand Down Expand Up @@ -90,6 +95,23 @@ export async function publish(release: Release, givenOpts?: Options) {
await git.addAnnotatedTag(versionTag, versionTag)
console.log(`tagged this commit with ${versionTag}`)

// Tag the git commit with the given dist tag names
//
if (opts.gitTagForDistTags) {
// todo parallel optimize?
const distTags = [release.distTag, ...(release.additiomalDistTags ?? [])]
for (const distTag of distTags) {
// dist tags are movable pointers. Except for init case it is expected to
// exist in the git repo. So use force to move the tag.
// https://stackoverflow.com/questions/8044583/how-can-i-move-a-tag-on-a-git-branch-to-a-different-commit
// todo provide nice semantic descriptions for each dist tag
await git.raw(['tag', '--force', '--message', distTag, distTag])
await git.raw(['push', 'origin', `:refs/tags/${distTag}`])
console.log('updated git tag %j', distTag)
}
await git.raw(['push', '--tags'])
}

// Push the git commits
//
await git.pushTags()
Expand Down

0 comments on commit bbf5c71

Please sign in to comment.