Skip to content

Commit 69535db

Browse files
Merge pull request #3 from depot/oidc
2 parents 0906e45 + 9d50b88 commit 69535db

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
## Inputs
3030
3131
- `version` (optional) - A string representing the version of the Depot CLI to install (e.g. `1.2.3`). The default value is `latest` which will install the latest available version. Can also specify a semver version range selector (e.g. `0.x.x`).
32+
- `oidc` (optional) - A boolean value indicating, if `true` the action will authenticate with the Depot API using GitHub Actions OIDC and set the `DEPOT_TOKEN` environment variable for future steps. This is typically not needed if you are using the `depot/build-push-action` action. The default value is `false`.
3233

3334
## Authentication
3435

Diff for: action.yml

+6
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,9 @@ inputs:
1414
the latest version for the target platform will be installed. Example: "0.0.2".
1515
default: latest
1616
required: false
17+
oidc:
18+
description: |-
19+
If set to true, the action will authenticate with the Depot API using OIDC
20+
and save the returned token as environment a `DEPOT_TOKEN` environment variable.
21+
default: 'false'
22+
required: false

Diff for: dist/index.js

+16
Original file line numberDiff line numberDiff line change
@@ -5454,6 +5454,22 @@ async function run() {
54545454
await installDepotCLI(url, resolvedVersion);
54555455
}
54565456
core.info(`depot ${resolvedVersion} is installed`);
5457+
// Attempt to exchange GitHub Actions OIDC token for temporary Depot trust relationship token
5458+
if (core.getBooleanInput('oidc')) {
5459+
if (!process.env.DEPOT_TOKEN) {
5460+
try {
5461+
const odicToken = await core.getIDToken('https://depot.dev');
5462+
const res = await client.postJson('https://depot.dev/api/auth/oidc/github-actions', { token: odicToken });
5463+
if (res.result && res.result.token) {
5464+
core.info(`Exchanged GitHub Actions OIDC token for temporary Depot token`);
5465+
core.exportVariable('DEPOT_TOKEN', res.result.token);
5466+
}
5467+
}
5468+
catch (err) {
5469+
core.info(`Unable to exchange GitHub OIDC token for temporary Depot token: ${err}`);
5470+
}
5471+
}
5472+
}
54575473
}
54585474
async function resolveVersion(version) {
54595475
const res = await client.get(`https://depot.dev/api/cli/release/${process.platform}/${process.arch}/${version}`);

Diff for: src/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,25 @@ async function run() {
2323
}
2424

2525
core.info(`depot ${resolvedVersion} is installed`)
26+
27+
// Attempt to exchange GitHub Actions OIDC token for temporary Depot trust relationship token
28+
if (core.getBooleanInput('oidc')) {
29+
if (!process.env.DEPOT_TOKEN) {
30+
try {
31+
const odicToken = await core.getIDToken('https://depot.dev')
32+
const res = await client.postJson<{ok: boolean; token: string}>(
33+
'https://depot.dev/api/auth/oidc/github-actions',
34+
{token: odicToken},
35+
)
36+
if (res.result && res.result.token) {
37+
core.info(`Exchanged GitHub Actions OIDC token for temporary Depot token`)
38+
core.exportVariable('DEPOT_TOKEN', res.result.token)
39+
}
40+
} catch (err) {
41+
core.info(`Unable to exchange GitHub OIDC token for temporary Depot token: ${err}`)
42+
}
43+
}
44+
}
2645
}
2746

2847
async function resolveVersion(version: string) {

0 commit comments

Comments
 (0)