Compare commits
1 commit
main
...
sethvargo/
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3b2dd40f9a |
2 changed files with 28 additions and 66 deletions
29
README.md
29
README.md
|
|
@ -26,19 +26,6 @@ support](https://cloud.google.com/support).**
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
- Run the `actions/checkout@v4` step _before_ this action. Omitting the
|
|
||||||
checkout step or putting it after `auth` will cause future steps to be
|
|
||||||
unable to authenticate.
|
|
||||||
|
|
||||||
- To create binaries, containers, pull requests, or other releases, add the
|
|
||||||
following to your `.gitignore`, `.dockerignore` and similar files to prevent
|
|
||||||
accidentally committing credentials to your release artifact:
|
|
||||||
|
|
||||||
```text
|
|
||||||
# Ignore generated credentials from google-github-actions/auth
|
|
||||||
gha-creds-*.json
|
|
||||||
```
|
|
||||||
|
|
||||||
- This action runs using Node 20. Use a [runner
|
- This action runs using Node 20. Use a [runner
|
||||||
version](https://github.com/actions/virtual-environments) that supports this
|
version](https://github.com/actions/virtual-environments) that supports this
|
||||||
version of Node or newer.
|
version of Node or newer.
|
||||||
|
|
@ -237,20 +224,8 @@ regardless of the authentication mechanism.
|
||||||
generate a credentials file which can be used for authentication via gcloud
|
generate a credentials file which can be used for authentication via gcloud
|
||||||
and Google Cloud SDKs in other steps in the workflow. The default is true.
|
and Google Cloud SDKs in other steps in the workflow. The default is true.
|
||||||
|
|
||||||
The credentials file is exported into `$GITHUB_WORKSPACE`, which makes it
|
The credentials file is exported into the GitHub Actions temp directory,
|
||||||
available to all future steps and filesystems (including Docker-based GitHub
|
outside of the current workspace.
|
||||||
Actions). The file is automatically removed at the end of the job via a post
|
|
||||||
action. In order to use exported credentials, you **must** add the
|
|
||||||
`actions/checkout` step before calling `auth`. This is due to how GitHub
|
|
||||||
Actions creates `$GITHUB_WORKSPACE`:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
jobs:
|
|
||||||
job_id:
|
|
||||||
steps:
|
|
||||||
- uses: 'actions/checkout@v4' # Must come first!
|
|
||||||
- uses: 'google-github-actions/auth@v2'
|
|
||||||
```
|
|
||||||
|
|
||||||
- `export_environment_variables`: (Optional) If true, the action will export
|
- `export_environment_variables`: (Optional) If true, the action will export
|
||||||
common environment variables which are known to be consumed by popular
|
common environment variables which are known to be consumed by popular
|
||||||
|
|
|
||||||
63
src/main.ts
63
src/main.ts
|
|
@ -12,7 +12,8 @@
|
||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
import { join as pathjoin } from 'path';
|
import { join as pathjoin } from 'node:path';
|
||||||
|
import { mkdir } from 'node:fs/promises';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
exportVariable,
|
exportVariable,
|
||||||
|
|
@ -25,11 +26,10 @@ import {
|
||||||
import {
|
import {
|
||||||
errorMessage,
|
errorMessage,
|
||||||
exactlyOneOf,
|
exactlyOneOf,
|
||||||
isEmptyDir,
|
|
||||||
isPinnedToHead,
|
isPinnedToHead,
|
||||||
parseMultilineCSV,
|
|
||||||
parseBoolean,
|
parseBoolean,
|
||||||
parseDuration,
|
parseDuration,
|
||||||
|
parseMultilineCSV,
|
||||||
pinnedToHeadWarning,
|
pinnedToHeadWarning,
|
||||||
} from '@google-github-actions/actions-utils';
|
} from '@google-github-actions/actions-utils';
|
||||||
|
|
||||||
|
|
@ -141,44 +141,31 @@ export async function run(logger: Logger) {
|
||||||
if (createCredentialsFile) {
|
if (createCredentialsFile) {
|
||||||
logger.debug(`Creating credentials file`);
|
logger.debug(`Creating credentials file`);
|
||||||
|
|
||||||
// Note: We explicitly and intentionally export to GITHUB_WORKSPACE
|
// Get the runner's temporary directory. This is cleaned up between runs
|
||||||
// instead of RUNNER_TEMP, because RUNNER_TEMP is not shared with
|
// automatically, but also subsets of this directory are shared with
|
||||||
// Docker-based actions on the filesystem. Exporting to GITHUB_WORKSPACE
|
// Docker-based GitHub Actions.
|
||||||
// ensures that the exported credentials are automatically available to
|
const runnerTempDir = process.env.RUNNER_TEMP;
|
||||||
// Docker-based actions without user modification.
|
if (!runnerTempDir) {
|
||||||
|
throw new Error('$RUNNER_TEMP is not set');
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is an undocumented path that is shared with Docker containers as a
|
||||||
|
// volume and has path remapping.
|
||||||
//
|
//
|
||||||
// This has the unintended side-effect of leaking credentials over time,
|
// https://github.com/actions/runner/blob/0d24afa114c2ee4b6451e35f2ba2cb9b96955789/src/Runner.Worker/Handlers/ContainerActionHandler.cs#L193-L202
|
||||||
// because GITHUB_WORKSPACE is not automatically cleaned up on self-hosted
|
const githubHomeDir = pathjoin(runnerTempDir, '_github_home');
|
||||||
// runners. To mitigate this issue, this action defines a post step to
|
logger.debug(`Computed home directory: "${githubHomeDir}"`);
|
||||||
// remove any created credentials.
|
|
||||||
const githubWorkspace = process.env.GITHUB_WORKSPACE;
|
|
||||||
if (!githubWorkspace) {
|
|
||||||
throw new Error('$GITHUB_WORKSPACE is not set');
|
|
||||||
}
|
|
||||||
|
|
||||||
// There have been a number of issues where users have not used the
|
// Create the directory. Unlike $GITHUB_WORKSPACE, this directory may not
|
||||||
// "actions/checkout" step before our action. Our action relies on the
|
// yet exist.
|
||||||
// creation of that directory; worse, if a user puts "actions/checkout"
|
await mkdir(githubHomeDir, { recursive: true });
|
||||||
// after our action, it will delete the exported credential. This
|
logger.debug(`Created home directory: "${githubHomeDir}"`);
|
||||||
// following code does a small check to see if there are any files in the
|
|
||||||
// directory. It emits a warning if there are no files, since there may be
|
|
||||||
// legitimate use cases for authenticating without checking out the
|
|
||||||
// repository.
|
|
||||||
const githubWorkspaceIsEmpty = await isEmptyDir(githubWorkspace);
|
|
||||||
if (githubWorkspaceIsEmpty) {
|
|
||||||
logger.info(
|
|
||||||
`⚠️ The "create_credentials_file" option is true, but the current ` +
|
|
||||||
`GitHub workspace is empty. Did you forget to use ` +
|
|
||||||
`"actions/checkout" before this step? If you do not intend to ` +
|
|
||||||
`share authentication with future steps in this job, set ` +
|
|
||||||
`"create_credentials_file" to false.`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create credentials file.
|
// Generate an output file that is unique, but still coupled to the run
|
||||||
const outputFile = generateCredentialsFilename();
|
// and run attempt.
|
||||||
const outputPath = pathjoin(githubWorkspace, outputFile);
|
const credentialsPath = await client.createCredentialsFile(
|
||||||
const credentialsPath = await client.createCredentialsFile(outputPath);
|
pathjoin(githubHomeDir, generateCredentialsFilename()),
|
||||||
|
);
|
||||||
logger.info(`Created credentials file at "${credentialsPath}"`);
|
logger.info(`Created credentials file at "${credentialsPath}"`);
|
||||||
|
|
||||||
// Output to be available to future steps.
|
// Output to be available to future steps.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue