Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
pull_request:
merge_group:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions: {}

env:
Expand Down
36,690 changes: 16,881 additions & 19,809 deletions dist/chunk1.js

Large diffs are not rendered by default.

128 changes: 46 additions & 82 deletions dist/main.js
Original file line number Diff line number Diff line change
@@ -1,99 +1,63 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
const require_utils = require('./chunk1.js');








var _chunk1js = require('./chunk1.js');

// src/main.ts
var core2 = _chunk1js.__toESM.call(void 0, _chunk1js.require_core.call(void 0, ));

// src/registry_url.ts
var core = _chunk1js.__toESM.call(void 0, _chunk1js.require_core.call(void 0, ));
//#region src/registry_url.ts
var import_core$1 = /* @__PURE__ */ require_utils.__toESM(require_utils.require_core());
function getAudienceFromUrl(url) {
const audience = url.replace(/^https?:\/\//, "");
if (audience.startsWith("http://") || audience.startsWith("https://")) {
throw new Error(
"Bug: The audience should not include the protocol (http:// or https://)."
);
}
return audience;
const audience = url.replace(/^https?:\/\//, "");
if (audience.startsWith("http://") || audience.startsWith("https://")) throw new Error("Bug: The audience should not include the protocol (http:// or https://).");
return audience;
}
function getRegistryUrl() {
const url = core.getInput("url") || "https://crates.io";
if (url.endsWith("/")) {
return url.slice(0, -1);
}
return url;
const url = import_core$1.getInput("url") || "https://crates.io";
if (url.endsWith("/")) return url.slice(0, -1);
return url;
}

// src/main.ts
_chunk1js.runAction.call(void 0, run);
//#endregion
//#region src/main.ts
var import_core = /* @__PURE__ */ require_utils.__toESM(require_utils.require_core());
require_utils.runAction(run);
async function run() {
checkPermissions();
const registryUrl = getRegistryUrl();
const audience = getAudienceFromUrl(registryUrl);
const jwtToken = await getJwtToken(audience);
const token = await requestTrustedPublishingToken(registryUrl, jwtToken);
setTokenOutput(token);
core2.saveState(_chunk1js.TOKEN_KEY, token);
core2.saveState(_chunk1js.REGISTRY_URL_KEY, registryUrl);
checkPermissions();
const registryUrl = getRegistryUrl();
const token = await requestTrustedPublishingToken(registryUrl, await getJwtToken(getAudienceFromUrl(registryUrl)));
setTokenOutput(token);
import_core.saveState(require_utils.TOKEN_KEY, token);
import_core.saveState(require_utils.REGISTRY_URL_KEY, registryUrl);
}
/** Check that GitHub Actions workflow permissions are set correctly. */
function checkPermissions() {
if (process.env.ACTIONS_ID_TOKEN_REQUEST_URL === void 0 || !process.env.ACTIONS_ID_TOKEN_REQUEST_URL) {
throw new Error(
"Please ensure the 'id-token' permission is set to 'write' in your workflow. For more information, see: https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings"
);
}
if (process.env.ACTIONS_ID_TOKEN_REQUEST_URL === void 0 || !process.env.ACTIONS_ID_TOKEN_REQUEST_URL) throw new Error("Please ensure the 'id-token' permission is set to 'write' in your workflow. For more information, see: https://docs.github.com/en/actions/security-for-github-actions/security-hardening-your-deployments/about-security-hardening-with-openid-connect#adding-permissions-settings");
}
async function getJwtToken(audience) {
core2.info(`Retrieving GitHub Actions JWT token with audience: ${audience}`);
const jwtToken = await core2.getIDToken(audience);
if (!jwtToken) {
throw new Error("Failed to retrieve JWT token from GitHub Actions");
}
core2.info("Retrieved JWT token successfully");
return jwtToken;
import_core.info(`Retrieving GitHub Actions JWT token with audience: ${audience}`);
const jwtToken = await import_core.getIDToken(audience);
if (!jwtToken) throw new Error("Failed to retrieve JWT token from GitHub Actions");
import_core.info("Retrieved JWT token successfully");
return jwtToken;
}
async function requestTrustedPublishingToken(registryUrl, jwtToken) {
const tokenUrl = _chunk1js.getTokensEndpoint.call(void 0, registryUrl);
const userAgent = _chunk1js.getUserAgent.call(void 0, );
core2.info(
`Requesting token from: ${tokenUrl}. User agent: ${userAgent["User-Agent"]}`
);
const response = await fetch(tokenUrl, {
method: "POST",
headers: {
/* eslint-disable @typescript-eslint/naming-convention */
"Content-Type": "application/json",
...userAgent
},
body: JSON.stringify({ jwt: jwtToken })
});
if (!response.ok) {
await _chunk1js.throwHttpErrorMessage.call(void 0,
"Failed to retrieve token from Cargo registry",
response
);
}
const tokenResponse = await response.json();
if (!tokenResponse.token) {
await _chunk1js.throwHttpErrorMessage.call(void 0,
"Failed to retrieve token from the Cargo registry response body",
response
);
}
core2.info("Retrieved token successfully");
return tokenResponse.token;
const tokenUrl = require_utils.getTokensEndpoint(registryUrl);
const userAgent = require_utils.getUserAgent();
import_core.info(`Requesting token from: ${tokenUrl}. User agent: ${userAgent["User-Agent"]}`);
const response = await fetch(tokenUrl, {
method: "POST",
headers: {
"Content-Type": "application/json",
...userAgent
},
body: JSON.stringify({ jwt: jwtToken })
});
if (!response.ok) await require_utils.throwHttpErrorMessage("Failed to retrieve token from Cargo registry", response);
const tokenResponse = await response.json();
if (!tokenResponse.token) await require_utils.throwHttpErrorMessage("Failed to retrieve token from the Cargo registry response body", response);
import_core.info("Retrieved token successfully");
return tokenResponse.token;
}
function setTokenOutput(token) {
core2.setSecret(token);
core2.setOutput(_chunk1js.TOKEN_KEY, token);
import_core.setSecret(token);
import_core.setOutput(require_utils.TOKEN_KEY, token);
}


exports.run = run;
//#endregion
exports.run = run;
60 changes: 24 additions & 36 deletions dist/post.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,30 @@
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
const require_utils = require('./chunk1.js');








var _chunk1js = require('./chunk1.js');

// src/post.ts
var core = _chunk1js.__toESM.call(void 0, _chunk1js.require_core.call(void 0, ));
_chunk1js.runAction.call(void 0, cleanup);
//#region src/post.ts
var import_core = /* @__PURE__ */ require_utils.__toESM(require_utils.require_core());
require_utils.runAction(cleanup);
async function cleanup() {
const token = core.getState(_chunk1js.TOKEN_KEY);
const registryUrl = core.getState(_chunk1js.REGISTRY_URL_KEY);
if (!token) {
core.info("No token to revoke");
return;
}
await revokeToken(registryUrl, token);
const token = import_core.getState(require_utils.TOKEN_KEY);
const registryUrl = import_core.getState(require_utils.REGISTRY_URL_KEY);
if (!token) {
import_core.info("No token to revoke");
return;
}
await revokeToken(registryUrl, token);
}
async function revokeToken(registryUrl, token) {
const tokensEndpoint = _chunk1js.getTokensEndpoint.call(void 0, registryUrl);
core.info(`Revoking trusted publishing token at ${tokensEndpoint}`);
const response = await fetch(tokensEndpoint, {
method: "DELETE",
headers: {
/* eslint-disable @typescript-eslint/naming-convention */
Authorization: `Bearer ${token}`,
..._chunk1js.getUserAgent.call(void 0, )
}
});
if (!response.ok) {
await _chunk1js.throwHttpErrorMessage.call(void 0, "Failed to revoke token", response);
}
core.info("Token revoked successfully");
const tokensEndpoint = require_utils.getTokensEndpoint(registryUrl);
import_core.info(`Revoking trusted publishing token at ${tokensEndpoint}`);
const response = await fetch(tokensEndpoint, {
method: "DELETE",
headers: {
Authorization: `Bearer ${token}`,
...require_utils.getUserAgent()
}
});
if (!response.ok) await require_utils.throwHttpErrorMessage("Failed to revoke token", response);
import_core.info("Token revoked successfully");
}


exports.cleanup = cleanup;
//#endregion
exports.cleanup = cleanup;
2 changes: 1 addition & 1 deletion eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default defineConfig([
...tseslint.configs.strict,
...tseslint.configs.strictTypeChecked,
{
ignores: ["**/dist", "**/node_modules", "tsup.config.ts"],
ignores: ["**/dist", "**/node_modules", "tsdown.config.ts"],
},
{
files: ["src/**/*.ts", "*.mjs"],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Get a temporary access token that you can use to interact with crates.io.",
"private": true,
"scripts": {
"package": "tsup",
"package": "tsdown",
"format": "prettier --write .",
"lint": "eslint",
"test": "vitest"
Expand All @@ -28,8 +28,8 @@
"globals": "^16.4.0",
"msw": "^2.11.5",
"prettier": "^3.6.2",
"tsdown": "^0.15.10",
"tslib": "^2.8.1",
"tsup": "^8.5.0",
"typescript": "^5.9.3",
"typescript-eslint": "^8.46.1",
"vitest": "^3.2.4"
Expand Down
Loading