From 89dc0f7f751114d4f44aa6d0ddd71639137d2657 Mon Sep 17 00:00:00 2001 From: ealush Date: Tue, 26 Apr 2022 11:06:43 -0400 Subject: [PATCH] vx: create git tags from changes --- vx/commands/release.js | 4 +- ...oLatestBranch.js => commitChangesToGit.js} | 40 ++++++++++++++----- vx/scripts/release/steps/create_git_tag.sh | 10 +++++ 3 files changed, 42 insertions(+), 12 deletions(-) rename vx/scripts/release/steps/{pushToLatestBranch.js => commitChangesToGit.js} (68%) create mode 100644 vx/scripts/release/steps/create_git_tag.sh diff --git a/vx/commands/release.js b/vx/commands/release.js index f3794dace..50ea1cf61 100644 --- a/vx/commands/release.js +++ b/vx/commands/release.js @@ -1,4 +1,4 @@ -const pushToLatestBranch = require('../scripts/release/steps/pushToLatestBranch'); +const commitChangesToGit = require('../scripts/release/steps/commitChangesToGit'); const build = require('vx/commands/build'); const logger = require('vx/logger'); @@ -49,5 +49,5 @@ async function releaseAll() { return; } - pushToLatestBranch(); + commitChangesToGit(); } diff --git a/vx/scripts/release/steps/pushToLatestBranch.js b/vx/scripts/release/steps/commitChangesToGit.js similarity index 68% rename from vx/scripts/release/steps/pushToLatestBranch.js rename to vx/scripts/release/steps/commitChangesToGit.js index 07251a8f1..0d45f0023 100644 --- a/vx/scripts/release/steps/pushToLatestBranch.js +++ b/vx/scripts/release/steps/commitChangesToGit.js @@ -11,33 +11,44 @@ const logger = require('vx/logger'); const packageNames = require('vx/packageNames'); const vxPath = require('vx/vxPath'); -const SCRIPT_PATH = path.resolve( +const RELEASE_SCRIPTS = path.resolve( vxPath.VX_SCRIPTS_PATH, 'release', - 'steps', + 'steps' +); + +const PUSH_TO_LATEST_BRANCH = path.resolve( + RELEASE_SCRIPTS, 'push_to_latest_branch.sh' ); +const CREATE_GIT_TAG = path.resolve(RELEASE_SCRIPTS, 'create_git_tag.sh'); + const EMOJIS = ['🚀', '🦺', '🤘', '✨', '🌈', '✅']; -function pushToLatestBranch() { +function commitChangesToGit() { logger.info('🌎 Pushing latest branch.'); const allChanges = listAllChangesSinceStableBranch(); const changedPackages = filterChangedPackages(allChanges); + + pushToLatestBranch(allChanges, changedPackages); + createTags(changedPackages); +} + +module.exports = commitChangesToGit; + +function pushToLatestBranch(allChanges, changedPackages) { const messages = allChanges.map(({ title }) => title); - const command = [ + + exec([ 'sh', - SCRIPT_PATH, + PUSH_TO_LATEST_BRANCH, `"${createCommitMessage(changedPackages)}"`, `"${messages.join('\n')}"`, - ].join(' '); - - exec(command); + ]); } -module.exports = pushToLatestBranch; - function filterChangedPackages(commits) { return packageNames.list.filter(packageName => { return commits.some(({ title, files }) => { @@ -60,3 +71,12 @@ function createCommitMessage(changedPackages) { return `${sample(EMOJIS)} Updating: ${msg}`; } + +function createTags(changedPackages) { + return changedPackages.forEach(packageName => { + const version = packageJson(packageName).version; + const tag = `${packageName}@${version}`; + + exec(['sh', CREATE_GIT_TAG, tag]); + }); +} diff --git a/vx/scripts/release/steps/create_git_tag.sh b/vx/scripts/release/steps/create_git_tag.sh new file mode 100644 index 000000000..10f714ed5 --- /dev/null +++ b/vx/scripts/release/steps/create_git_tag.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +git config --global user.email $EMAIL_ADDRESS --replace-all +git config --global user.name $GIT_NAME + +echo "Creating Git Tag: $1" +git tag -a "$1" -m "$1" + +echo "Pushing Git Tag: $1" +git push origin $1 \ No newline at end of file