2023-08-03 17:34:41 +00:00
|
|
|
# Temporarily disabled while v2.0.0 of @actions/artifact is under development
|
|
|
|
|
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
|
2023-01-03 15:59:01 +00:00
|
|
|
uses: actions/checkout@v3
|
2020-04-23 18:52:53 +00:00
|
|
|
|
2023-08-28 14:40:06 +00:00
|
|
|
- name: Set Node.js 20.x
|
2023-01-03 15:38:50 +00:00
|
|
|
uses: actions/setup-node@v3
|
2020-04-23 18:52:53 +00:00
|
|
|
with:
|
2023-08-28 14:40:06 +00:00
|
|
|
node-version: 20.x
|
2020-04-23 18:52:53 +00:00
|
|
|
|
|
|
|
# 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: |
|
2023-08-17 16:32:55 +00:00
|
|
|
echo "file1=hello from file 1" >> $GITHUB_ENV
|
|
|
|
echo "file2=hello from file 2" >> $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
|
2023-08-17 16:32:55 +00:00
|
|
|
echo '${{ env.file1 }}' > artifact-path/first.txt
|
|
|
|
echo '${{ env.file2 }}' > artifact-path/second.txt
|
2020-04-23 18:52:53 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
- name: Upload Artifacts using actions/github-script@v6
|
|
|
|
uses: actions/github-script@v6
|
2023-08-17 16:32:55 +00:00
|
|
|
with:
|
|
|
|
script: |
|
2023-08-17 18:40:33 +00:00
|
|
|
const artifact = require('./packages/artifact/lib/artifact')
|
2020-04-23 18:52:53 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
const artifactName = 'my-artifact-${{ matrix.runs-on }}'
|
|
|
|
console.log('artifactName: ' + artifactName)
|
2020-04-23 18:52:53 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
const fileContents = ['artifact-path/first.txt','artifact-path/second.txt']
|
2020-04-23 18:52:53 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
const uploadResult = await artifact.create().uploadArtifact(artifactName, fileContents, './')
|
|
|
|
console.log(uploadResult)
|
2023-08-17 16:32:55 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
const success = uploadResult.success
|
|
|
|
const size = uploadResult.size
|
|
|
|
const id = uploadResult.id
|
2023-08-17 16:32:55 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
if (!success) {
|
|
|
|
throw new Error('Failed to upload artifact')
|
|
|
|
} else {
|
|
|
|
console.log(`Successfully uploaded artifact ${id}`)
|
|
|
|
}
|
2023-08-17 16:32:55 +00:00
|
|
|
|
2023-08-17 18:40:33 +00:00
|
|
|
verify:
|
|
|
|
runs-on: ubuntu-latest
|
|
|
|
needs: [build]
|
|
|
|
steps:
|
|
|
|
- name: Checkout
|
|
|
|
uses: actions/checkout@v3
|
|
|
|
|
2023-08-28 14:40:06 +00:00
|
|
|
- name: Set Node.js 20.x
|
2023-08-17 18:40:33 +00:00
|
|
|
uses: actions/setup-node@v3
|
|
|
|
with:
|
2023-08-28 14:40:06 +00:00
|
|
|
node-version: 20.x
|
2023-08-17 18:40:33 +00:00
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
- name: List artifacts using actions/github-script@v6
|
|
|
|
uses: actions/github-script@v6
|
|
|
|
with:
|
|
|
|
script: |
|
|
|
|
const artifact = require('./packages/artifact/lib/artifact')
|
|
|
|
|
|
|
|
const workflowRunId = process.env.GITHUB_RUN_ID
|
|
|
|
const repository = process.env.GITHUB_REPOSITORY
|
|
|
|
const repositoryOwner = repository.split('/')[0]
|
|
|
|
const repositoryName = repository.split('/')[1]
|
|
|
|
|
|
|
|
const listResult = await artifact.create().listArtifacts(workflowRunId, repositoryOwner, repositoryName, '${{ secrets.GITHUB_TOKEN }}')
|
|
|
|
console.log(listResult)
|
|
|
|
|
|
|
|
const artifacts = listResult.artifacts
|
|
|
|
|
|
|
|
if (artifacts.length !== 3) {
|
|
|
|
throw new Error('Expected 3 artifacts but only found ' + artifacts.length + ' artifacts')
|
|
|
|
}
|
|
|
|
|
|
|
|
const artifactNames = artifacts.map(artifact => artifact.name)
|
|
|
|
if (!artifactNames.includes('my-artifact-ubuntu-latest')){
|
|
|
|
throw new Error("Expected artifact list to contain an artifact named my-artifact-ubuntu-latest but it's missing")
|
|
|
|
}
|
|
|
|
if (!artifactNames.includes('my-artifact-windows-latest')){
|
|
|
|
throw new Error("Expected artifact list to contain an artifact named my-artifact-windows-latest but it's missing")
|
|
|
|
}
|
|
|
|
if (!artifactNames.includes('my-artifact-macos-latest')){
|
|
|
|
throw new Error("Expected artifact list to contain an artifact named my-artifact-macos-latest but it's missing")
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log('Successfully listed artifacts that were uploaded')
|