Github Action To Upload to Google Drive Using A Google OAuth2 Credentials. This is alternative of Google Drive action that use service account.
For example, you want to upload using Google Workspace Account but doesn't have permission to change the domain-wide delegation permission.
steps:
- uses: actions/checkout@v4.1.1
- name: Upload Artifacts TO Google Drive
uses: hsnfirdaus/action-upload-drive-oauth@v2.0.0
with:
target: <LOCAL_PATH_TO_YOUR_FILE>
client_id: ${{ secrets.<YOUR_OAUTH2_CLIENT_ID> }}
client_secret: ${{ secrets.<YOUR_OAUTH2_CLIENT_SECRET> }}
redirect_uri: ${{ secrets.<YOUR_OAUTH2_REDIRECT_URI> }}
credentials: ${{ github.event.inputs.credentials }}
parent_folder_id: <YOUR_DRIVE_FOLDER_ID>
At above example, we are using Github Actions Input for Manual Workflow.
Local path to the file to upload, can be relative from github runner current directory.
Google OAuth Client ID
Google OAuth Client Secret
Google OAuth Redirect URI
A OAuth2 Credential (JSON access_token, scope, token_type,...).
You can get the JSON using Google OAuth Playground. Make sure to select Drive API V3 Scope. After get authorization code, click "Exchange authorization code for token" button. In the response, It will looks something like this:
{
"access_token": "XXX",
"scope": "https://www.googleapis.com/auth/drive",
"token_type": "Bearer",
"expires_in": 3599,
"refresh_token": "XXX"
}
The id of the drive folder where you want to upload your file. It is the string of characters after the last /
when browsing to your folder URL.
The name of the file to be uploaded. Set to the target
filename if not specified.
A sub-folder where to upload your file. It will be created if non-existent and must remain unique. Useful to organize your drive like so:
📂 Release // parent folder
┃
┣ 📂 v1.0 // child folder
┃ ┗ 📜 uploaded_file_v1.0
┃
┣ 📂 v2.0 // child folder
┃ ┗ 📜 uploaded_file_v2.0
If set true, delete files with the same name before uploading.