From 0cd8740a85965bbebfc8ab3f709649e4609f3e6b Mon Sep 17 00:00:00 2001 From: nigeljamesstevenson <105309450+nigeljamesstevenson@users.noreply.github.com> Date: Sat, 11 May 2024 22:15:53 +0100 Subject: [PATCH] Ensure the cherry pick operation only executes against `trunk` (#47312) * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-release-highlight-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update README.md * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update test-assistant-api-rest-change-tracker.yml * Update cherry pick workflow to only execute against trunk * Update workflow to add safety checks before accessing nested properties * Update workflow to add safety checks before accessing nested properties * log outputs for debugging * log outputs for debugging * log outputs for debugging * log outputs for debugging * log outputs for debugging * log outputs for debugging * log outputs for debugging * sync files pre PR --- .github/workflows/cherry-pick.yml | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cherry-pick.yml b/.github/workflows/cherry-pick.yml index c9519aeb277..3fda61def9d 100644 --- a/.github/workflows/cherry-pick.yml +++ b/.github/workflows/cherry-pick.yml @@ -39,18 +39,34 @@ jobs: outputs: run: ${{ steps.check.outputs.run }} steps: + - name: Fetch Pull Request Details + if: github.event.issue.pull_request + id: fetch_pr_details + uses: actions/github-script@v6 + with: + script: | + const issue = context.payload.issue; + const pullRequestUrl = issue.pull_request.url; + const prDetails = await github.request(pullRequestUrl); + core.setOutput('base_ref', prDetails.data.base.ref); + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: check id: check uses: actions/github-script@v6 with: script: | + const baseRef = process.env.BASE_REF; + console.log("baseRef:", baseRef); + let run = false; const isManualTrigger = context.payload.inputs && context.payload.inputs.release_branch && context.payload.inputs.release_branch != null; - const isMergedMilestonedIssue = context.payload.issue && context.payload.issue.pull_request != null && context.payload.issue.pull_request.merged_at != null && context.payload.issue.milestone != null; + const isMergedMilestonedIssue = context.payload.issue && context.payload.issue.pull_request != null && context.payload.issue.pull_request.merged_at != null && context.payload.issue.milestone != null && baseRef == 'trunk'; - const isMergedMilestonedPR = context.payload.pull_request && context.payload.pull_request != null && context.payload.pull_request.merged == true && context.payload.pull_request.milestone != null; + const isMergedMilestonedPR = context.payload.pull_request && context.payload.pull_request != null && context.payload.pull_request.merged == true && context.payload.pull_request.milestone != null && baseRef == 'trunk'; const isBot = context.payload.pull_request && ( context.payload.pull_request.user.login == 'github-actions[bot]' || context.payload.pull_request.user.type == 'Bot' ); @@ -59,6 +75,9 @@ jobs: } else { core.setOutput( 'run', 'false' ); } + env: + BASE_REF: ${{ steps.fetch_pr_details.outputs.base_ref }} + prep: name: Prep inputs runs-on: ubuntu-20.04 @@ -363,4 +382,4 @@ jobs: Release lead please review: ${{ steps.cherry-pick-pr.outputs.cherry-pick-pr }} - ${{ steps.deletion-pr.outputs.deletion-pr }} + ${{ steps.deletion-pr.outputs.deletion-pr }} \ No newline at end of file