Update candidate release to use the latest commit that passed all checks (#9506)

diff --git a/.github/workflows/build_package.yml b/.github/workflows/build_package.yml
index a204e87..94981a9 100644
--- a/.github/workflows/build_package.yml
+++ b/.github/workflows/build_package.yml
@@ -21,6 +21,9 @@
       release_id:
         description: 'Release id to upload artifacts to'
         default: ''
+      commit:
+        description: 'Commit to check out'
+        default: ''
 
 jobs:
   build_core:
@@ -66,6 +69,7 @@
         with:
           path: 'main_checkout'
           submodules: true
+          ref: ${{ github.event.inputs.commit }}
 
       ##########################################################################
       # OS specific setup
diff --git a/.github/workflows/schedule_candidate_release.yml b/.github/workflows/schedule_candidate_release.yml
index 302defa..33e43bb 100644
--- a/.github/workflows/schedule_candidate_release.yml
+++ b/.github/workflows/schedule_candidate_release.yml
@@ -13,10 +13,17 @@
     # Don't run this in everyone's forks.
     if: github.repository == 'google/iree'
     steps:
+      - name: Get the last green commit
+        id: last_green_commit
+        uses: talentpair/last-green-commit-action@8b4b3bcd4ab5d9ab16875ce20ae012c4ce47ae68
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+
       - name: Checking out repository
         uses: actions/checkout@7884fcad6b5d53d10323aee724dc68d8b9096a2e  # v2
         with:
           token: ${{ secrets.WRITE_ACCESS_TOKEN }}
+          ref: ${{ steps.last_green_commit.outputs.result }}
 
       - name: Compute version
         run: |
@@ -56,4 +63,4 @@
           workflow: Build Native Release Packages
           token: ${{ secrets.WRITE_ACCESS_TOKEN }}
           ref: "${{ env.tag_name }}"
-          inputs: '{"package_suffix": "", "package_version": "${{ env.package_version }}", "release_id": "${{ steps.create_release.outputs.id }}"}'
+          inputs: '{"package_suffix": "", "package_version": "${{ env.package_version }}", "release_id": "${{ steps.create_release.outputs.id }}", "commit": "${{ steps.last_green_commit.outputs.result }}"}'