How to enable github action to access secret property file

Viewed 3356

I was working on an android project where alot of sensitive api keys were involved. These keys were stored in a specific gradle property file which is ignored by git.

secret.properties
apikey="938484738288274932228"

The question is how can I enable github actions to access this property file and the values inside it without pushing the file to git.

already tried - making a fallback property file with blank values ( but the values might be required for future tests )

1 Answers

So this is the method I used to make this work.

  • First place base64 encode the file content of the property file you want to hide.
  • Then add that base64 string into a Github secret by going to setting in Github web client
  • Then set up GitHub action in the project and add the task to write decoded content into a file from GH secret
- name: Decode secrets.properties file
        env:
          SECRETS_PROPERTIES: ${{ secrets.SECRETS_PROPERTIES }}
        run: echo "$SECRETS_PROPERTIES" | base64 -d > ./secrets.properties
  • In your build.gradle file ( the one either in the root or /app directory ) you need to place the following code in order to let Gradle load the properties from the secrets.properties file.
def secretsPropertiesFile = rootProject.file("./secrets.properties")
def secretsProperties = new Properties()
secretsProperties.load(new FileInputStream(secretsPropertiesFile))
  • Accessing the values within gradle would be secretsProperties['apikey']

More resources:

Related