-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get the download URL for a workflow artifact instead of following the redirect and downloading it #240
Comments
In Node.js, yes: let { url } = await octokit.request('HEAD /repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}', {
owner: 'octocat',
repo: 'hello-world',
artifact_id: 42,
archive_format: 'archive_format'
}) In browsers it is not currently possible, due to lacking CORS settings See also |
Thanks for the speedy reply. Fwiw I get a 404 from Github for the I ended up using Axios (from Node.js), like this: let request = octokit.actions.downloadArtifact.endpoint({
owner,
repo,
artifact_id,
archive_format,
});
let response = await axios.get(request.url, {
headers: {
...request.headers,
Authorization: `token ${token}`,
},
validateStatus(status) {
return status === 302;
},
maxRedirects: 0,
});
let url = response.headers.location; |
I was able to reproduce the problem, thank you! That is likely an API bug. The problem is the final URL at I'll check in with support and keep you posted. Your workaround looks good for the time being |
Thanks @bantic, it is exactly what I was looking for. |
For reference, here is a GitHub Action workflow file to create an artifact for testing: name: Create artifact
on:
workflow_dispatch: {}
jobs:
create-artifact:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: mkdir -p my-artifact
- run: echo hello > my-artifact/world.txt
- uses: actions/upload-artifact@v2
with:
name: my-artifact
path: my-artifact/world.txt See it in action at https://github.com/gr2m/sandbox/actions/workflows/create-artifact.yml Then I use this script to get the URL, which works const { Octokit } = require("@octokit/core");
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
});
run();
async function run() {
const owner = "gr2m";
const repo = "sandbox";
const {
data: { artifacts },
} = await octokit.request("GET /repos/{owner}/{repo}/actions/artifacts", {
owner,
repo,
});
try {
let { headers } = await octokit.request(
"HEAD /repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}",
{
owner,
repo,
artifact_id: artifacts[0].id,
archive_format: "zip",
}
);
console.log(headers.location);
} catch (error) {
console.log(error);
}
} But when I change it to But it turns out not to be a problem with the API, the problem is that For node usage, the request can be set to not follow redirects. So this works let { headers } = await octokit.request(
"HEAD /repos/{owner}/{repo}/actions/artifacts/{artifact_id}/{archive_format}",
{
owner,
repo,
artifact_id: artifacts[0].id,
archive_format: "zip",
request: {
redirect: "manual",
},
}
);
console.log(headers.location); Note the Sorry this took me a while to figure out. All node-fetch extensions documented here can be set using |
Is it possible to get the download URL for an artifact?
The docs here suggest that the 302 redirect URL will be returned from a call like this:
When I am trying that (as well as
octokit.actions.downloadArtifact
, as per these docs), it seems that the 302 redirect is followed, making myresponse
look like so:I want to just get that url, without downloading the response into that
data
ArrayBuffer
.Is that possible? I've tried adding
request: { redirect: 'manual'}
as an option, but that didn't seem to do it.The text was updated successfully, but these errors were encountered: