Skip to content

This action uploads files/folders to a Google Cloud Storage (GCS) bucket.

License

Notifications You must be signed in to change notification settings

yamatoya/upload-cloud-storage

 
 

Repository files navigation

upload-cloud-storage

This action uploads files/folders to a Google Cloud Storage (GCS) bucket. This is useful when you want upload build artifacts from your workflow.

Paths to files that are successfully uploaded are set as output variables and can be used in subsequent steps.

Prerequisites

  • This action requires Google Cloud credentials that are authorized to upload blobs to the specified bucket. See the Authorization section below for more information.

Usage

For uploading a file

steps:
  - id: upload-file
    uses: google-github-actions/upload-cloud-storage@main
    with:
      path: /path/to/file
      destination: bucket-name/file

  # Example of using the output
  - id: uploaded-files
    uses: foo/bar@master
    env:
      file: ${{steps.upload-file.outputs.uploaded}}

The file will be uploaded to gs://bucket-name/file

For uploading a folder

steps:
  - id: upload-files
    uses: google-github-actions/upload-cloud-storage@main
    with:
      path: /path/to/folder
      destination: bucket-name

  # Example of using the output
  - id: uploaded-files
    uses: foo/bar@master
    env:
      files: ${{steps.upload-files.outputs.uploaded}}

If the folder has the following structure:

.
└── folder
    ├── file1
    └── folder2
        └── file2

The files will be uploaded to gs://bucket-name/folder/file1,gs://bucket-name/folder/folder2/file2

Inputs

  • path: (Required) The path to a file or folder inside the action's filesystem that should be uploaded to the bucket.

    You can specify either the absolute path or the relative path from the action:

    path: /path/to/file
    path: ../path/to/file
  • destination: (Required) The destination for the file/folder in the form bucket-name or with an optional prefix in the form bucket-name/prefix

    destination: bucket-name

    In the above example, the file will be uploaded to gs://bucket-name/file

    destination: bucket-name/prefix

    In the above example, the file will be uploaded to gs://bucket-name/prefix/file

  • gzip: (Optional) Upload file(s) with gzip content encoding, defaults to true.

    gzip: false

    In the above example, the file(s) will be uploaded without gzip content-encoding

  • credentials: (Optional) Google Service Account JSON credentials as JSON or base64 encoded string, typically sourced from a GitHub Secret. If unspecified, other authentication methods are attempted. See Authorization below.

Outputs

List of successfully uploaded file(s).

For example:

steps:
  - id: upload-file
    uses: google-github-actions/upload-cloud-storage@main
    with:
      path: /path/to/file
      destination: bucket-name/file

will be available in future steps as the output "uploaded":

- id: publish
  uses: foo/bar@master
  env:
    file: ${{steps.upload-file.outputs.uploaded}}

Authorization

There are a few ways to authenticate this action. The caller must have permissions to access the secrets being requested.

Via the setup-gcloud action

You can provide credentials using the setup-gcloud action:

- uses: google-github-actions/setup-gcloud@master
  with:
    service_account_key: ${{ secrets.GCP_SA_KEY }}
    export_default_credentials: true
- uses: google-github-actions/upload-cloud-storage@main

The advantage of this approach is that it authenticates all future actions. A disadvantage of this approach is that downloading and installing gcloud may be heavy for some use cases.

Via credentials

You can provide Google Cloud Service Account JSON directly to the action by specifying the credentials input. First, create a GitHub Secret that contains the JSON content, then import it into the action:

- id: upload-file
  uses: google-github-actions/upload-cloud-storage@main
  with:
    credentials: ${{ secrets.gcp_credentials }}
    path: /path/to/folder
    destination: bucket-name/file

Via Application Default Credentials

If you are hosting your own runners, and those runners are on Google Cloud, you can leverage the Application Default Credentials of the instance. This will authenticate requests as the service account attached to the instance. This only works using a custom runner hosted on GCP.

- id: upload-file
  uses: google-github-actions/upload-cloud-storage@main

The action will automatically detect and use the Application Default Credentials.

About

This action uploads files/folders to a Google Cloud Storage (GCS) bucket.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 92.3%
  • JavaScript 7.7%