-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added separate workflow that search cache, it will allow us to remove duplication of this logic in `main.yml`, `full.yml` and `schedule.yml` ! This solution won't work if PR changes search-cache.yml, but this workflow is supposed to almost never change
- Loading branch information
Kirill Sizov
authored
Jan 9, 2023
1 parent
1e2db74
commit 7df2b2f
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: Search Cache | ||
on: | ||
workflow_call: | ||
outputs: | ||
sha: | ||
value: ${{ jobs.search_cache.outputs.sha }} | ||
|
||
# if: | | ||
# github.event.pull_request.draft == false && | ||
# !startsWith(github.event.pull_request.title, '[WIP]') && | ||
# !startsWith(github.event.pull_request.title, '[Dependent]') | ||
|
||
jobs: | ||
search_cache: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
sha: ${{ steps.get-sha.outputs.sha}} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
REPO: ${{ github.repository }} | ||
steps: | ||
- name: Getting SHA with cache from the default branch | ||
id: get-sha | ||
run: | | ||
DEFAULT_BRANCH=$(gh api /repos/$REPO | jq -r '.default_branch') | ||
for sha in $(gh api "/repos/$REPO/commits?per_page=100&sha=$DEFAULT_BRANCH" | jq -r '.[].sha'); | ||
do | ||
RUN_status=$(gh api /repos/${REPO}/actions/workflows/cache.yml/runs | \ | ||
jq -r ".workflow_runs[]? | select((.head_sha == \"${sha}\") and (.conclusion == \"success\")) | .status") | ||
if [[ ${RUN_status} == "completed" ]]; then | ||
SHA=$sha | ||
break | ||
fi | ||
done | ||
echo Default branch is ${DEFAULT_BRANCH} | ||
echo Workflow will try to get cache from commit: ${SHA} | ||
echo "sha=${SHA}" >> $GITHUB_OUTPUT |