@actions/attest 2.0.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -15,6 +15,14 @@ initiated.
15
15
  See [Using artifact attestations to establish provenance for builds](https://docs.github.com/en/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds)
16
16
  for more information on artifact attestations.
17
17
 
18
+ ## Table of Contents
19
+ - [Usage](#usage)
20
+ - [attest](#attest)
21
+ - [attestProvenance](#attestprovenance)
22
+ - [Attestation](#attestation)
23
+ - [Sigstore Instance](#sigstore-instance)
24
+ - [Storage](#storage)
25
+
18
26
  ## Usage
19
27
 
20
28
  ### `attest`
@@ -165,6 +173,74 @@ export type Attestation = {
165
173
  For details about the Sigstore bundle format, see the [Bundle protobuf
166
174
  specification](https://github.com/sigstore/protobuf-specs/blob/main/protos/sigstore_bundle.proto).
167
175
 
176
+ ### createStorageRecord
177
+
178
+ The `createStorageRecord` function creates an
179
+ [artifact metadata storage record](https://docs.github.com/en/rest/orgs/artifact-metadata?apiVersion=2022-11-28#create-artifact-metadata-storage-record)
180
+ on behalf of an attested artifact. It accepts parameters defining artifact
181
+ and package registry details. The storage record contains metadata about where the artifact is stored on a given package registry.
182
+
183
+ ```js
184
+ const { createStorageRecord } = require('@actions/attest');
185
+ const core = require('@actions/core');
186
+
187
+ async function run() {
188
+ // In order to persist attestations to the repo, this should be a token with
189
+ // repository write permissions.
190
+ const ghToken = core.getInput('gh-token');
191
+
192
+ const record = await createStorageRecord(
193
+ artifactOptions: {
194
+ name: 'my-artifact-name',
195
+ digest: { 'sha256': '36ab4667...'},
196
+ version: "v1.0.0"
197
+ },
198
+ packageRegistryOptions: {
199
+ registryUrl: "https://my-fave-pkg-registry.com"
200
+ },
201
+ token: ghToken
202
+ );
203
+
204
+ console.log(record);
205
+ }
206
+
207
+ run();
208
+ ```
209
+
210
+ The `createStorageRecord` function supports the following options:
211
+
212
+ ```typescript
213
+ // Artifact details to associate the record with
214
+ export type ArtifactOptions = {
215
+ // The name of the artifact
216
+ name: string
217
+ // The digest of the artifact
218
+ digest: string
219
+ // The version of the artifact
220
+ version?: string
221
+ // The status of the artifact
222
+ status?: string
223
+ }
224
+ // Includes details about the package registry the artifact was published to
225
+ export type PackageRegistryOptions = {
226
+ // The URL of the package registry
227
+ registryUrl: string
228
+ // The URL of the artifact in the package registry
229
+ artifactUrl?: string
230
+ // The package registry repository the artifact was published to.
231
+ repo?: string
232
+ // The path of the artifact in the package registry repository.
233
+ path?: string
234
+ }
235
+ // GitHub token for writing attestations.
236
+ token: string
237
+ // Optional parameters for the write operation.
238
+ // The number of times to retry the request.
239
+ retryAttempts?: number
240
+ // HTTP headers to include in request to Artifact Metadata API.
241
+ headers?: RequestHeaders
242
+ ```
243
+
168
244
  ## Sigstore Instance
169
245
 
170
246
  When generating the signed attestation there are two different Sigstore
@@ -0,0 +1,28 @@
1
+ import { RequestHeaders } from '@octokit/types';
2
+ /**
3
+ * Options for creating a storage record for an attested artifact.
4
+ */
5
+ export type ArtifactOptions = {
6
+ name: string;
7
+ digest: string;
8
+ version?: string;
9
+ status?: string;
10
+ };
11
+ export type PackageRegistryOptions = {
12
+ registryUrl: string;
13
+ artifactUrl?: string;
14
+ repo?: string;
15
+ path?: string;
16
+ };
17
+ /**
18
+ * Writes a storage record on behalf of an artifact that has been attested
19
+ * @param artifactOptions - parameters for the storage record API request.
20
+ * @param packageRegistryOptions - parameters for the package registry API request.
21
+ * @param token - GitHub token used to authenticate the request.
22
+ * @param retryAttempts - The number of retries to attempt if the request fails.
23
+ * @param headers - Additional headers to include in the request.
24
+ *
25
+ * @returns The ID of the storage record.
26
+ * @throws Error if the storage record fails to persist.
27
+ */
28
+ export declare function createStorageRecord(artifactOptions: ArtifactOptions, packageRegistryOptions: PackageRegistryOptions, token: string, retryAttempts?: number, headers?: RequestHeaders): Promise<number[]>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
+ return new (P || (P = Promise))(function (resolve, reject) {
38
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
42
+ });
43
+ };
44
+ var __rest = (this && this.__rest) || function (s, e) {
45
+ var t = {};
46
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
47
+ t[p] = s[p];
48
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
49
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
50
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
51
+ t[p[i]] = s[p[i]];
52
+ }
53
+ return t;
54
+ };
55
+ Object.defineProperty(exports, "__esModule", { value: true });
56
+ exports.createStorageRecord = createStorageRecord;
57
+ const github = __importStar(require("@actions/github"));
58
+ const plugin_retry_1 = require("@octokit/plugin-retry");
59
+ const CREATE_STORAGE_RECORD_REQUEST = 'POST /orgs/{owner}/artifacts/metadata/storage-record';
60
+ const DEFAULT_RETRY_COUNT = 5;
61
+ /**
62
+ * Writes a storage record on behalf of an artifact that has been attested
63
+ * @param artifactOptions - parameters for the storage record API request.
64
+ * @param packageRegistryOptions - parameters for the package registry API request.
65
+ * @param token - GitHub token used to authenticate the request.
66
+ * @param retryAttempts - The number of retries to attempt if the request fails.
67
+ * @param headers - Additional headers to include in the request.
68
+ *
69
+ * @returns The ID of the storage record.
70
+ * @throws Error if the storage record fails to persist.
71
+ */
72
+ function createStorageRecord(artifactOptions, packageRegistryOptions, token, retryAttempts, headers) {
73
+ return __awaiter(this, void 0, void 0, function* () {
74
+ const retries = retryAttempts !== null && retryAttempts !== void 0 ? retryAttempts : DEFAULT_RETRY_COUNT;
75
+ const octokit = github.getOctokit(token, { retry: { retries } }, plugin_retry_1.retry);
76
+ try {
77
+ const response = yield octokit.request(CREATE_STORAGE_RECORD_REQUEST, Object.assign({ owner: github.context.repo.owner, headers }, buildRequestParams(artifactOptions, packageRegistryOptions)));
78
+ const data = typeof response.data == 'string'
79
+ ? JSON.parse(response.data)
80
+ : response.data;
81
+ return data === null || data === void 0 ? void 0 : data.storage_records.map((r) => r.id);
82
+ }
83
+ catch (err) {
84
+ const message = err instanceof Error ? err.message : err;
85
+ throw new Error(`Failed to persist storage record: ${message}`);
86
+ }
87
+ });
88
+ }
89
+ function buildRequestParams(artifactOptions, packageRegistryOptions) {
90
+ const { registryUrl, artifactUrl } = packageRegistryOptions, rest = __rest(packageRegistryOptions, ["registryUrl", "artifactUrl"]);
91
+ return Object.assign(Object.assign(Object.assign({}, artifactOptions), { registry_url: registryUrl, artifact_url: artifactUrl }), rest);
92
+ }
93
+ //# sourceMappingURL=artifactMetadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"artifactMetadata.js","sourceRoot":"","sources":["../src/artifactMetadata.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,kDA0BC;AAvED,wDAAyC;AACzC,wDAA2C;AAG3C,MAAM,6BAA6B,GACjC,sDAAsD,CAAA;AACxD,MAAM,mBAAmB,GAAG,CAAC,CAAA;AA4B7B;;;;;;;;;;GAUG;AACH,SAAsB,mBAAmB,CACvC,eAAgC,EAChC,sBAA8C,EAC9C,KAAa,EACb,aAAsB,EACtB,OAAwB;;QAExB,MAAM,OAAO,GAAG,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,mBAAmB,CAAA;QACpD,MAAM,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,EAAC,KAAK,EAAE,EAAC,OAAO,EAAC,EAAC,EAAE,oBAAK,CAAC,CAAA;QACnE,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,6BAA6B,kBAClE,KAAK,EAAE,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,EAChC,OAAO,IACJ,kBAAkB,CAAC,eAAe,EAAE,sBAAsB,CAAC,EAC9D,CAAA;YAEF,MAAM,IAAI,GACR,OAAO,QAAQ,CAAC,IAAI,IAAI,QAAQ;gBAC9B,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC;gBAC3B,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAA;YAEnB,OAAO,IAAI,aAAJ,IAAI,uBAAJ,IAAI,CAAE,eAAe,CAAC,GAAG,CAAC,CAAC,CAAe,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAA;QAC7D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,OAAO,GAAG,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,CAAA;YACxD,MAAM,IAAI,KAAK,CAAC,qCAAqC,OAAO,EAAE,CAAC,CAAA;QACjE,CAAC;IACH,CAAC;CAAA;AAED,SAAS,kBAAkB,CACzB,eAAgC,EAChC,sBAA8C;IAE9C,MAAM,EAAC,WAAW,EAAE,WAAW,KAAa,sBAAsB,EAA9B,IAAI,UAAI,sBAAsB,EAA5D,8BAAmC,CAAyB,CAAA;IAClE,qDACK,eAAe,KAClB,YAAY,EAAE,WAAW,EACzB,YAAY,EAAE,WAAW,KACtB,IAAI,EACR;AACH,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { createStorageRecord } from './artifactMetadata';
1
2
  export { AttestOptions, attest } from './attest';
2
3
  export { AttestProvenanceOptions, attestProvenance, buildSLSAProvenancePredicate } from './provenance';
3
4
  export type { SerializedBundle } from '@sigstore/bundle';
package/lib/index.js CHANGED
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildSLSAProvenancePredicate = exports.attestProvenance = exports.attest = void 0;
3
+ exports.buildSLSAProvenancePredicate = exports.attestProvenance = exports.attest = exports.createStorageRecord = void 0;
4
+ var artifactMetadata_1 = require("./artifactMetadata");
5
+ Object.defineProperty(exports, "createStorageRecord", { enumerable: true, get: function () { return artifactMetadata_1.createStorageRecord; } });
4
6
  var attest_1 = require("./attest");
5
7
  Object.defineProperty(exports, "attest", { enumerable: true, get: function () { return attest_1.attest; } });
6
8
  var provenance_1 = require("./provenance");
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAA8C;AAAvB,gGAAA,MAAM,OAAA;AAC7B,2CAIqB;AAFnB,8GAAA,gBAAgB,OAAA;AAChB,0HAAA,4BAA4B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAAsD;AAA9C,uHAAA,mBAAmB,OAAA;AAC3B,mCAA8C;AAAvB,gGAAA,MAAM,OAAA;AAC7B,2CAIqB;AAFnB,8GAAA,gBAAgB,OAAA;AAChB,0HAAA,4BAA4B,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actions/attest",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Actions attestation lib",
5
5
  "keywords": [
6
6
  "github",
@@ -55,4 +55,4 @@
55
55
  "@octokit/core": "^5.2.0"
56
56
  }
57
57
  }
58
- }
58
+ }