Script Upload to Google Drive Shared Folder Github
Upload to Google Bulldoze
This is a GitHub action to upload a file or a folder (zipped) to Google Drive using a Google Service Account.
Table of Contents
- Changes
- Setup
- Google Service Account (GSA)
- Share Bulldoze folder with the GSA
- Store credentials as GitHub secrets
- Inputs
-
credentials
-
folder
-
target
-
proper noun
-
- Outputs
-
link
-
- Usage Examples
- Unproblematic file workflow example
- Simple folder workflow example
- Simple link workflow case
- Complex workflow example
- Documentation
Changes
v1.1
Added an output with a link to the Drive folder.
Setup
This section lists the requirements to brand this activity work and how to meet them.
Google Service Account (GSA)
First of all you volition demand a Google Service Business relationship for your project. Service accounts are just specific Google account types that are used by services instead of people.
To make i become to Service Accounts in the IAM and administration section of the Google Cloud Plattform dashboard and create a new project or cull the ane you lot are already using for your electric current shenanigans. Click on create new service account and proceed with the process. At the end you lot will get the choice to generate a key, we need this key so store information technology safely. It's a json file whith the post-obit construction:
{ "type": " " , "project_id": " " , "private_key_id": " " , "private_key": " " , "client_email": " " , "client_id": " " , "auth_uri": " " , "token_uri": " " , "auth_provider_x509_cert_url": " " , "client_x509_cert_url": " " }
Share Bulldoze folder with the GSA
Go to your Google Bulldoze and find the folder you want your files to be uploaded to and share information technology with the GSA. You can discover your service account email address in the client_email
holding of your GSA credentials. While you are here, take a note of the folder's ID, the long set up of characters later on the last /
in your address bar if you have the folder opened in your browser.
Store credentials as GitHub secrets
This action needs your GSA credentials to properly cosign with Google and nosotros don't want anybody to take a peek at them, right? Get to the Secrets section of your repo and add together a new surreptitious for your credentials. As per GitHub's recommendation, we will shop any complex data (similar your fancy JSON credentials) as a base64 encoded cord.
Y'all can encode jour .json
file easily into a new .txt
file using any bash terminal (just don't forget to change the placeholders with the real proper noun of your credentials file and and the desired output):
$ base64 CREDENTIALS_FILENAME.json > ENCODED_CREDENTIALS_FILENAME.txt
The contents of the newly generated .txt
file is what we have to procure as a value for our secret.
Of import: This activity assumes that the credentials are stored as a base64 encoded string. If that'due south not the example, the action volition fail.
Inputs
This section lists all inputs this activity tin can take.
credentials
Required: Yeah
A base64 encoded string with your GSA credentials.
folder
Required: Yes
The ID of the Google Drive binder yous want to upload to.
I would advise you store this as an environmental variable or a Github hole-and-corner
target
Required: Aye
The local path to the file or binder you want to upload.
If the path to a binder is given, it will be zipped before upload.
name
Required: NO
Default: nothing
The proper noun you want your zilch file to have.
- If the
target
input is a file, this input will be ignored.- If not provided, information technology volition default to the binder's proper name.
Outputs
This section lists all outputs this activity produces. A link to the Bulldoze binder.
link
A link to the Bulldoze folder.
Usage Examples
This department contains some useful examples.
Simple usage file workflow case
This a very simple workflow example that checks out the repo and uploads the README.md
file to a Google Drive binder every time there is a push button to chief.
name: Store readme in Drive on: push: { branches: [chief] } jobs: buildAndTestForSomePlatforms: proper name: Upload readme to drive runs-on: ubuntu-latest steps: # Checkout - name: Checkout repository uses: actions/checkout@v2 # Upload to Drive - name: Upload README.md to Google Drive uses: Jodebu/upload-to-drive@principal with: target: README.medico credentials: secrets.<YOUR_DRIVE_CREDENTIALS> binder: <YOUR_DRIVE_FOLDER_ID>
Simple folder workflow example
This a very simple workflow instance that checks out the repo and uploads the public
folder as a zip file to a Drive binder every time there is a push to master.
proper noun: Store public in Drive on: push: { branches: [master] } jobs: buildAndTestForSomePlatforms: proper noun: Upload public to drive runs-on: ubuntu-latest steps: # Checkout - name: Checkout repository uses: deportment/checkout@v2 # Upload to Drive - proper noun: Upload public folder to Google Drive uses: Jodebu/upload-to-drive@main with: target: public credentials: secrets.<YOUR_DRIVE_CREDENTIALS> folder: <YOUR_DRIVE_FOLDER_ID>
Uncomplicated link workflow example
This a very simple workflow example that checks out the repo and uploads the public
folder as a zip file to a Drive folder every time there is a push to master. Later that, information technology sends a Telegram message using Telegram Message Notify with a link to the folder.
name: Store public in Drive on: button: { branches: [main] } jobs: buildAndTestForSomePlatforms: proper name: Upload public to drive runs-on: ubuntu-latest steps: # Checkout - proper noun: Checkout repository uses: actions/checkout@v2 # Upload to Drive - proper name: Upload public folder to Google Drive uses: Jodebu/upload-to-drive@main id: driveUpload with: target: public credentials: secrets.<YOUR_DRIVE_CREDENTIALS> folder: <YOUR_DRIVE_FOLDER_ID> # Send Telegram message - name: Send link to file uses: appleboy/telegram-action@master with: to: ${{ secrets.TELEGRAM_TO }} token: ${{ secrets.TELEGRAM_TOKEN }} bulletin: File uploaded to ${{ steps.driveUpload.outputs.link }}
Complex workflow example
This is a little bit more than complex workflow example. This is really a simplified version of the current workflow that I utilise in my unity projects to examination, compile, and upload several platform builds at a time.
name: Dev build on: push: { branches: [develop] } env: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} jobs: buildAndTestForSomePlatforms: proper name: Build for ${{ matrix.targetPlatform }} on version ${{ matrix.unityVersion }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: projectPath: - examination-projection unityVersion: - 2019.3.14f1 targetPlatform: - StandaloneOSX - StandaloneWindows64 - StandaloneLinux64 steps: # Checkout - name: Checkout repository uses: actions/checkout@v2 with: lfs: true # Cache - uses: actions/enshroud@v1.i.0 with: path: ${{ matrix.projectPath }}/Library primal: Library-${{ matrix.projectPath }}-${{ matrix.targetPlatform }} restore-keys: | Library-${{ matrix.projectPath }}- Library- # Test - name: Run tests uses: webbertakken/unity-test-runner@v1.3 id: testRunner with: projectPath: ${{ matrix.projectPath }} unityVersion: ${{ matrix.unityVersion }} # Upload examination results - uses: deportment/upload-artifact@v1 with: proper name: Test results (all modes) path: ${{ steps.testRunner.outputs.artifactsPath }} # Build - name: Build projects uses: webbertakken/unity-builder@v0.x with: projectPath: ${{ matrix.projectPath }} unityVersion: ${{ matrix.unityVersion }} targetPlatform: ${{ matrix.targetPlatform }} buildName: ${{ secrets.APP_NAME }} # Upload to Drive - name: Upload build to Google Drive uses: Jodebu/upload-to-drive@main with: target: build name: ${{ matrix.targetPlatform }} credentials: ${{ secrets.DRIVE_CREDENTIALS }} folder: ${{ secrets.DRIVE_FOLDER }}
Documentation
A simple auto-generated documentation can be establish hither.
Source: https://github.com/Jodebu/upload-to-drive
0 Response to "Script Upload to Google Drive Shared Folder Github"
Post a Comment