Skip to content

Commit 8ed470c

Browse files
authored
Merge pull request #234 from crazy-max/fix-sha-pr
set associated head sha on pull request event
2 parents 8671a4f + 61ddee1 commit 8ed470c

File tree

4 files changed

+34
-30
lines changed

4 files changed

+34
-30
lines changed

__tests__/meta.test.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,7 +2091,7 @@ describe('pr', () => {
20912091
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
20922092
"org.opencontainers.image.version=pr-15",
20932093
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2094-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2094+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
20952095
"org.opencontainers.image.licenses=MIT"
20962096
]
20972097
],
@@ -2117,7 +2117,7 @@ describe('pr', () => {
21172117
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
21182118
"org.opencontainers.image.version=pr-15",
21192119
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2120-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2120+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
21212121
"org.opencontainers.image.licenses=MIT"
21222122
]
21232123
],
@@ -2133,14 +2133,14 @@ describe('pr', () => {
21332133
} as Inputs,
21342134
{
21352135
main: 'pr-15',
2136-
partial: ['sha-a9c8c58'],
2136+
partial: ['sha-3370e22'],
21372137
latest: false
21382138
} as Version,
21392139
[
21402140
'org/app:pr-15',
2141-
'org/app:sha-a9c8c58',
2141+
'org/app:sha-3370e22',
21422142
'ghcr.io/user/app:pr-15',
2143-
'ghcr.io/user/app:sha-a9c8c58'
2143+
'ghcr.io/user/app:sha-3370e22'
21442144
],
21452145
[
21462146
"org.opencontainers.image.title=Hello-World",
@@ -2149,7 +2149,7 @@ describe('pr', () => {
21492149
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
21502150
"org.opencontainers.image.version=pr-15",
21512151
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2152-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2152+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
21532153
"org.opencontainers.image.licenses=MIT"
21542154
]
21552155
],
@@ -2164,24 +2164,24 @@ describe('pr', () => {
21642164
]
21652165
} as Inputs,
21662166
{
2167-
main: 'sha-a9c8c58',
2167+
main: 'sha-3370e22',
21682168
partial: ['pr-15'],
21692169
latest: false
21702170
} as Version,
21712171
[
2172-
'org/app:sha-a9c8c58',
2172+
'org/app:sha-3370e22',
21732173
'org/app:pr-15',
2174-
'ghcr.io/user/app:sha-a9c8c58',
2174+
'ghcr.io/user/app:sha-3370e22',
21752175
'ghcr.io/user/app:pr-15'
21762176
],
21772177
[
21782178
"org.opencontainers.image.title=Hello-World",
21792179
"org.opencontainers.image.description=This your first repo!",
21802180
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
21812181
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
2182-
"org.opencontainers.image.version=sha-a9c8c58",
2182+
"org.opencontainers.image.version=sha-3370e22",
21832183
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2184-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2184+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
21852185
"org.opencontainers.image.licenses=MIT"
21862186
]
21872187
],
@@ -2214,7 +2214,7 @@ describe('pr', () => {
22142214
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
22152215
"org.opencontainers.image.version=pr-15-bal",
22162216
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2217-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2217+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
22182218
"org.opencontainers.image.licenses=MIT"
22192219
]
22202220
],
@@ -2247,7 +2247,7 @@ describe('pr', () => {
22472247
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
22482248
"org.opencontainers.image.version=15-bal",
22492249
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2250-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2250+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
22512251
"org.opencontainers.image.licenses=MIT"
22522252
]
22532253
],
@@ -2262,24 +2262,24 @@ describe('pr', () => {
22622262
]
22632263
} as Inputs,
22642264
{
2265-
main: 'sha-2665741',
2265+
main: 'sha-3370e22',
22662266
partial: ['pr-15'],
22672267
latest: false
22682268
} as Version,
22692269
[
2270-
'org/app:sha-2665741',
2270+
'org/app:sha-3370e22',
22712271
'org/app:pr-15',
2272-
'ghcr.io/user/app:sha-2665741',
2272+
'ghcr.io/user/app:sha-3370e22',
22732273
'ghcr.io/user/app:pr-15'
22742274
],
22752275
[
22762276
"org.opencontainers.image.title=Hello-World",
22772277
"org.opencontainers.image.description=This your first repo!",
22782278
"org.opencontainers.image.url=https://github.com/octocat/Hello-World",
22792279
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
2280-
"org.opencontainers.image.version=sha-2665741",
2280+
"org.opencontainers.image.version=sha-3370e22",
22812281
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2282-
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
2282+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
22832283
"org.opencontainers.image.licenses=MIT"
22842284
]
22852285
],
@@ -2312,7 +2312,7 @@ describe('pr', () => {
23122312
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
23132313
"org.opencontainers.image.version=15-bal",
23142314
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2315-
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
2315+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
23162316
"org.opencontainers.image.licenses=MIT"
23172317
]
23182318
],
@@ -2332,15 +2332,15 @@ describe('pr', () => {
23322332
{
23332333
main: 'pr-15',
23342334
partial: [
2335-
'sha-2665741',
2336-
'sha-266574110acf203503badf966df2ea24b5d732d7'
2335+
'sha-3370e22',
2336+
'sha-3370e228f2209994d57af4427fe64e71bb79ac96'
23372337
],
23382338
latest: false
23392339
} as Version,
23402340
[
23412341
'org/app:pr-15',
2342-
'org/app:sha-2665741',
2343-
'org/app:sha-266574110acf203503badf966df2ea24b5d732d7'
2342+
'org/app:sha-3370e22',
2343+
'org/app:sha-3370e228f2209994d57af4427fe64e71bb79ac96'
23442344
],
23452345
[
23462346
"org.opencontainers.image.title=Hello-World",
@@ -2349,7 +2349,7 @@ describe('pr', () => {
23492349
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
23502350
"org.opencontainers.image.version=pr-15",
23512351
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2352-
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
2352+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
23532353
"org.opencontainers.image.licenses=MIT"
23542354
]
23552355
],
@@ -2378,7 +2378,7 @@ describe('pr', () => {
23782378
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
23792379
"org.opencontainers.image.version=mytag-master",
23802380
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2381-
"org.opencontainers.image.revision=266574110acf203503badf966df2ea24b5d732d7",
2381+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
23822382
"org.opencontainers.image.licenses=MIT"
23832383
]
23842384
],
@@ -2407,7 +2407,7 @@ describe('pr', () => {
24072407
"org.opencontainers.image.source=https://github.com/octocat/Hello-World",
24082408
"org.opencontainers.image.version=mytag-master",
24092409
"org.opencontainers.image.created=2020-01-10T00:30:00.000Z",
2410-
"org.opencontainers.image.revision=a9c8c5828b91be19d9728548b24759e352367ef1",
2410+
"org.opencontainers.image.revision=3370e228f2209994d57af4427fe64e71bb79ac96",
24112411
"org.opencontainers.image.licenses=MIT"
24122412
]
24132413
],

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/meta.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ export class Meta {
3737
context.ref = `refs/pull/${context.payload.number}/merge`;
3838
}
3939

40+
if ((/pull_request/.test(context.eventName) || /pull_request_target/.test(context.eventName)) && context.payload?.pull_request?.head?.sha != undefined) {
41+
context.sha = context.payload.pull_request.head.sha;
42+
}
43+
4044
this.inputs = inputs;
4145
this.context = context;
4246
this.repo = repo;
@@ -301,7 +305,7 @@ export class Meta {
301305

302306
let val = this.context.sha;
303307
if (tag.attrs['format'] === tcl.ShaFormat.Short) {
304-
val = this.context.sha.substr(0, 7);
308+
val = this.context.sha.substring(0, 7);
305309
}
306310

307311
const vraw = this.setValue(val, tag);
@@ -367,7 +371,7 @@ export class Meta {
367371
return ctx.ref.replace(/^refs\/tags\//g, '');
368372
},
369373
sha: function () {
370-
return ctx.sha.substr(0, 7);
374+
return ctx.sha.substring(0, 7);
371375
},
372376
base_ref: function () {
373377
if (/^refs\/tags\//.test(ctx.ref) && ctx.payload?.base_ref != undefined) {

0 commit comments

Comments
 (0)