Skip to content

Experimental: Write workflows scripting the Google APIs in JavaScript

License

Notifications You must be signed in to change notification settings

tomoasleep/googleapis-script

Repository files navigation

googleapis-script

This action makes it easy to quickly write a script in your workflow that uses Google APIs. This action is inspired by actions/github-script.

⚠️ This action is still a bit of an experiment. The API and functionality may change.

Usage

In order to use this action, a script input is provided. The value of that input should be the body of an asynchronous function call. The following arguments will be provided:

See googleapis/google-api-nodejs-client for the API client documentation.

Authentication

In order to authenticate Google APIs these inputs are provided:

Before using Google APIs, you must be sure the API to use has been enabled. For more details, See: https://github.com/googleapis/google-auth-library-nodejs#application-default-credentials.

Example

Create a document from a template document

This example creates a new document and merge contents to it like the practice in https://developers.google.com/docs/api/how-tos/merge.

- uses: tomoasleep/googleapis-script@v1-alpha
  with:
    service-account-credentials-json: ${{ secrets.GOOGLE_APIS_CREDENTIAL_JSON }}
    scopes-json: '["https://www.googleapis.com/auth/documents", "https://www.googleapis.com/auth/drive.file"]'
    script: |
      // Create a new document from a template document.
      const newDoc = await google.drive("v3").files.copy({ fileId: "<TEMPLATE DOCUMENT ID>", supportsAllDrives: true })

      // Replace placeholders in the created document.
      const requests = [
        {
          replaceAllText: {
            containsText: { text: '{{date}}', matchCase: true },
            replaceText: new Date().toString(),
          },
        },
      ]
      const doc = await google.docs("v1").documents.batchUpdate({ documentId: newDoc.data.id, resource: { requests } })

      console.log(doc.data.documentId)
      core.setOutput("new-document-id", doc.data.documentId)

Development

This action is generated from actions/typescript-action. See development.md for details.

About

Experimental: Write workflows scripting the Google APIs in JavaScript

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published