Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LINBEE-9077 - add the ability to skip clone + download artifact #108

Merged
merged 21 commits into from
Aug 15, 2024
Merged
34 changes: 33 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
Expand All @@ -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' }}
yeelali14 marked this conversation as resolved.
Show resolved Hide resolved
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
16 changes: 16 additions & 0 deletions scripts/get-condition-vars.js
Original file line number Diff line number Diff line change
@@ -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')
}
}