From 27ef93013ccb9b9c51f69d3d1e0f06eb2e1a4c50 Mon Sep 17 00:00:00 2001 From: jordanbreen28 Date: Wed, 1 May 2024 13:27:46 +0100 Subject: [PATCH] (CAT-1829) - Update to dynamic checkout ref gem_ci This commit implements a dynamic checkout ref for the gem_ci workflow. This is because we will be updating the calling workflows to be run on the pull_request_target trigger so they can safely access secrets, so this extra checkout logic is needed in order to checkout the head branch. --- .github/workflows/gem_ci.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/gem_ci.yml b/.github/workflows/gem_ci.yml index 2e2ed7b..fa3d64d 100644 --- a/.github/workflows/gem_ci.yml +++ b/.github/workflows/gem_ci.yml @@ -34,9 +34,22 @@ jobs: PUPPET_GEM_VERSION: ${{ inputs.puppet_gem_version }} steps: + # If we are on a PR, checkout the PR head sha, else checkout the default branch + # required when trigger set to pull_request_target + - name: "Set the checkout ref" + id: set_ref + run: | + if [[ "${{ github.event_name }}" == "pull_request_target" ]]; then + echo "ref=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT + else + echo "ref=${{ github.ref }}" >> $GITHUB_OUTPUT + fi - name: "checkout" uses: "actions/checkout@v4" + with: + fetch-depth: 1 + ref: ${{ steps.set_ref.outputs.ref }} - name: "export environment" run: |