From f1f5b3e56ce5287276ea02ba106e754fc035c9aa Mon Sep 17 00:00:00 2001 From: Daniel Gaspar Date: Thu, 30 Jan 2025 13:33:55 +0000 Subject: [PATCH] fix(ci): ephemeral env, handle different label, create comment --- .github/workflows/ephemeral-env.yml | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ephemeral-env.yml b/.github/workflows/ephemeral-env.yml index 0529fbe6813..ea29805c98c 100644 --- a/.github/workflows/ephemeral-env.yml +++ b/.github/workflows/ephemeral-env.yml @@ -50,17 +50,45 @@ jobs: echo "result=up" >> $GITHUB_OUTPUT else echo "result=noop" >> $GITHUB_OUTPUT - exit 0 fi - name: Get event SHA id: get-sha - run: | - echo "sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT + if: steps.eval-label.outputs.result == 'up' + uses: actions/github-script@v7 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + let prSha; + + // If event is workflow_dispatch, use the issue_number from inputs + if (context.eventName === "workflow_dispatch") { + const prNumber = "${{ github.event.inputs.issue_number }}"; + if (!prNumber) { + console.log("No PR number found."); + return; + } + + // Fetch PR details using the provided issue_number + const { data: pr } = await github.rest.pulls.get({ + owner: context.repo.owner, + repo: context.repo.repo, + pull_number: prNumber + }); + + prSha = pr.head.sha; + } else { + // If it's not workflow_dispatch, use the PR head sha from the event + prSha = context.payload.pull_request.head.sha; + } + + console.log(`PR SHA: ${prSha}`); + core.setOutput("sha", prSha); - name: Looking for feature flags in PR description uses: actions/github-script@v7 id: eval-feature-flags + if: steps.eval-label.outputs.result == 'up' with: script: | const description = context.payload.pull_request @@ -81,6 +109,7 @@ jobs: - name: Reply with confirmation comment uses: actions/github-script@v7 + if: steps.eval-label.outputs.result == 'up' with: github-token: ${{ secrets.GITHUB_TOKEN }} script: |