11/* eslint-disable no-console */
2+ import execa from 'execa' ;
23import { copy } from 'fs-extra' ;
34
45import {
@@ -10,13 +11,22 @@ import {
1011 REPO_URL ,
1112 ensureGitHubToken ,
1213} from '../../common' ;
13- import { getLanguageFolder } from '../../config' ;
14- import { cloneRepository , configureGitHubAuthor } from '../../release/common' ;
14+ import { getLanguageFolder , getPackageVersionDefault } from '../../config' ;
15+ import {
16+ cloneRepository ,
17+ configureGitHubAuthor ,
18+ RELEASED_TAG ,
19+ } from '../../release/common' ;
1520import type { Language } from '../../types' ;
1621import { getNbGitDiff } from '../utils' ;
1722
1823import text from './text' ;
1924
25+ const IS_RELEASE_COMMIT =
26+ process . env . HEAD_COMMIT_MESSAGE ?. startsWith (
27+ text . commitPrepareReleaseMessage
28+ ) || false ;
29+
2030export function decideWhereToSpread ( commitMessage : string ) : Language [ ] {
2131 if ( commitMessage . startsWith ( 'chore: release' ) ) {
2232 return [ ] ;
@@ -77,6 +87,21 @@ async function spreadGeneration(): Promise<void> {
7787 const commitMessage = cleanUpCommitMessage ( lastCommitMessage ) ;
7888 const langs = decideWhereToSpread ( lastCommitMessage ) ;
7989
90+ // At this point, we know the release will happen on every clients
91+ // So we want to set the released tag at the monorepo level too.
92+ if ( IS_RELEASE_COMMIT ) {
93+ // remove old `released` tag
94+ await run (
95+ `git fetch origin refs/tags/${ RELEASED_TAG } :refs/tags/${ RELEASED_TAG } `
96+ ) ;
97+ await run ( `git tag -d ${ RELEASED_TAG } ` ) ;
98+ await run ( `git push --delete origin ${ RELEASED_TAG } ` ) ;
99+
100+ // create new `released` tag
101+ await run ( `git tag released` ) ;
102+ await run ( `git push --tags` ) ;
103+ }
104+
80105 for ( const lang of langs ) {
81106 const { tempGitDir } = await cloneRepository ( {
82107 lang,
@@ -100,14 +125,24 @@ async function spreadGeneration(): Promise<void> {
100125 continue ;
101126 }
102127
128+ const version = getPackageVersionDefault ( lang ) ;
129+ const message = IS_RELEASE_COMMIT
130+ ? `chore: release ${ version } `
131+ : commitMessage ;
132+
103133 await configureGitHubAuthor ( tempGitDir ) ;
104134 await run ( `git add .` , { cwd : tempGitDir } ) ;
105135 await gitCommit ( {
106- message : commitMessage ,
136+ message,
107137 coAuthors : [ author , ...coAuthors ] ,
108138 cwd : tempGitDir ,
109139 } ) ;
110- await run ( `git push` , { cwd : tempGitDir } ) ;
140+ await execa ( 'git' , [ 'tag' , version ] , {
141+ cwd : tempGitDir ,
142+ } ) ;
143+ await run ( IS_RELEASE_COMMIT ? 'git push --follow-tags' : 'git push' , {
144+ cwd : tempGitDir ,
145+ } ) ;
111146 console . log ( `✅ Spread the generation to ${ lang } repository.` ) ;
112147 }
113148}
0 commit comments