Skip to content

Commit 2b61c49

Browse files
Yeela LifshitzYeela Lifshitz
authored andcommitted
Refactor checkout conditions in action.yml and update variable handling in get-condition-vars.js
1 parent c28c79e commit 2b61c49

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

action.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ runs:
8989
IS_NON_COMMIT_ARG: ${{ fromJSON(fromJSON(inputs.client_payload)).isNonCommitEvent }}
9090
ENABLE_CACHE_ARG: ${{ env.ENABLE_CACHE }}
9191
RUN_ID_ARG: ${{ fromJSON(fromJSON(inputs.client_payload)).artifactRunId }}
92+
CACHE_DOWNLOAD_FAILED_ARG: ${{ env.CACHE_DOWNLOAD_FAILED }}
9293
with:
9394
script: |
9495
require('${{ github.action_path }}/scripts/get-condition-vars.js')(core);
@@ -126,7 +127,7 @@ runs:
126127
script: require('${{ github.action_path }}/scripts/check-cache-download-status')(core);
127128

128129
- name: Checkout Pull Request branches history
129-
if: ${{ env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true' }}
130+
if: ${{ env.SHOULD_CHECKOUT == 'true' }}
130131
shell: bash
131132
run: |
132133
ALL=2147483647
@@ -139,27 +140,26 @@ runs:
139140
git checkout $'${{ steps.safe-strings.outputs.head_ref }}'
140141
141142
- name: Create cm folder
142-
if: ${{ env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true' }}
143+
if: ${{ env.SHOULD_CHECKOUT == 'true' }}
143144
shell: bash
144145
run: cd gitstream && mkdir cm
145146

146147
- name: Checkout cm repo
147148
uses: actions/checkout@v4
148-
if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == true && (env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true')}}
149+
if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == true && env.SHOULD_CHECKOUT == 'true'}}
149150
with:
150151
repository: '${{ fromJSON(fromJSON(inputs.client_payload)).owner }}/${{ fromJSON(fromJSON(inputs.client_payload)).cmRepo }}'
151152
ref: ${{ fromJSON(fromJSON(inputs.client_payload)).cmRepoRef }}
152153
path: gitstream/cm/
153154

154155
- name: Checkout cm org
155156
uses: actions/checkout@v4
156-
if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmOrg == true && (env.SKIP_GIT_CLONE == 'false' || env.CACHE_DOWNLOAD_FAILED == 'true')}}
157+
if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmOrg == true && env.SHOULD_CHECKOUT == 'true'}}
157158
with:
158159
repository: 'cm/cm'
159160
ref: ${{ fromJSON(fromJSON(inputs.client_payload)).cmOrgRef }}
160161
path: gitstream/cm-org/
161162

162-
163163
- name: Volume folder
164164
shell: bash
165165
run: mv gitstream code

scripts/get-condition-vars.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* eslint-disable import/no-commonjs */
22

33
module.exports = core => {
4-
const { IS_NON_COMMIT_ARG, ENABLE_CACHE_ARG, RUN_ID_ARG } = process.env
4+
const { IS_NON_COMMIT_ARG, ENABLE_CACHE_ARG, RUN_ID_ARG, CACHE_DOWNLOAD_FAILED } = process.env
55
try {
66
const isRunIdExists = !!RUN_ID_ARG
77

@@ -12,10 +12,15 @@ module.exports = core => {
1212

1313
core.exportVariable('IS_NON_COMMIT_EVENT', IS_NON_COMMIT_ARG)
1414
core.exportVariable('SKIP_GIT_CLONE', skipGitClone.toString())
15+
16+
const shouldCheckout = !skipGitClone || CACHE_DOWNLOAD_FAILED === 'true';
17+
core.exportVariable('SHOULD_CHECKOUT', shouldCheckout.toString());
18+
1519
} catch (error) {
1620
core.warn(`Failed to get condition variables: ${error.message}`)
1721

1822
core.exportVariable('IS_NON_COMMIT_EVENT', 'false')
1923
core.exportVariable('SKIP_GIT_CLONE', 'false')
24+
core.exportVariable('SHOULD_CHECKOUT', 'true')
2025
}
21-
}
26+
}

0 commit comments

Comments
 (0)