diff --git a/action.yml b/action.yml index 02a1dff6..88b49323 100644 --- a/action.yml +++ b/action.yml @@ -83,7 +83,27 @@ runs: process.exit(1); } + - name: Get condition variables + uses: actions/github-script@v7 + env: + CLIENT_PAYLOAD_ARG: ${{ inputs.client_payload }} + ENABLE_CACHE_ARG: ${{ env.ENABLE_CACHE }} + with: + script: | + require('${{ github.action_path }}/scripts/get-condition-vars.js')(core); + + - name: Download cache artifact + uses: actions/download-artifact@v4 + if: ${{ env.SKIP_GIT_CLONE == 'true' }} + with: + github-token: ${{ fromJSON(fromJSON(inputs.client_payload)).githubToken || github.token }} + repository: ${{ inputs.full_repository }} + run-id: ${{ fromJSON(fromJSON(inputs.client_payload)).artifactRunId }} + name: output + path: code/output + - name: Checkout Pull Request branches history + if: ${{ env.SKIP_GIT_CLONE == 'false' }} shell: bash run: | ALL=2147483647 @@ -96,12 +116,13 @@ runs: git checkout $'${{ steps.safe-strings.outputs.head_ref }}' - name: Create cm folder + if: ${{ env.SKIP_GIT_CLONE == 'false' }} shell: bash run: cd gitstream && mkdir cm - name: Checkout cm repo uses: actions/checkout@v4 - if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == true }} + if: ${{ fromJSON(fromJSON(inputs.client_payload)).hasCmRepo == true && env.SKIP_GIT_CLONE == 'false' }} with: repository: '${{ fromJSON(fromJSON(inputs.client_payload)).owner }}/${{ fromJSON(fromJSON(inputs.client_payload)).cmRepo }}' ref: ${{ fromJSON(fromJSON(inputs.client_payload)).cmRepoRef }} @@ -125,3 +146,14 @@ runs: RULES_RESOLVER_URL: ${{ inputs.resolver_url }} RULES_RESOLVER_TOKEN: ${{ inputs.resolver_token }} DEBUG_MODE: ${{ inputs.debug_mode }} + IS_NON_COMMIT_EVENT: ${{ env.IS_NON_COMMIT_EVENT }} + ENABLE_CACHE: ${{ env.ENABLE_CACHE || 'false' }} + ENABLE_DEBUG_ARTIFACTS: ${{ env.ENABLE_DEBUG_ARTIFACTS }} + + - name: Upload artifacts + if: ${{ env.ENABLE_DEBUG_ARTIFACTS == 'true' || env.ENABLE_CACHE == 'true' }} + uses: actions/upload-artifact@v4 + with: + retention-days: 2 + name: output + path: code/output diff --git a/scripts/get-condition-vars.js b/scripts/get-condition-vars.js new file mode 100644 index 00000000..b308f5de --- /dev/null +++ b/scripts/get-condition-vars.js @@ -0,0 +1,16 @@ +/* eslint-disable import/no-commonjs */ + +module.exports = core => { + const { CLIENT_PAYLOAD_ARG, ENABLE_CACHE_ARG } = process.env + try { + const payload = JSON.parse(CLIENT_PAYLOAD_ARG) + const isNonCommitEvent = payload.isNonCommitEvent === true + const skipGitClone = isNonCommitEvent && ENABLE_CACHE_ARG === 'true' + core.exportVariable('IS_NON_COMMIT_EVENT', isNonCommitEvent.toString()) + core.exportVariable('SKIP_GIT_CLONE', skipGitClone.toString()) + } catch (error) { + core.setFailed(error.message) + core.exportVariable('IS_NON_COMMIT_EVENT', 'false') + core.exportVariable('SKIP_GIT_CLONE', 'false') + } +}