mirror of https://github.com/actions/toolkit
Add tests for E2E artifact upload
parent
c9dab8c79d
commit
cf1b02a2e3
|
@ -50,48 +50,19 @@ 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
|
# We're using node -e to call the functions directly available in the @actions/artifact package
|
||||||
- name: Upload artifacts using uploadArtifact()
|
- name: Upload artifacts using uploadArtifact()
|
||||||
run: |
|
run: |
|
||||||
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-1',['artifact-path/world.txt'], process.argv[1]))" "${{ github.workspace }}"
|
node -e "Promise.resolve(require('./packages/artifact/lib/artifact').create().uploadArtifact('my-artifact',['artifact-path/first.txt','artifact-path/second.txt'], process.argv[1]))" "${{ github.workspace }}"
|
||||||
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()
|
|
||||||
run: |
|
|
||||||
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()
|
|
||||||
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()
|
|
||||||
run: |
|
|
||||||
mkdir multi-artifact-directory
|
|
||||||
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().downloadAllArtifacts('multi-artifact-directory'))"
|
|
||||||
|
|
||||||
- name: Verify downloadAllArtifacts()
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
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 }}"
|
|
||||||
packages/artifact/__tests__/test-artifact-file.sh "multi-artifact-directory/my-artifact-3/artifact-path/empty.txt" "${{ env.empty-artifact-content }}"
|
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
name: 'Set env variables'
|
||||||
|
description: 'Sets certain env variables so that e2e artifact upload, list, get and download can be tested in a shell'
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'index.js'
|
|
@ -0,0 +1,14 @@
|
||||||
|
// Certain env variables are not set by default in a shell context and are only available in a node context from a running action
|
||||||
|
// In order to be able to upload and download artifacts e2e in a shell when running CI tests, we need these env variables set
|
||||||
|
const fs = require('fs');
|
||||||
|
const os = require('os');
|
||||||
|
const filePath = process.env[`GITHUB_ENV`]
|
||||||
|
fs.appendFileSync(filePath, `ACTIONS_RESULTS_URL=${process.env.ACTIONS_RESULTS_URL}${os.EOL}`, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
})
|
||||||
|
fs.appendFileSync(filePath, `ACTIONS_RUNTIME_TOKEN=${process.env.ACTIONS_RUNTIME_TOKEN}${os.EOL}`, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
})
|
||||||
|
fs.appendFileSync(filePath, `GITHUB_RUN_ID=${process.env.GITHUB_RUN_ID}${os.EOL}`, {
|
||||||
|
encoding: 'utf8'
|
||||||
|
})
|
|
@ -10,8 +10,8 @@
|
||||||
],
|
],
|
||||||
"homepage": "https://github.com/actions/toolkit/tree/main/packages/artifact",
|
"homepage": "https://github.com/actions/toolkit/tree/main/packages/artifact",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "lib/artifact-client.js",
|
"main": "lib/artifact.js",
|
||||||
"types": "lib/artifact-client.d.ts",
|
"types": "lib/artifact.d.ts",
|
||||||
"directories": {
|
"directories": {
|
||||||
"lib": "lib",
|
"lib": "lib",
|
||||||
"test": "__tests__"
|
"test": "__tests__"
|
||||||
|
|
Loading…
Reference in New Issue