Skip to content

Commit 7ef4c60

Browse files
committed
Add optional flag to only search for stash in current branch
In some cases, when you want to optimize building and using big artifacts, you want to build them in one job, upload as artifact and use them in the same workflow in other jobs, and you do not want to fallback to the target branch artifact. This is for example where you want to build docker image from current sources, and pull the image in other jobs of the same workflow. If you make mistake in your workflow or miss uploading the artifact in this case, you will silently pull and use the "target" version of the artifact (so in this case it will be target sources of your code). This might lead to cases where your CI tests will not be testing your source code. # Please enter the commit message for your changes. Lines starting
1 parent 4ab8682 commit 7ef4c60

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

stash/restore/action.yml

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ inputs:
2222
functionality as there is no eviction (only expiry).
2323
2424
The action checks the current branch for a stash, if there is no match,
25-
the base branch(PRs)/default branch is searched. If there is more than one
26-
match for any branch the most recently updated stash takes precedent.
25+
the base branch(PRs)/default branch is searched unless it's specified not to.
26+
If there is more than one match for any branch the most recently updated stash takes precedent.
2727
2828
To reduce amount of api calls (1000/h/repo limit) the name of the
2929
current branch will be appended to the key. Key and branchname will be normalized.
@@ -36,6 +36,12 @@ inputs:
3636
token:
3737
description: 'GITHUB_TOKEN to use to authenticate against the artifacts api.'
3838
default: ${{ github.token }}
39+
40+
only-current-branch:
41+
description: >
42+
If true, only the current branch will be searched for the stash.
43+
If false, the base branch(PRs)/default branch branch will be searched as well.
44+
default: "false"
3945
outputs:
4046
stash-hit:
4147
description: >
@@ -94,6 +100,7 @@ runs:
94100
head_name: "${{ steps.mung.outputs.stash_head }}"
95101
run_id: "${{ github.run_id }}"
96102
stash_key: "${{ inputs.key }}"
103+
only_current_branch: "${{ inputs.only-current-branch }}"
97104

98105
shell: python3 {0}
99106
run: |
@@ -112,9 +119,11 @@ runs:
112119
stash = gs.get_branch_stash(repo, head_name, env("head_ref"), env("head_repo_id"))
113120
114121
if not stash:
115-
gs.print_debug(f"Looking for stash {base_name} on base branch.")
116-
stash = gs.get_branch_stash(repo, base_name, env("base_ref"), env("base_repo_id"))
117-
122+
if env("only_current_branch") == "true":
123+
print("Skipping base branch search as only-current-branch was set to true.")
124+
else:
125+
gs.print_debug(f"Looking for stash {base_name} on base branch.")
126+
stash = gs.get_branch_stash(repo, base_name, env("base_ref"), env("base_repo_id"))
118127
gs.print_debug(f"Stash: {stash}")
119128
if not stash:
120129
print(f"Stash not found for key: {env('stash_key')}")

0 commit comments

Comments
 (0)