Merge pull request #2321 from actions/bdehamer/storage-record-orchestration-id
Custom user-agent string for storage record API reqs
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
# @actions/attest Releases
|
# @actions/attest Releases
|
||||||
|
|
||||||
|
## 3.2.0
|
||||||
|
|
||||||
|
- Add custom user-agent for more API calls [#2321](https://github.com/actions/toolkit/pull/2321)
|
||||||
|
|
||||||
## 3.1.0
|
## 3.1.0
|
||||||
|
|
||||||
- Add support for `ACTIONS_ORCHESTRATION_ID` in user-agent [#2320](https://github.com/actions/toolkit/pull/2320)
|
- Add support for `ACTIONS_ORCHESTRATION_ID` in user-agent [#2320](https://github.com/actions/toolkit/pull/2320)
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/attest",
|
"name": "@actions/attest",
|
||||||
"version": "3.0.0",
|
"version": "3.2.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@actions/attest",
|
"name": "@actions/attest",
|
||||||
"version": "3.0.0",
|
"version": "3.2.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^3.0.0",
|
"@actions/core": "^3.0.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@actions/attest",
|
"name": "@actions/attest",
|
||||||
"version": "3.1.0",
|
"version": "3.2.0",
|
||||||
"description": "Actions attestation lib",
|
"description": "Actions attestation lib",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"github",
|
"github",
|
||||||
@@ -36,7 +36,7 @@
|
|||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"Error: run tests from root\" && exit 1",
|
"test": "echo \"Error: run tests from root\" && exit 1",
|
||||||
"tsc": "tsc && cp src/package-version.cjs lib/"
|
"tsc": "tsc && cp src/internal/package-version.cjs lib/internal/"
|
||||||
},
|
},
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/actions/toolkit/issues"
|
"url": "https://github.com/actions/toolkit/issues"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {retry} from '@octokit/plugin-retry'
|
import {retry} from '@octokit/plugin-retry'
|
||||||
import {RequestHeaders} from '@octokit/types'
|
import {RequestHeaders} from '@octokit/types'
|
||||||
|
import {getUserAgent} from './internal/utils.js'
|
||||||
|
|
||||||
const CREATE_STORAGE_RECORD_REQUEST =
|
const CREATE_STORAGE_RECORD_REQUEST =
|
||||||
'POST /orgs/{owner}/artifacts/metadata/storage-record'
|
'POST /orgs/{owner}/artifacts/metadata/storage-record'
|
||||||
@@ -52,10 +53,16 @@ export async function createStorageRecord(
|
|||||||
): Promise<number[]> {
|
): Promise<number[]> {
|
||||||
const retries = retryAttempts ?? DEFAULT_RETRY_COUNT
|
const retries = retryAttempts ?? DEFAULT_RETRY_COUNT
|
||||||
const octokit = github.getOctokit(token, {retry: {retries}}, retry)
|
const octokit = github.getOctokit(token, {retry: {retries}}, retry)
|
||||||
|
|
||||||
|
const headersWithUserAgent = {
|
||||||
|
'User-Agent': getUserAgent(),
|
||||||
|
...headers
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await octokit.request(CREATE_STORAGE_RECORD_REQUEST, {
|
const response = await octokit.request(CREATE_STORAGE_RECORD_REQUEST, {
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
headers,
|
headers: headersWithUserAgent,
|
||||||
...buildRequestParams(artifactOptions, packageRegistryOptions)
|
...buildRequestParams(artifactOptions, packageRegistryOptions)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -3,5 +3,5 @@
|
|||||||
// ESLint rules and doesn't work reliably across all Node.js versions.
|
// ESLint rules and doesn't work reliably across all Node.js versions.
|
||||||
// By keeping this as a .cjs file, we can use require() naturally and export
|
// By keeping this as a .cjs file, we can use require() naturally and export
|
||||||
// the version for the ESM modules to import.
|
// the version for the ESM modules to import.
|
||||||
const packageJson = require('../package.json')
|
const packageJson = require('../../package.json')
|
||||||
module.exports = {version: packageJson.version}
|
module.exports = {version: packageJson.version}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
import {version} from './package-version.cjs'
|
||||||
|
|
||||||
|
export const getUserAgent = (): string => {
|
||||||
|
const baseUserAgent = `@actions/attest-${version}`
|
||||||
|
|
||||||
|
const orchId = process.env['ACTIONS_ORCHESTRATION_ID']
|
||||||
|
if (orchId) {
|
||||||
|
// Sanitize the orchestration ID to ensure it contains only valid characters
|
||||||
|
// Valid characters: 0-9, a-z, _, -, .
|
||||||
|
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_')
|
||||||
|
return `${baseUserAgent} actions_orchestration_id/${sanitizedId}`
|
||||||
|
}
|
||||||
|
|
||||||
|
return baseUserAgent
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as github from '@actions/github'
|
import * as github from '@actions/github'
|
||||||
import {retry} from '@octokit/plugin-retry'
|
import {retry} from '@octokit/plugin-retry'
|
||||||
import {RequestHeaders} from '@octokit/types'
|
import {RequestHeaders} from '@octokit/types'
|
||||||
import {version} from './package-version.cjs'
|
import {getUserAgent} from './internal/utils.js'
|
||||||
|
|
||||||
const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
|
const CREATE_ATTESTATION_REQUEST = 'POST /repos/{owner}/{repo}/attestations'
|
||||||
const DEFAULT_RETRY_COUNT = 5
|
const DEFAULT_RETRY_COUNT = 5
|
||||||
@@ -52,17 +52,3 @@ export const writeAttestation = async (
|
|||||||
throw new Error(`Failed to persist attestation: ${message}`)
|
throw new Error(`Failed to persist attestation: ${message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const getUserAgent = (): string => {
|
|
||||||
const baseUserAgent = `@actions/attest-${version}`
|
|
||||||
|
|
||||||
const orchId = process.env['ACTIONS_ORCHESTRATION_ID']
|
|
||||||
if (orchId) {
|
|
||||||
// Sanitize the orchestration ID to ensure it contains only valid characters
|
|
||||||
// Valid characters: 0-9, a-z, _, -, .
|
|
||||||
const sanitizedId = orchId.replace(/[^a-z0-9_.-]/gi, '_')
|
|
||||||
return `${baseUserAgent} actions_orchestration_id/${sanitizedId}`
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseUserAgent
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user