@@ -6,6 +6,10 @@ import { getPRNumber, getAbsoluteArtifactPath } from './utils';
6
6
const core = require ( '@actions/core' ) ;
7
7
const github = require ( '@actions/github' ) ;
8
8
9
+ // The sha set for `before` on push events if the first push to a commit. This should not ever be the case if
10
+ // pushing to main unless it's the initial commit.
11
+ const DEFAULT_PUSH_BEFORE_SHA = '0000000000000000000000000000000000000000' ;
12
+
9
13
function getInputs ( ) : UploadInputs {
10
14
core . info ( 'Parsing inputs...' ) ;
11
15
@@ -23,21 +27,31 @@ function getInputs(): UploadInputs {
23
27
// of the commit that triggered this action.
24
28
// Therefore, on a PR we need to explicitly get the head sha
25
29
let sha ;
30
+ let baseSha ;
26
31
let branchName ;
32
+ const eventFile = fs . readFileSync ( process . env . GITHUB_EVENT_PATH ?? '' , {
33
+ encoding : 'utf8' ,
34
+ } ) ;
35
+ const eventFileJson = JSON . parse ( eventFile ) ;
27
36
if ( process . env . GITHUB_EVENT_NAME === 'pull_request' ) {
28
- const eventFile = fs . readFileSync ( process . env . GITHUB_EVENT_PATH ?? '' , {
29
- encoding : 'utf8' ,
30
- } ) ;
31
- const eventFileJson = JSON . parse ( eventFile ) ;
32
37
sha = eventFileJson ?. pull_request ?. head ?. sha ?? process . env . GITHUB_SHA ?? '' ;
38
+ baseSha = eventFileJson ?. pull_request ?. base ?. sha ?? '' ;
33
39
branchName = process . env . GITHUB_HEAD_REF ?? '' ;
34
- } else {
40
+ } else if ( process . env . GITHUB_EVENT_NAME === 'push' ) {
35
41
sha = process . env . GITHUB_SHA ?? '' ;
42
+ // Get the SHA of the previous commit, which will be the baseSha in the case of a push event.
43
+ baseSha = eventFileJson ?. before ?? '' ;
44
+ if ( eventFileJson ?. baseRef === null || baseSha === DEFAULT_PUSH_BEFORE_SHA ) {
45
+ baseSha = '' ;
46
+ }
47
+
36
48
const ref = process . env . GITHUB_REF ?? '' ;
37
49
if ( ref !== '' ) {
38
50
const refSplits = ref . split ( '/' ) ;
39
51
branchName = refSplits [ refSplits . length - 1 ] ;
40
52
}
53
+ } else {
54
+ core . setFailed ( `Unsupported action trigger: ${ process . env . GITHUB_EVENT_NAME } ` ) ;
41
55
}
42
56
43
57
if ( sha === '' ) {
@@ -78,6 +92,7 @@ function getInputs(): UploadInputs {
78
92
filename,
79
93
emergeApiKey,
80
94
sha,
95
+ baseSha,
81
96
repoName,
82
97
prNumber,
83
98
buildType,
0 commit comments