Skip to content

Commit

Permalink
chore: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
devthejo committed Jan 7, 2025
1 parent cc7d4d3 commit ba2533b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
14 changes: 14 additions & 0 deletions dist/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -27593,41 +27593,55 @@ async function run() {
const tokenBureauUrl = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('token-bureau-url', { required: true });
const audience = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('audience', { required: true });

_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`Using token-bureau-url: ${tokenBureauUrl}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`Using audience: ${audience}`);

// Get OIDC token from GitHub Actions
const idToken = await _actions_core__WEBPACK_IMPORTED_MODULE_0__.getIDToken(audience);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug('Successfully obtained OIDC token');

// Extract current repository from environment
const repository = process.env.GITHUB_REPOSITORY?.split('/')[1];
if (!repository) {
throw new Error('GITHUB_REPOSITORY environment variable is not set');
}
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`Repository: ${repository}`);

// Request token from TokenBureau
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug('Sending request to TokenBureau');
const response = await fetch(`${tokenBureauUrl}/generate-token`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${idToken}`,
'Content-Type': 'application/json',
'Accept': 'application/json',
'User-Agent': 'token-bureau-action'
},
body: JSON.stringify({
repositories: [repository]
})
});

_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug(`Response status: ${response.status}`);

if (!response.ok) {
const error = await response.text();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.error(`Error response: ${error}`);
throw new Error(`Failed to get token: ${error}`);
}

const data = await response.json();
_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug('Successfully received token response');

// Set outputs
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setSecret(data.token);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('token', data.token);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('expires_at', data.expires_at);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setOutput('installation_id', data.installation_id);

_actions_core__WEBPACK_IMPORTED_MODULE_0__.debug('Action completed successfully');
} catch (error) {
_actions_core__WEBPACK_IMPORTED_MODULE_0__.error(`Action failed: ${error.message}`);
_actions_core__WEBPACK_IMPORTED_MODULE_0__.setFailed(error.message);
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/action/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@ async function run() {
const tokenBureauUrl = core.getInput('token-bureau-url', { required: true });
const audience = core.getInput('audience', { required: true });

console.log(`Using token-bureau-url: ${tokenBureauUrl}`);
console.log(`Using audience: ${audience}`);
core.debug(`Using token-bureau-url: ${tokenBureauUrl}`);
core.debug(`Using audience: ${audience}`);

// Get OIDC token from GitHub Actions
const idToken = await core.getIDToken(audience);
console.log('Successfully obtained OIDC token');
core.debug('Successfully obtained OIDC token');

// Extract current repository from environment
const repository = process.env.GITHUB_REPOSITORY?.split('/')[1];
if (!repository) {
throw new Error('GITHUB_REPOSITORY environment variable is not set');
}
console.log(`Repository: ${repository}`);
core.debug(`Repository: ${repository}`);

// Request token from TokenBureau
console.log('Sending request to TokenBureau');
core.debug('Sending request to TokenBureau');
const response = await fetch(`${tokenBureauUrl}/generate-token`, {
method: 'POST',
headers: {
Expand All @@ -35,7 +35,7 @@ async function run() {
})
});

console.log(`Response status: ${response.status}`);
core.debug(`Response status: ${response.status}`);

if (!response.ok) {
const error = await response.text();
Expand All @@ -44,15 +44,15 @@ async function run() {
}

const data = await response.json();
console.log('Successfully received token response');
core.debug('Successfully received token response');

// Set outputs
core.setSecret(data.token);
core.setOutput('token', data.token);
core.setOutput('expires_at', data.expires_at);
core.setOutput('installation_id', data.installation_id);

console.log('Action completed successfully');
core.debug('Action completed successfully');
} catch (error) {
core.error(`Action failed: ${error.message}`);
core.setFailed(error.message);
Expand Down

0 comments on commit ba2533b

Please sign in to comment.