diff --git a/.github/workflows/run_tests_and_upload_to_firebase.yml b/.github/workflows/run_tests_and_upload_to_firebase.yml index 4b269bf..6a4ba00 100644 --- a/.github/workflows/run_tests_and_upload_to_firebase.yml +++ b/.github/workflows/run_tests_and_upload_to_firebase.yml @@ -43,6 +43,11 @@ jobs: run: | python -m unittest discover -s tests -p "test_*.py" + - name: Debug Environment Variables + run: | + echo "FIREBASE_TYPE: ${{ env.FIREBASE_TYPE }}" + echo "FIREBASE_PROJECT_ID: ${{ env.FIREBASE_PROJECT_ID }}" + - name: Check test status and run scraper/Firebase uploader if: ${{ steps.test.outcome == 'success' }} run: | diff --git a/src/firebase_uploader.py b/src/firebase_uploader.py index 0e7dc00..81e3a16 100644 --- a/src/firebase_uploader.py +++ b/src/firebase_uploader.py @@ -10,38 +10,30 @@ def initialize_firebase(): dotenv_path = find_dotenv() load_dotenv(dotenv_path) - FIREBASE_URL = os.getenv("FIREBASE_URL") - FIREBASE_KEY = os.getenv("FIREBASE_KEY") - FIREBASE_TYPE = os.getenv("FIREBASE_TYPE") - FIREBASE_PROJECT_ID = os.getenv("FIREBASE_PROJECT_ID") - FIREBASE_PRIVATE_KEY_ID = os.getenv("FIREBASE_PRIVATE_KEY_ID") - FIREBASE_PRIVATE_KEY = os.getenv("FIREBASE_PRIVATE_KEY") - FIREBASE_CLIENT_EMAIL = os.getenv("FIREBASE_CLIENT_EMAIL") - FIREBASE_CLIENT_ID = os.getenv("FIREBASE_CLIENT_ID") - FIREBASE_AUTH_URI = os.getenv("FIREBASE_AUTH_URI") - FIREBASE_TOKEN_URI = os.getenv("FIREBASE_TOKEN_URI") - FIREBASE_AUTH_PROVIDER_X509_CERT_URL = os.getenv( - "FIREBASE_AUTH_PROVIDER_X509_CERT_URL" - ) - FIREBASE_CLIENT_X509_CERT_URL = os.getenv("FIREBASE_CLIENT_X509_CERT_URL") - FIREBASE_UNIVERSE_DOMAIN = os.getenv("FIREBASE_UNIVERSE_DOMAIN") - - cred = credentials.Certificate( - { - "type": FIREBASE_TYPE, - "project_id": FIREBASE_PROJECT_ID, - "private_key_id": FIREBASE_PRIVATE_KEY_ID, - "private_key": FIREBASE_PRIVATE_KEY, - "client_email": FIREBASE_CLIENT_EMAIL, - "client_id": FIREBASE_CLIENT_ID, - "auth_uri": FIREBASE_AUTH_URI, - "token_uri": FIREBASE_TOKEN_URI, - "auth_provider_x509_cert_url": FIREBASE_AUTH_PROVIDER_X509_CERT_URL, - "client_x509_cert_url": FIREBASE_CLIENT_X509_CERT_URL, - "universe_domain": FIREBASE_UNIVERSE_DOMAIN, - } - ) - firebase_admin.initialize_app(cred, {"databaseURL": FIREBASE_URL}) + # Parse the credentials as JSON + cred_dict = { + "type": os.getenv("FIREBASE_TYPE"), + "project_id": os.getenv("FIREBASE_PROJECT_ID"), + "private_key_id": os.getenv("FIREBASE_PRIVATE_KEY_ID"), + "private_key": os.getenv("FIREBASE_PRIVATE_KEY").replace( + "\\n", "\n" + ), # Replace \\n with actual newlines + "client_email": os.getenv("FIREBASE_CLIENT_EMAIL"), + "client_id": os.getenv("FIREBASE_CLIENT_ID"), + "auth_uri": os.getenv("FIREBASE_AUTH_URI"), + "token_uri": os.getenv("FIREBASE_TOKEN_URI"), + "auth_provider_x509_cert_url": os.getenv( + "FIREBASE_AUTH_PROVIDER_X509_CERT_URL" + ), + "client_x509_cert_url": os.getenv("FIREBASE_CLIENT_X509_CERT_URL"), + "universe_domain": os.getenv("FIREBASE_UNIVERSE_DOMAIN"), + } + + # Remove any None values + cred_dict = {k: v for k, v in cred_dict.items() if v is not None} + + cred = credentials.Certificate(cred_dict) + firebase_admin.initialize_app(cred, {"databaseURL": os.getenv("FIREBASE_URL")}) def backup_songs(songs_ref, backup_ref):