I’m using GitHub Actions to run some tests on every push and I need DVC. I’m trying to make this work with the runs-on: ubuntu-latest
option but when I try to run it, the action get’s stuck because it requires manual authentication. Is there a way to go around this and automate the authentication ?
2
Answers
I figured out that in order for this to work, I had to switch to using a service account.
I had the same issue. Here are the steps I used to setup a Google Service Account with DVC, Google Drive and Github Actions.
Setup a google cloud platform service account
A google cloud platform service account "is a special kind of account used by an application or compute workload, such as a Compute Engine virtual machine (VM) instance, rather than a person. A service account is identified by its email address, which is unique to the account." In this case, the service account for your app to access Google Drive.
ENABLE
button+ Create Credentials
button and then selectService Account
.Create and continue
button.continue
at the "Grant this service account access to the project (optional)" section: No need to add any accesses.Done
at the "Grant users access to this service account (optional)". Again, no need to grant any additional accesses.key
–>add key
–>Create new key
andCreate
button. A JSON file of the key you created will download.Share access to the Google Drive folder where the DVC repo will live
Still on Google Cloud Platform,
service_account_name@project_id.iam.gserviceaccount.com
Set DVC config to use a google service account
On your local machine, modify the DVC project config file by typing the following commands. Change
my_remote
with your actual DVC remote name.dvc remote add --default my_remote gdrive://your_folder_hash
dvc remote modify my_remote gdrive_use_service_account true
dvc remote modify my_remote --local gdrive_service_account_json_file_path path/to/file.json
This will modify the .dvc/config and .dvc/config.local files in your project.
Run the command
dvc push
. If you see no error message, you are done with this step.Push your code to origin on Github
Setup a Repository Secret
New repository secret
button.Secret*
text box.Add Secret
buttonSetup a Github action
To your Github action yaml file, add the following (make sure to change the
YOUR_REPO_SECRET_NAME
to the name of the repo secret you created in the previous step.Commit this change and run the Github action!
References