53 lines
2.2 KiB
YAML
53 lines
2.2 KiB
YAML
name: upload-artifact
|
|
description: "Uploads an artifact. Does not compress it or anything - supports just one file."
|
|
inputs:
|
|
path:
|
|
required: true
|
|
description: "Path to the file that should be uploaded"
|
|
artifact-name:
|
|
required: true
|
|
description: "Name of the resulting artifact"
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- run: |
|
|
set -euxo pipefail
|
|
ARTIFACT_BASE="${ACTIONS_RUNTIME_URL}_apis/pipelines/workflows/${GITHUB_RUN_ID}/artifacts?api-version=6.0-preview"
|
|
FILE_SIZE_BYTES=$(wc -c < ${{ inputs.path }})
|
|
FILE_SIZE_BYTES_MINUS_ONE=$(echo $FILE_SIZE_BYTES - 1 | bc)
|
|
FILE_MD5=$(md5sum ${{ inputs.path }} | cut -f1 -d" ")
|
|
RESOURCE_URL="$(
|
|
curl \
|
|
-XPOST \
|
|
--silent \
|
|
--fail-with-body \
|
|
--header "Authorization: Bearer ${{ github.token }}" \
|
|
--header 'Accept: application/json;api-version=6.0-preview' \
|
|
--header 'Content-Type: application/json' \
|
|
--data '{"type": "actions_storage", "name": "${{ inputs.artifact-name }}"}' \
|
|
$ARTIFACT_BASE | jq --exit-status --raw-output .fileContainerResourceUrl
|
|
)"
|
|
|
|
curl \
|
|
-XPUT \
|
|
--fail-with-body \
|
|
--header 'Accept: application/json;api-version=6.0-preview' \
|
|
--header "Authorization: Bearer ${{ github.token }}" \
|
|
--header 'Content-Type: application/octet-stream' \
|
|
--header "x-tfs-filelength: ${FILE_SIZE_BYTES}" \
|
|
--header "content-length: ${FILE_SIZE_BYTES}" \
|
|
--header "x-actions-results-md5: ${FILE_MD5}" \
|
|
--header "Content-Range: bytes 0-${FILE_SIZE_BYTES_MINUS_ONE}/${FILE_SIZE_BYTES}" \
|
|
--data-binary @${{ inputs.path }} \
|
|
"${RESOURCE_URL}?itemPath=${{ inputs.artifact-name }}/$(basename ${{ inputs.path }})"
|
|
|
|
curl \
|
|
-XPATCH \
|
|
--silent \
|
|
--fail-with-body \
|
|
--header 'Accept: application/json;api-version=6.0-preview' \
|
|
--header "Authorization: Bearer ${{ github.token }}" \
|
|
--header 'Content-Type: application/json' \
|
|
"${ARTIFACT_BASE}&artifactName=${{ inputs.artifact-name }}"
|
|
shell: sh
|