Skip to content

raeperd/google-drive-download-action

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

Google drive download action

.github/workflows/test.yml Quality Gate Status Maintainability Rating Lines of Code Code Smells
Github action for downloading google-drive files or folder using Drives: list API

Usage

runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
      - uses: raeperd/raeperd/google-drive-download-action@v1.0
        with:
          clientId: ${{ secrets.CLIENT_ID }}
          clientSecret: ${{ secrets.CLIENT_SECRET }}
          redirectUri: ${{ secrets.REDIRECT_URI }}
          credential_json: ${{ secrets.CREDENTIAL_JSON }}
          q: "'1U-2NgagKTnqkIZrML52A2SsD9HDDeDN7' in parents"
          path: "./"
  • clientId (required)
    • Client id of oauth2 client application
  • clientSecret (required)
    • Client secret of oauth2 client application
  • redirectUri (required)
    • Redirect uri of oauth2 client application
  • credential_json (required)
    • credential.json value with refresh_token with scope https://www.googleapis.com/auth/drive.readonly
  • q (required)
    • Query string to search for files and folders
  • path (optional)
    • Path to download files default to working directory
    • Default to ./

Getting Started

Before we start, we need Google Drive Application Project and credential.json

Create Google Drive Application Project

  1. Create a Google Cloud project
  2. Setup Google API Oauth2 prerequisites
    • After creating your credentials, download the client_secret.json file from the API Console.
  3. Enable the Google Drive API

Create credential.json

  • Create credential.json using Node.js quickstart | Google Drive API
  • Or you can create credential.json using ts-node - npm
    1. Clone this repository, and install dependencies
    2. Move your client_secret.json file into repository directory with name oauth.keys.json
    3. ts-node write-credential.ts

❗❗ NEVER INCLUDE YOUR CLIENT SECRET (oauth.keys.json and credential.json) IN VERSION CONTROL ❗❗

Setting up repository secret

To run this action, we need 4 repository secret parameter

  1. clientId
  2. clientSecret
  3. redirectUri
  4. credential_json
  • First 3 parameters can be obtained by client_secret.json (or oauth.keys.json)
  • credential_json is contents of file credential.json created by you
    • This value is parsed by action, using JSON.parse() function.
    • Check out /src/input.ts for more detail

How to debug google drive api query

Use debug.ts file in this repo

  1. Define constants CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, CREDENTIAL_JSON
  2. Define constants query inside main() function
  3. Run ts-node ./debug.ts and checkout results

❗❗ **NEVER INCLUDE YOUR CHANGES OF debug.ts IN VERSION CONTROL ❗❗

License

License: MIT

Contacts

raeperd117@gmail.com