@@ -3,6 +3,8 @@ import { execaCommand } from '../../utils/exec';
3
3
// eslint-disable-next-line import/no-cycle
4
4
import { logger } from '../publish' ;
5
5
6
+ const { version : storybookVersion } = require ( '../../../code/package.json' ) ;
7
+
6
8
const getTheLastCommitHashThatUpdatedTheSandboxRepo = async ( branch : string ) => {
7
9
const owner = 'storybookjs' ;
8
10
const repo = 'sandboxes' ;
@@ -16,16 +18,23 @@ const getTheLastCommitHashThatUpdatedTheSandboxRepo = async (branch: string) =>
16
18
await fetch ( `https://api.github.com/repos/${ owner } /${ repo } /commits/${ latestCommitSha } ` )
17
19
) . json ( ) ;
18
20
const latestCommitMessage = commitData . commit . message ;
19
- logger . log (
20
- `Latest commit message of ${ owner } /${ repo } on branch ${ branch } : ${ latestCommitMessage } `
21
- ) ;
22
- // The commit message will look like this: Update examples - Thu Apr 13 2023 - 97dbc82537c3
21
+
22
+ // The commit message will look like this: 7.0.5 - Thu Apr 13 2023 - 97dbc82537c3
23
23
// the hash at the end relates to the monorepo commit that updated the sandboxes
24
- return latestCommitMessage . split ( '\n' ) [ 0 ] . split ( ' - ' ) [ 2 ] ;
24
+ const lastCommitHash = latestCommitMessage . split ( '\n' ) [ 0 ] . split ( ' - ' ) [ 2 ] ;
25
+ if ( ! lastCommitHash ) {
26
+ throw new Error (
27
+ `Could not find the last commit hash in the following commit message: "${ latestCommitMessage } ".\nDid someone manually push to the sandboxes repo?`
28
+ ) ;
29
+ }
30
+
31
+ return lastCommitHash ;
25
32
} catch ( error ) {
26
- logger . error (
27
- `Error getting latest commit message of ${ owner } /${ repo } on branch ${ branch } : ${ error . message } `
28
- ) ;
33
+ if ( ! error . message . includes ( 'Did someone manually push to the sandboxes repo' ) ) {
34
+ logger . error (
35
+ `⚠️ Error getting latest commit message of ${ owner } /${ repo } on branch ${ branch } : ${ error . message } `
36
+ ) ;
37
+ }
29
38
30
39
throw error ;
31
40
}
@@ -47,6 +56,7 @@ export async function commitAllToGit({ cwd, branch }: { cwd: string; branch: str
47
56
48
57
let gitCommitCommand ;
49
58
59
+ logger . log ( '🔍 Determining commit message' ) ;
50
60
try {
51
61
const previousCommitHash = await getTheLastCommitHashThatUpdatedTheSandboxRepo ( branch ) ;
52
62
const mergeCommits = (
@@ -66,20 +76,31 @@ export async function commitAllToGit({ cwd, branch }: { cwd: string; branch: str
66
76
67
77
const diffLink = `https://github.com/storybookjs/storybook/compare/${ previousCommitHash } ...${ currentCommitHash } ` ;
68
78
69
- const commitTitle = `Update sandboxes - ${ new Date ( ) . toDateString ( ) } - ${ previousCommitHash } ` ;
70
- const commitBody = [ ...prLinks , `\nCheck the diff here: ${ diffLink } ` ] . join ( '\n' ) ;
79
+ const commitTitle = `${ storybookVersion } - ${ new Date ( ) . toDateString ( ) } - ${ previousCommitHash } ` ;
80
+ const commitBody = [
81
+ `\nCheck the diff here: ${ diffLink } ` ,
82
+ '\nList of included PRs since previous version:' ,
83
+ ...prLinks ,
84
+ ] . join ( '\n' ) ;
71
85
gitCommitCommand = `git commit -m "${ commitTitle } " -m "${ commitBody } "` ;
72
86
} catch ( err ) {
73
- gitCommitCommand = `git commit -m "Update sandboxes - ${ new Date ( ) . toDateString ( ) } - ${ currentCommitHash } ` ;
87
+ logger . log (
88
+ `⚠️ Falling back to a simpler commit message because of an error while trying to get the previous commit hash: ${ err . message } `
89
+ ) ;
90
+ gitCommitCommand = `git commit -m "${ storybookVersion } - ${ new Date ( ) . toDateString ( ) } - ${ currentCommitHash } "` ;
74
91
}
75
92
76
93
await execaCommand ( gitCommitCommand , {
77
94
shell : true ,
78
95
cwd,
79
96
} ) ;
80
97
} catch ( e ) {
81
- logger . log (
82
- `🤷 Git found no changes between previous versions so there is nothing to commit. Skipping publish!`
83
- ) ;
98
+ if ( e . message . includes ( 'nothing to commit' ) ) {
99
+ logger . log (
100
+ `🤷 Git found no changes between previous versions so there is nothing to commit. Skipping publish!`
101
+ ) ;
102
+ } else {
103
+ logger . error ( `🤯 Something went wrong while committing to git: ${ e . message } ` ) ;
104
+ }
84
105
}
85
106
}
0 commit comments