2020-04-23 18:52:53 +00:00
name : artifact-unit-tests
2020-05-14 20:18:21 +00:00
on :
push :
branches :
2020-07-21 15:33:05 +00:00
- main
2020-05-14 20:18:21 +00:00
paths-ignore :
- '**.md'
pull_request :
paths-ignore :
- '**.md'
2020-04-23 18:52:53 +00:00
jobs :
build :
name : Build
strategy :
matrix :
2020-05-14 20:18:21 +00:00
runs-on : [ ubuntu-latest, windows-latest, macos-latest]
2020-04-23 18:52:53 +00:00
fail-fast : false
runs-on : ${{ matrix.runs-on }}
steps :
- name : Checkout
uses : actions/checkout@v2
2022-11-04 11:23:04 +00:00
- name : Set Node.js 16.x
2020-04-23 18:52:53 +00:00
uses : actions/setup-node@v1
with :
2022-11-04 11:23:04 +00:00
node-version : 16. x
2022-11-01 17:01:13 +00:00
- run : npm install -g npm@latest
2020-04-23 18:52:53 +00:00
# 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
# without these to just compile the artifacts package
- name : Install root npm packages
run : npm ci
- name : Compile artifact package
run : |
npm ci
npm run tsc
working-directory : packages/artifact
2021-12-14 20:50:50 +00:00
2020-04-23 18:52:53 +00:00
- name : Set artifact file contents
2020-09-30 13:46:54 +00:00
shell : bash
2020-04-23 18:52:53 +00:00
run : |
2020-09-30 13:46:54 +00:00
echo "non-gzip-artifact-content=hello" >> $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
2021-12-14 20:50:50 +00:00
echo "empty-artifact-content=_EMPTY_" >> $GITHUB_ENV
2020-04-23 18:52:53 +00:00
- name : Create files that will be uploaded
run : |
2021-12-14 20:50:50 +00:00
mkdir artifact-path
2020-04-23 18:52:53 +00:00
echo ${{ env.non-gzip-artifact-content }} > artifact-path/world.txt
echo ${{ env.gzip-artifact-content }} > artifact-path/gzip.txt
2021-12-14 20:50:50 +00:00
touch artifact-path/empty.txt
2020-04-23 18:52:53 +00:00
# We're using node -e to call the functions directly available in the @actions/artifact package
- name : Upload artifacts using uploadArtifact()
run : |
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-1',['artifact-path/world.txt'], '${{ github.workspace }}'))"
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-2',['artifact-path/gzip.txt'], '${{ github.workspace }}'))"
2021-12-14 20:50:50 +00:00
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().uploadArtifact('my-artifact-3',['artifact-path/empty.txt'], '${{ github.workspace }}'))"
2020-04-23 18:52:53 +00:00
- 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'))"
2021-12-14 20:50:50 +00:00
mkdir artifact-3-directory
node -e "Promise.resolve(require('./packages/artifact/lib/artifact-client').create().downloadArtifact('my-artifact-3','artifact-3-directory'))"
2020-04-23 18:52:53 +00:00
- name : Verify downloadArtifact()
shell : bash
run : |
2020-05-15 16:18:50 +00:00
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 }}"
2021-12-14 20:50:50 +00:00
packages/artifact/__tests__/test-artifact-file.sh "artifact-3-directory/artifact-path/empty.txt" "${{ env.empty-artifact-content }}"
2020-04-23 18:52:53 +00:00
- 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 : |
2020-05-15 16:18:50 +00:00
packages/artifact/__tests__/test-artifact-file.sh "multi-artifact-directory/my-artifact-1/artifact-path/world.txt" "${{ env.non-gzip-artifact-content }}"
2021-12-14 20:50:50 +00:00
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 }}"