-
Notifications
You must be signed in to change notification settings - Fork 726
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
Question: What API is used to upload artifacts? #180
Comments
You can find all the APIs here: https://github.com/actions/toolkit/tree/main/packages/artifact All the core APIs interactions are in our See also: https://github.com/actions/upload-artifact#additional-documentation |
Hi, I'm aware of the NPM-based API, but I am referring more to the REST API that (I assume) underlies it. What HTTP endpoints are hit in order to upload artifacts, and where are they documented? |
Would also like to know this. Is there a rest API in which developers can interact with? |
Any news about an API endpoints? |
Sorry to ping you @konradpabjan, just want to make to sure you get the REST API question (I'm searching for the same thing to work around actions/runner#1491) |
I gave up and started using GitHub packages for artifacts. They are billed the same afaik. |
@andersson09 are we able to deal with let's say zip files or plain binary ? (sounds a good way to work around if we are able to do this kind of thing) |
Yep. Currently I'm zipping and renaming them to .nupkg and treating them as a nuget package. I Would assume there are other ways too though. |
They're not documented anywhere. You'd have to effectively dig through the NPM package to figure all the calls that are made and it's not very intuitive. There is a HTTP POST call to create the artifact container: Then multiple PUT calls to actually upload the content: Followed by a PATCH call to finalize the artifact upload: A bit more information here: They're effectively "internal" APIs that don't hit The upload process is unnecessarily complex for what it is (because we proxy everything through our backend before uploading to blob storage). We're already working on a pretty major overhaul (think upload-artifact |
I'm grateful for all the attention this has received, and the fact that an "upload URL" is in the works is excellent news! The restriction on uploads (being allowed only from a runner and in the context of a run) is fine for my use case, so I'll look forward to |
@konradpabjan thank you a lot for describing the flow and pointing out in the code where this is happening. Thanks to you I've been able to implement a GitHub action to share data across workflow jobs. When I started working on my action, I had no idea how I was going to handle I still had to dig a bit back and forth on the repo to understand all the request headers/bodies and response headers/bodies involved in the
If you don't feel comfortable exploring typescript code from the links that @konradpabjan provided, you can check these for equivalent C# versions:
Hope this helps out fellow developers until we get an official API for this.
|
ok tried to simplify this down further and made a few discoveries...
import child_process from 'child_process';
import path from 'path';
import url from 'url';
const __dirname = path.dirname(url.fileURLToPath(import.meta.url));
const exe = path.resolve(__dirname, 'main.sh');
try {
child_process.execFileSync(exe, {stdio: 'inherit'});
} catch (e) {
process.exit(e.status);
} then I've distilled down the "create an artifact and upload one file" to these curl commands: #!/usr/bin/env bash
set -euxo pipefail
ARTIFACT_NAME='artifact-name'
HEADERS=(
--header 'Accept: application/json;api-version=6.0-preview'
--header "Authorization: Bearer $ACTIONS_RUNTIME_TOKEN"
)
ARTIFACT_BASE="${ACTIONS_RUNTIME_URL}_apis/pipelines/workflows/${GITHUB_RUN_ID}/artifacts?api-version=6.0-preview"
RESOURCE_URL="$(
curl \
-XPOST \
--silent \
--fail-with-body \
"${HEADERS[@]}" \
--header 'Content-Type: application/json' \
--data '{"type": "actions_storage", "name": "'"${ARTIFACT_NAME}"'"}' \
"$ARTIFACT_BASE" | jq --exit-status --raw-output .fileContainerResourceUrl
)"
curl \
-XPUT \
--silent \
--fail-with-body \
"${HEADERS[@]}" \
--header 'Content-Type: application/octet-stream' \
--header 'Content-Range: bytes 0-10/11' \
--data 'hello world' \
"${RESOURCE_URL}?itemPath=${ARTIFACT_NAME}/data.txt"
curl \
-XPATCH \
--silent \
--fail-with-body \
"${HEADERS[@]}" \
--header 'Content-Type: application/json' \
--data '{"size": 11}' \
"${ARTIFACT_BASE}&artifactName=${ARTIFACT_NAME}" some important things I missed and spent a bunch of time on:
|
When I dump the jobs:
dump-env:
runs-on: macos-latest
steps:
- run: env Neither EDIT: Just found this (Emphasis mine):
|
there are three types of github actions: node, docker, and composite |
@clayellis I also tried to do what you did before I developed my GitHub action that uploads/downloads artifacts and therefore I had to be able to access At first I was also puzzled by the fact I couldn't list those env variables and eventually found similar info to what you linked. I just wanted to confirm that indeed those env variables will be available to your action, regardless of the type, when the action is being executed. Below is an extract of the log from running my action:
My action is a docker action and the part I want to call your attention to are the env variables passed into the action. Note that both of the env variables you mentioned are passed to my action via In the code of my app that is running inside the docker action I can access then access them as expected:
|
For anyone who comes across this in the future looking for yet another example of how to hit these APIs, here's a CICD action written in Swift. This action doesn't follow the exact logic that the official action uses in its upload compression flow but was sufficient for my needs. |
Apologies if this is not the proper place to ask; this repo is the closest I could get to what I was looking for.
I am curious about uploading artifacts from my own custom Docker action.
The API does not list an upload function: https://docs.github.com/en/rest/reference/actions#artifacts
I tried to dig into how this action performs the upload step and it rapidly becomes a bit lower-level than I was expecting to see:
upload-artifact/src/upload-artifact.ts
Line 54 in ea3d524
upload-artifact/dist/index.js
Line 3815 in ea3d524
upload-artifact/dist/index.js
Line 6908 in ea3d524
Is this hitting an API that's not available to the public? I only ask because I don't see anything related to passing in a
GITHUB_TOKEN
like other actions (e.g. super-linter).The text was updated successfully, but these errors were encountered: