@@ -70,6 +70,40 @@ function distTag(version) {
7070 return prerelease ? prerelease [ 1 ] : "latest" ;
7171}
7272
73+ function runGit ( args ) {
74+ const result = spawnSync ( "git" , args , {
75+ cwd : root ,
76+ encoding : "utf8" ,
77+ stdio : [ "ignore" , "pipe" , "pipe" ] ,
78+ } ) ;
79+ process . stdout . write ( result . stdout ) ;
80+ process . stderr . write ( result . stderr ) ;
81+ if ( result . status !== 0 ) process . exit ( result . status || 1 ) ;
82+ }
83+
84+ function hasLocalGitTag ( tagName ) {
85+ const result = spawnSync (
86+ "git" ,
87+ [ "rev-parse" , "--verify" , "--quiet" , `refs/tags/${ tagName } ` ] ,
88+ {
89+ cwd : root ,
90+ stdio : "ignore" ,
91+ }
92+ ) ;
93+ return result . status === 0 ;
94+ }
95+
96+ function createGitTag ( tagName ) {
97+ if ( hasLocalGitTag ( tagName ) ) {
98+ console . log ( `Git tag ${ tagName } already exists locally.` ) ;
99+ } else {
100+ runGit ( [ "tag" , tagName , "-m" , tagName ] ) ;
101+ }
102+
103+ // changesets/action parses this line, then pushes the tag and creates the GitHub release.
104+ console . log ( `New tag: ${ tagName } ` ) ;
105+ }
106+
73107const staged = [ ] ;
74108for ( const packageJsonPath of packageJsonPaths ( ) ) {
75109 const pkg = readJson ( packageJsonPath ) ;
@@ -104,6 +138,9 @@ for (const packageJsonPath of packageJsonPaths()) {
104138 if ( result . status !== 0 ) process . exit ( result . status || 1 ) ;
105139
106140 const stageId = result . stdout . match ( / " s t a g e I d " \s * : \s * " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
141+ const tagName = `${ pkg . name } @${ pkg . version } ` ;
142+ createGitTag ( tagName ) ;
143+
107144 staged . push ( {
108145 name : pkg . name ,
109146 version : pkg . version ,
0 commit comments