Skip to content

Commit

Permalink
Merge branch 'main' into robherley/artifact-digest
Browse files Browse the repository at this point in the history
  • Loading branch information
robherley authored May 19, 2022
2 parents 35e5aac + 500d0b4 commit eb7ed88
Show file tree
Hide file tree
Showing 51 changed files with 2,800 additions and 280 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
inputs:
package:
required: true
description: 'core, artifact, cache, exec, github, glob, io, tool-cache'
description: 'core, artifact, cache, exec, github, glob, http-client, io, tool-cache'

jobs:
test:
runs-on: macos-latest
Expand All @@ -17,48 +17,48 @@ jobs:

- name: verify package exists
run: ls packages/${{ github.event.inputs.package }}

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

- name: npm install
run: npm install

- name: bootstrap
run: npm run bootstrap

- name: build
run: npm run build

- name: test
run: npm run test

- name: pack
run: npm pack
working-directory: packages/${{ github.event.inputs.package }}

- name: upload artifact
uses: actions/upload-artifact@v2
with:
name: ${{ github.event.inputs.package }}
path: packages/${{ github.event.inputs.package }}/*.tgz

publish:
runs-on: macos-latest
needs: test
environment: npm-publish
steps:

- name: download artifact
uses: actions/download-artifact@v2
with:
name: ${{ github.event.inputs.package }}

- name: setup authentication
run: echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" >> .npmrc
env:
env:
NPM_TOKEN: ${{ secrets.TOKEN }}

- name: publish
Expand All @@ -68,13 +68,13 @@ jobs:
if: failure()
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":":pb__failed: Failed to publish a new version of ${{ github.event.inputs.package }}"}' $SLACK_WEBHOOK
env:
env:
SLACK_WEBHOOK: ${{ secrets.SLACK }}

- name: notify slack on success
if: success()
run: |
curl -X POST -H 'Content-type: application/json' --data '{"text":":dance: Successfully published a new version of ${{ github.event.inputs.package }}"}' $SLACK_WEBHOOK
env:
env:
SLACK_WEBHOOK: ${{ secrets.SLACK }}

9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ $ npm install @actions/glob
```
<br/>

:phone: [@actions/http-client](packages/http-client)

A lightweight HTTP client optimized for building actions. Read more [here](packages/http-client)

```bash
$ npm install @actions/http-client
```
<br/>

:pencil2: [@actions/io](packages/io)

Provides disk i/o functions like cp, mv, rmRF, which etc. Read more [here](packages/io)
Expand Down
10 changes: 9 additions & 1 deletion packages/artifact/RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,12 @@

### 1.0.0

- Update `lockfileVersion` to `v2` in `package-lock.json [#1009](https://github.com/actions/toolkit/pull/1009)
- Update `lockfileVersion` to `v2` in `package-lock.json` [#1009](https://github.com/actions/toolkit/pull/1009)

### 1.0.1

- Update to v2.0.0 of `@actions/http-client`

### 1.0.2

- Update to v2.0.1 of `@actions/http-client` [#1087](https://github.com/actions/toolkit/pull/1087)
5 changes: 2 additions & 3 deletions packages/artifact/__tests__/retry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import * as net from 'net'
import * as core from '@actions/core'
import * as configVariables from '../src/internal/config-variables'
import {retry} from '../src/internal/requestUtils'
import {IHttpClientResponse} from '@actions/http-client/interfaces'
import {HttpClientResponse} from '@actions/http-client'

jest.mock('../src/internal/config-variables')
Expand Down Expand Up @@ -42,7 +41,7 @@ async function testRetry(

async function handleResponse(
testResponseCode: number | undefined
): Promise<IHttpClientResponse> {
): Promise<HttpClientResponse> {
if (!testResponseCode) {
throw new Error(
'Test incorrectly set up. reverse.pop() was called too many times so not enough test response codes were supplied'
Expand Down Expand Up @@ -72,7 +71,7 @@ async function emptyMockReadBody(): Promise<string> {

async function setupSingleMockResponse(
statusCode: number
): Promise<IHttpClientResponse> {
): Promise<HttpClientResponse> {
const mockMessage = new http.IncomingMessage(new net.Socket())
const mockReadBody = emptyMockReadBody
mockMessage.statusCode = statusCode
Expand Down
46 changes: 32 additions & 14 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: 2 additions & 2 deletions packages/artifact/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@actions/artifact",
"version": "1.0.0",
"version": "1.0.2",
"preview": true,
"description": "Actions artifact lib",
"keywords": [
Expand Down Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/http-client": "^1.0.11",
"@actions/http-client": "^2.0.1",
"tmp": "^0.2.1",
"tmp-promise": "^3.0.2"
},
Expand Down
8 changes: 4 additions & 4 deletions packages/artifact/src/internal/download-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {URL} from 'url'
import {StatusReporter} from './status-reporter'
import {performance} from 'perf_hooks'
import {ListArtifactsResponse, QueryArtifactResponse} from './contracts'
import {IHttpClientResponse} from '@actions/http-client/interfaces'
import {HttpClientResponse} from '@actions/http-client'
import {HttpManager} from './http-manager'
import {DownloadItem} from './download-specification'
import {getDownloadFileConcurrency, getRetryLimit} from './config-variables'
Expand Down Expand Up @@ -152,7 +152,7 @@ export class DownloadHttpClient {
const headers = getDownloadHeaders('application/json', true, true)

// a single GET request is used to download a file
const makeDownloadRequest = async (): Promise<IHttpClientResponse> => {
const makeDownloadRequest = async (): Promise<HttpClientResponse> => {
const client = this.downloadHttpManager.getClient(httpClientIndex)
return await client.get(artifactLocation, headers)
}
Expand Down Expand Up @@ -225,7 +225,7 @@ export class DownloadHttpClient {

// keep trying to download a file until a retry limit has been reached
while (retryCount <= retryLimit) {
let response: IHttpClientResponse
let response: HttpClientResponse
try {
response = await makeDownloadRequest()
} catch (error) {
Expand Down Expand Up @@ -295,7 +295,7 @@ export class DownloadHttpClient {
* @param isGzip a boolean denoting if the content is compressed using gzip and if we need to decode it
*/
async pipeResponseToFile(
response: IHttpClientResponse,
response: HttpClientResponse,
destinationStream: fs.WriteStream,
isGzip: boolean
): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion packages/artifact/src/internal/http-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {HttpClient} from '@actions/http-client/index'
import {HttpClient} from '@actions/http-client'
import {createHttpClient} from './utils'

/**
Expand Down
12 changes: 6 additions & 6 deletions packages/artifact/src/internal/requestUtils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {IHttpClientResponse} from '@actions/http-client/interfaces'
import {HttpClientResponse} from '@actions/http-client'
import {
isRetryableStatusCode,
isSuccessStatusCode,
Expand All @@ -11,11 +11,11 @@ import {getRetryLimit} from './config-variables'

export async function retry(
name: string,
operation: () => Promise<IHttpClientResponse>,
operation: () => Promise<HttpClientResponse>,
customErrorMessages: Map<number, string>,
maxAttempts: number
): Promise<IHttpClientResponse> {
let response: IHttpClientResponse | undefined = undefined
): Promise<HttpClientResponse> {
let response: HttpClientResponse | undefined = undefined
let statusCode: number | undefined = undefined
let isRetryable = false
let errorMessage = ''
Expand Down Expand Up @@ -71,9 +71,9 @@ export async function retry(

export async function retryHttpClientRequest(
name: string,
method: () => Promise<IHttpClientResponse>,
method: () => Promise<HttpClientResponse>,
customErrorMessages: Map<number, string> = new Map(),
maxAttempts = getRetryLimit()
): Promise<IHttpClientResponse> {
): Promise<HttpClientResponse> {
return await retry(name, method, customErrorMessages, maxAttempts)
}
9 changes: 4 additions & 5 deletions packages/artifact/src/internal/upload-http-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ import {promisify} from 'util'
import {URL} from 'url'
import {performance} from 'perf_hooks'
import {StatusReporter} from './status-reporter'
import {HttpCodes} from '@actions/http-client'
import {IHttpClientResponse} from '@actions/http-client/interfaces'
import {HttpCodes, HttpClientResponse} from '@actions/http-client'
import {HttpManager} from './http-manager'
import {UploadSpecification} from './upload-specification'
import {UploadOptions} from './upload-options'
Expand Down Expand Up @@ -421,7 +420,7 @@ export class UploadHttpClient {
digest
)

const uploadChunkRequest = async (): Promise<IHttpClientResponse> => {
const uploadChunkRequest = async (): Promise<HttpClientResponse> => {
const client = this.uploadHttpManager.getClient(httpClientIndex)
return await client.sendStream('PUT', resourceUrl, openStream(), headers)
}
Expand All @@ -432,7 +431,7 @@ export class UploadHttpClient {
// Increments the current retry count and then checks if the retry limit has been reached
// If there have been too many retries, fail so the download stops
const incrementAndCheckRetryLimit = (
response?: IHttpClientResponse
response?: HttpClientResponse
): boolean => {
retryCount++
if (retryCount > retryLimit) {
Expand Down Expand Up @@ -469,7 +468,7 @@ export class UploadHttpClient {

// allow for failed chunks to be retried multiple times
while (retryCount <= retryLimit) {
let response: IHttpClientResponse
let response: HttpClientResponse

try {
response = await uploadChunkRequest()
Expand Down
Loading

0 comments on commit eb7ed88

Please sign in to comment.