I’m having trouble with GitHub Actions while trying to integrate with the Google Sheets API. I’m attempting to save my Google Sheets credentials as a credentials.json file from repository secrets, but the file that gets created is always empty. This results in an error in my Python script when I try to use the credentials for authentication.
Setup: I’ve added a repository secret named GOOGLE_SHEETS_CREDENTIALS in GitHub, which contains the correct JSON file generated from Google Cloud Console. In my GitHub Actions workflow, I’m trying to save the secret to a credentials.json file like this:
- name: Save Google Sheets credentials run: echo "${{ secrets.GOOGLE_SHEETS_CREDENTIALS }}" | tr -d '\r' > credentials.json
I’m checking whether the file was saved correctly using this step:
- name: Debug: Check if credentials.json is empty run: | if [ ! -s credentials.json ]; then echo "Error: credentials.json is empty!" exit 1 fi
The Problem: I keep getting an error message saying that the credentials.json file is empty.
I’ve double-checked the secret in GitHub, and it contains the correct JSON file. I also added a step to output the secret to the logs, but I don’t see any data there either.
What I’ve Tried: I’ve confirmed that the secret contains the full, valid JSON file from Google Cloud Console. I’ve used tr -d '\r' to remove any potential problematic line breaks. I’ve added debugging steps, but the file always ends up empty.
Has anyone encountered a similar issue or has any idea what could be going wrong? I would appreciate any help!