1
0
Fork 0

Merge branch 'main' into konradpabjan/download-artifact-next

pull/1495/head
Konrad Pabjan 2023-08-17 12:42:59 -04:00
commit 6b96da32ae
2 changed files with 25 additions and 42 deletions

View File

@ -31,11 +31,6 @@ jobs:
with: with:
node-version: 16.x node-version: 16.x
# In order to upload & download artifacts from a shell script, certain env variables need to be set that are only available in the
# node context. This runs a local action that gets and sets the necessary env variables that are needed
- name: Set env variables
uses: ./packages/artifact/__tests__/ci-test-action/
# Need root node_modules because certain npm packages like jest are configured for the entire repository and it won't be possible # Need root node_modules because certain npm packages like jest are configured for the entire repository and it won't be possible
# without these to just compile the artifacts package # without these to just compile the artifacts package
- name: Install root npm packages - name: Install root npm packages
@ -50,48 +45,35 @@ jobs:
- name: Set artifact file contents - name: Set artifact file contents
shell: bash shell: bash
run: | run: |
echo "non-gzip-artifact-content=hello" >> $GITHUB_ENV echo "file1=hello from file 1" >> $GITHUB_ENV
echo "gzip-artifact-content=Some large amount of text that has a compression ratio that is greater than 100%. If greater than 100%, gzip is used to upload the file" >> $GITHUB_ENV echo "file2=hello from file 2" >> $GITHUB_ENV
echo "empty-artifact-content=_EMPTY_" >> $GITHUB_ENV
- name: Create files that will be uploaded - name: Create files that will be uploaded
run: | run: |
mkdir artifact-path mkdir artifact-path
echo '${{ env.non-gzip-artifact-content }}' > artifact-path/world.txt echo '${{ env.file1 }}' > artifact-path/first.txt
echo '${{ env.gzip-artifact-content }}' > artifact-path/gzip.txt echo '${{ env.file2 }}' > artifact-path/second.txt
touch artifact-path/empty.txt
# We're using node -e to call the functions directly available in the @actions/artifact package - uses: actions/github-script@v6
- name: Upload artifacts using uploadArtifact() with:
run: | script: |
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-1',['artifact-path/world.txt'], process.argv[1]))" "${{ github.workspace }}" const artifact = require('./packages/artifact/lib/artifact')
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-2',['artifact-path/gzip.txt'], process.argv[1]))" "${{ github.workspace }}"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-3',['artifact-path/empty.txt'], process.argv[1]))" "${{ github.workspace }}"
- name: Download artifacts using downloadArtifact() const artifactName = 'my-artifact-${{ matrix.runs-on }}'
run: | console.log('artifactName: ' + artifactName)
mkdir artifact-1-directory
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().downloadArtifact('my-artifact-1','artifact-1-directory'))"
mkdir artifact-2-directory
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().downloadArtifact('my-artifact-2','artifact-2-directory'))"
mkdir artifact-3-directory
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().downloadArtifact('my-artifact-3','artifact-3-directory'))"
- name: Verify downloadArtifact() const fileContents = ['artifact-path/first.txt','artifact-path/second.txt']
shell: bash
run: |
packages/artifact/__tests__/test-artifact-file.sh "artifact-1-directory/artifact-path/world.txt" "${{ env.non-gzip-artifact-content }}"
packages/artifact/__tests__/test-artifact-file.sh "artifact-2-directory/artifact-path/gzip.txt" "${{ env.gzip-artifact-content }}"
packages/artifact/__tests__/test-artifact-file.sh "artifact-3-directory/artifact-path/empty.txt" "${{ env.empty-artifact-content }}"
- name: Download artifacts using downloadAllArtifacts() const uploadResult = await artifact.create().uploadArtifact(artifactName, fileContents, './')
run: | console.log(uploadResult)
mkdir multi-artifact-directory
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().downloadAllArtifacts('multi-artifact-directory'))"
- name: Verify downloadAllArtifacts() const success = uploadResult.success
shell: bash const size = uploadResult.size
run: | const id = uploadResult.id
packages/artifact/__tests__/test-artifact-file.sh "multi-artifact-directory/my-artifact-1/artifact-path/world.txt" "${{ env.non-gzip-artifact-content }}"
packages/artifact/__tests__/test-artifact-file.sh "multi-artifact-directory/my-artifact-2/artifact-path/gzip.txt" "${{ env.gzip-artifact-content }}" if (!success) {
packages/artifact/__tests__/test-artifact-file.sh "multi-artifact-directory/my-artifact-3/artifact-path/empty.txt" "${{ env.empty-artifact-content }}" throw new Error('Failed to upload artifact')
} else {
console.log(`Successfully uploaded artifact ${id}`)
}

View File

@ -1,6 +1,6 @@
import {HttpClient, HttpClientResponse, HttpCodes} from '@actions/http-client' import {HttpClient, HttpClientResponse, HttpCodes} from '@actions/http-client'
import {BearerCredentialHandler} from '@actions/http-client/lib/auth' import {BearerCredentialHandler} from '@actions/http-client/lib/auth'
import {info} from '@actions/core' import {info, debug} from '@actions/core'
import {ArtifactServiceClientJSON} from '../../generated' import {ArtifactServiceClientJSON} from '../../generated'
import {getResultsServiceUrl, getRuntimeToken} from './config' import {getResultsServiceUrl, getRuntimeToken} from './config'
@ -53,6 +53,7 @@ class ArtifactHttpClient implements Rpc {
data: object | Uint8Array data: object | Uint8Array
): Promise<object | Uint8Array> { ): Promise<object | Uint8Array> {
const url = `${this.baseUrl}/twirp/${service}/${method}` const url = `${this.baseUrl}/twirp/${service}/${method}`
debug(`Requesting ${url}`)
const headers = { const headers = {
'Content-Type': contentType 'Content-Type': contentType
} }