Skip to content

Commit

Permalink
[Artifacts] @actions/artifact list artifact functionality + download …
Browse files Browse the repository at this point in the history
…interface setup (#1495)

* actions/artifact preparation for download-artifact v4

* Test matrix strategy

* Fix needs dependency

* Improve list artifact test

* Fix typo

* Fix variables

* Cleanup download-all interfaces

* Fix tsc error

* Simplify to just name instead of artifactName

* Simplify to id instead of ArtifactId

* PR cleanup
  • Loading branch information
konradpabjan committed Aug 17, 2023
1 parent 20afb1a commit 7b617c2
Show file tree
Hide file tree
Showing 15 changed files with 772 additions and 71 deletions.
86 changes: 71 additions & 15 deletions .github/workflows/artifact-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,82 @@ jobs:
echo '${{ env.file1 }}' > artifact-path/first.txt
echo '${{ env.file2 }}' > artifact-path/second.txt
- uses: actions/github-script@v6
- name: Upload Artifacts using actions/github-script@v6
uses: actions/github-script@v6
with:
script: |
const artifact = require('./packages/artifact/lib/artifact')
const artifact = require('./packages/artifact/lib/artifact')
const artifactName = 'my-artifact-${{ matrix.runs-on }}'
console.log('artifactName: ' + artifactName)
const artifactName = 'my-artifact-${{ matrix.runs-on }}'
console.log('artifactName: ' + artifactName)
const fileContents = ['artifact-path/first.txt','artifact-path/second.txt']
const fileContents = ['artifact-path/first.txt','artifact-path/second.txt']
const uploadResult = await artifact.create().uploadArtifact(artifactName, fileContents, './')
console.log(uploadResult)
const uploadResult = await artifact.create().uploadArtifact(artifactName, fileContents, './')
console.log(uploadResult)
const success = uploadResult.success
const size = uploadResult.size
const id = uploadResult.id
const success = uploadResult.success
const size = uploadResult.size
const id = uploadResult.id
if (!success) {
throw new Error('Failed to upload artifact')
} else {
console.log(`Successfully uploaded artifact ${id}`)
}
if (!success) {
throw new Error('Failed to upload artifact')
} else {
console.log(`Successfully uploaded artifact ${id}`)
}
verify:
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x

# 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')
171 changes: 171 additions & 0 deletions packages/artifact/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions packages/artifact/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,12 @@
},
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.1.1",
"@actions/http-client": "^2.1.0",
"@azure/storage-blob": "^12.15.0",
"@octokit/core": "^3.5.1",
"@octokit/plugin-request-log": "^1.0.4",
"@octokit/plugin-retry": "^3.0.9",
"@protobuf-ts/plugin": "^2.2.3-alpha.1",
"archiver": "^5.3.1",
"crypto": "^1.0.1",
Expand Down
3 changes: 1 addition & 2 deletions packages/artifact/src/artifact.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {ArtifactClient, Client} from './internal/client'
import {UploadOptions} from './internal/upload/upload-options'
import {UploadResponse} from './internal/upload/upload-response'
import {UploadOptions, UploadResponse} from './internal/shared/interfaces'

/**
* Exported functionality that we want to expose for any users of @actions/artifact
Expand Down
Loading

0 comments on commit 7b617c2

Please sign in to comment.