mirror of
https://github.com/gradle/actions.git
synced 2025-04-22 02:39:19 +08:00
Move the env plumbing code to short-lived-token.ts
This commit is contained in:
parent
c3c6e7d786
commit
4deb17d8b1
@ -23,7 +23,7 @@ jobs:
|
||||
inject-develocity:
|
||||
env:
|
||||
DEVELOCITY_INJECTION_ENABLED: true
|
||||
DEVELOCITY_URL: https://ge.solutions-team.gradle.com
|
||||
DEVELOCITY_URL: https://ge-helm-cluster-unstable.grdev.net
|
||||
DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
|
||||
DEVELOCITY_CCUD_PLUGIN_VERSION: '2.0'
|
||||
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.DEVELOCITY_ACCESS_KEY }} # required to test against GE plugin 3.16.2
|
||||
@ -68,7 +68,7 @@ jobs:
|
||||
inject-develocity-short-lived-token-with-input:
|
||||
env:
|
||||
DEVELOCITY_INJECTION_ENABLED: true
|
||||
DEVELOCITY_URL: 'https://ge.solutions-team.gradle.com'
|
||||
DEVELOCITY_URL: 'https://ge-helm-cluster-unstable.grdev.net'
|
||||
DEVELOCITY_PLUGIN_VERSION: ${{ matrix.plugin-version }}
|
||||
DEVELOCITY_CCUD_PLUGIN_VERSION: '2.0'
|
||||
strategy:
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as core from '@actions/core'
|
||||
import {BuildScanConfig} from '../configuration'
|
||||
import {getToken} from './short-lived-token'
|
||||
import {setupToken} from './short-lived-token'
|
||||
|
||||
export async function setup(config: BuildScanConfig): Promise<void> {
|
||||
maybeExportVariable('DEVELOCITY_INJECTION_INIT_SCRIPT_NAME', 'gradle-actions.inject-develocity.init.gradle')
|
||||
@ -12,30 +12,12 @@ export async function setup(config: BuildScanConfig): Promise<void> {
|
||||
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_URL', config.getBuildScanTermsOfUseUrl())
|
||||
maybeExportVariable('DEVELOCITY_TERMS_OF_USE_AGREE', config.getBuildScanTermsOfUseAgree())
|
||||
}
|
||||
const develocityAccesskeyEnvVar = `DEVELOCITY_ACCESS_KEY`
|
||||
if (config.getDevelocityAccessKey()) {
|
||||
try {
|
||||
core.debug('Fetching short-lived token...')
|
||||
const tokens = await getToken(
|
||||
getEnv('DEVELOCITY_ENFORCE_URL'),
|
||||
getEnv('DEVELOCITY_URL'),
|
||||
config.getDevelocityAccessKey(),
|
||||
config.getDevelocityTokenExpiry()
|
||||
)
|
||||
if (tokens != null && !tokens.isEmpty()) {
|
||||
core.debug(`Got token(s), setting the ${develocityAccesskeyEnvVar} env var`)
|
||||
const token = tokens.raw()
|
||||
core.setSecret(token)
|
||||
core.exportVariable(develocityAccesskeyEnvVar, token)
|
||||
} else {
|
||||
// In case of not being able to generate a token we set the env variable to empty to avoid leaks
|
||||
core.exportVariable(develocityAccesskeyEnvVar, '')
|
||||
}
|
||||
} catch (e) {
|
||||
core.exportVariable(develocityAccesskeyEnvVar, '')
|
||||
core.warning(`Failed to fetch short-lived token, reason: ${e}`)
|
||||
}
|
||||
}
|
||||
setupToken(
|
||||
config.getDevelocityAccessKey(),
|
||||
config.getDevelocityTokenExpiry(),
|
||||
getEnv('DEVELOCITY_ENFORCE_URL'),
|
||||
getEnv('DEVELOCITY_URL')
|
||||
)
|
||||
}
|
||||
|
||||
function getEnv(variableName: string): string | undefined {
|
||||
|
@ -1,6 +1,33 @@
|
||||
import * as httpm from 'typed-rest-client/HttpClient'
|
||||
import * as core from '@actions/core'
|
||||
|
||||
export async function setupToken(
|
||||
develocityAccessKey: string,
|
||||
develocityTokenExpiry: string,
|
||||
enforceUrl: string | undefined,
|
||||
develocityUrl: string | undefined
|
||||
): Promise<void> {
|
||||
const develocityAccesskeyEnvVar = 'DEVELOCITY_ACCESS_KEY'
|
||||
if (develocityAccessKey) {
|
||||
try {
|
||||
core.debug('Fetching short-lived token...')
|
||||
const tokens = await getToken(enforceUrl, develocityUrl, develocityAccessKey, develocityTokenExpiry)
|
||||
if (tokens != null && !tokens.isEmpty()) {
|
||||
core.debug(`Got token(s), setting the ${develocityAccesskeyEnvVar} env var`)
|
||||
const token = tokens.raw()
|
||||
core.setSecret(token)
|
||||
core.exportVariable(develocityAccesskeyEnvVar, token)
|
||||
} else {
|
||||
// In case of not being able to generate a token we set the env variable to empty to avoid leaks
|
||||
core.exportVariable(develocityAccesskeyEnvVar, '')
|
||||
}
|
||||
} catch (e) {
|
||||
core.exportVariable(develocityAccesskeyEnvVar, '')
|
||||
core.warning(`Failed to fetch short-lived token, reason: ${e}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getToken(
|
||||
enforceUrl: string | undefined,
|
||||
serverUrl: string | undefined,
|
||||
|
Loading…
x
Reference in New Issue
Block a user