Skip to content

Commit 4c1e823

Browse files
authored
Add the option "ref", specifying either a commit or a branch (#329)
This fixes #242.
1 parent a708c3c commit 4c1e823

File tree

4 files changed

+56
-2
lines changed

4 files changed

+56
-2
lines changed

.github/workflows/download.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,37 @@ jobs:
8787
commit: ${{ github.sha }}
8888
- name: Test
8989
run: cat artifact/sha | grep $GITHUB_SHA
90+
download-ref-branch:
91+
runs-on: ubuntu-latest
92+
needs: wait
93+
if: github.ref == 'refs/heads/master'
94+
steps:
95+
- name: Checkout
96+
uses: actions/checkout@v4
97+
- name: Download
98+
uses: ./
99+
with:
100+
workflow: upload.yml
101+
name: artifact
102+
path: artifact
103+
ref: master
104+
- name: Test
105+
run: cat artifact/sha | grep $GITHUB_SHA
106+
download-ref-commit:
107+
runs-on: ubuntu-latest
108+
needs: wait
109+
steps:
110+
- name: Checkout
111+
uses: actions/checkout@v4
112+
- name: Download
113+
uses: ./
114+
with:
115+
workflow: upload.yml
116+
name: artifact
117+
path: artifact
118+
ref: ${{ github.sha }}
119+
- name: Test
120+
run: cat artifact/sha | grep $GITHUB_SHA
90121
download-multiple:
91122
runs-on: ubuntu-latest
92123
needs: wait

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
66

77
## Usage
88

9-
> If `commit` or `pr` or `branch` or `run_id` or `workflow_conclusion` is not specified then the artifact from the most recent successfully completed workflow run will be downloaded.
9+
> If `commit`, `pr`, `branch`, `ref`, `run_id` or `workflow_conclusion` is not specified then the artifact from the most recent successfully completed workflow run will be downloaded.
1010
11-
**Do not specify `pr`, `commit`, `branch`, `run_id` together or `workflow_conclusion` and `run_id` together. Pick just one of each or none.**
11+
**Do not specify `pr`, `commit`, `branch`, `ref`, `run_id` together or `workflow_conclusion` and `run_id` together. Pick just one of each or none.**
1212

1313
```yaml
1414
- name: Download artifact
@@ -38,6 +38,9 @@ Let's suppose you have a workflow with a job in it that at the end uploads an ar
3838
commit: ${{github.event.pull_request.head.sha}}
3939
# Optional, will use the specified branch. Defaults to all branches
4040
branch: master
41+
# Optional, branch/tag/commit ID to reference. This can supersede both
42+
# branch and commit above.
43+
ref: master
4144
# Optional, defaults to all types
4245
event: push
4346
# Optional, will use specified workflow run

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ inputs:
4242
branch:
4343
description: Branch name
4444
required: false
45+
ref:
46+
description: Commit hash or branch name
47+
required: false
4548
event:
4649
description: Event type
4750
required: false

main.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ async function main() {
4646
let pr = core.getInput("pr")
4747
let commit = core.getInput("commit")
4848
let branch = core.getInput("branch")
49+
let ref = core.getInput("ref")
4950
let event = core.getInput("event")
5051
let runID = core.getInput("run_id")
5152
let runNumber = core.getInput("run_number")
@@ -74,6 +75,7 @@ async function main() {
7475
"pr": pr,
7576
"commit": commit,
7677
"branch": branch,
78+
"ref": ref,
7779
"run_id": runID
7880
}
7981
]
@@ -96,6 +98,21 @@ async function main() {
9698
//branch = pull.data.head.ref
9799
}
98100

101+
if (ref) {
102+
// Try to determine if the ref is a branch or a commit
103+
core.info(`==> Ref: ${ref}`)
104+
try {
105+
const response = await client.rest.repos.getBranch({
106+
owner: owner,
107+
repo: repo,
108+
branch: ref,
109+
})
110+
branch = ref
111+
} catch (error) {
112+
commit = ref
113+
}
114+
}
115+
99116
if (commit) {
100117
core.info(`==> Commit: ${commit}`)
101118
}

0 commit comments

Comments
 (0)