Skip to content

Commit

Permalink
fix: make sure secrets are only available on master
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfbecker committed Nov 6, 2019
1 parent 69eea98 commit 88322bd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/travis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ const createTravisEnvVar = async ({
repoName,
name,
value,
branch,
travisClient,
}: {
repoName: string
name: string
value: string
branch?: string
travisClient: TravisClient
}): Promise<void> => {
await travisClient.post(`/repo/sourcegraph%2F${repoName}/env_vars`, {
Expand All @@ -35,6 +37,7 @@ const createTravisEnvVar = async ({
'env_var.name': name,
'env_var.value': value,
'env_var.public': false,
'env_var.branch': branch,
},
})
}
Expand Down Expand Up @@ -137,14 +140,14 @@ export async function initTravis({
} else {
const npmToken = await createSourcegraphBotNpmToken()
console.log('🔑 Setting NPM_TOKEN env var in Travis')
await createTravisEnvVar({ repoName, name: 'NPM_TOKEN', value: npmToken, travisClient })
await createTravisEnvVar({ repoName, name: 'NPM_TOKEN', value: npmToken, branch: 'master', travisClient })
}

if (envVars.env_vars.some((envVar: any) => envVar.name === 'GITHUB_TOKEN')) {
console.log('🔑 GITHUB_TOKEN already set in Travis, skipping creation')
} else {
const githubToken = await createSourcegraphBotGitHubToken({ repoName, githubClient })
console.log('🔑 Setting GITHUB_TOKEN env var in Travis')
await createTravisEnvVar({ repoName, name: 'GITHUB_TOKEN', value: githubToken, travisClient })
await createTravisEnvVar({ repoName, name: 'GITHUB_TOKEN', value: githubToken, branch: 'master', travisClient })
}
}

0 comments on commit 88322bd

Please sign in to comment.