Skip doing work if it is not necessary

This commit is contained in:
Simon Engledew 2021-03-22 15:50:04 +00:00
parent 36a9516acc
commit 9165099103
No known key found for this signature in database
GPG key ID: 84302E7B02FE8BCE
3 changed files with 11 additions and 3 deletions

5
lib/actions-util.js generated
View file

@ -360,6 +360,9 @@ async function getRef() {
// than the 'merge' ref. If so, we want to convert the ref that
// we report back.
const pull_ref_regex = /refs\/pull\/(\d+)\/merge/;
if (!pull_ref_regex.test(ref)) {
return ref;
}
const head = await exports.getCommitOid("HEAD");
// in actions/checkout@v2 we can check if git rev-parse HEAD == GITHUB_SHA
// in actions/checkout@v1 this may not be true as it checks out the repository
@ -367,7 +370,7 @@ async function getRef() {
// git rev-parse GITHUB_REF != GITHUB_SHA, so we must check
// git git-parse GITHUB_REF == git rev-parse HEAD instead.
const hasChangedRef = sha !== head && (await exports.getCommitOid(ref)) !== head;
if (pull_ref_regex.test(ref) && hasChangedRef) {
if (hasChangedRef) {
const newRef = ref.replace(pull_ref_regex, "refs/pull/$1/head");
core.debug(`No longer on merge commit, rewriting ref from ${ref} to ${newRef}.`);
return newRef;

File diff suppressed because one or more lines are too long

View file

@ -432,7 +432,12 @@ export async function getRef(): Promise<string> {
// than the 'merge' ref. If so, we want to convert the ref that
// we report back.
const pull_ref_regex = /refs\/pull\/(\d+)\/merge/;
if (!pull_ref_regex.test(ref)) {
return ref;
}
const head = await getCommitOid("HEAD");
// in actions/checkout@v2 we can check if git rev-parse HEAD == GITHUB_SHA
// in actions/checkout@v1 this may not be true as it checks out the repository
// using GITHUB_REF. There is a subtle race condition where
@ -440,7 +445,7 @@ export async function getRef(): Promise<string> {
// git git-parse GITHUB_REF == git rev-parse HEAD instead.
const hasChangedRef = sha !== head && (await getCommitOid(ref)) !== head;
if (pull_ref_regex.test(ref) && hasChangedRef) {
if (hasChangedRef) {
const newRef = ref.replace(pull_ref_regex, "refs/pull/$1/head");
core.debug(
`No longer on merge commit, rewriting ref from ${ref} to ${newRef}.`