Search code examples
ruby-on-railstestingcontinuous-integrationgithub-actionscredentials

Rails & Github Actions - Credentials


I have a Rails 6 app using the credentials storage built into Rails and I am running testing and CI on this app with Github Actions.

I have initializer code that uses credentials that passes test on my local machine because it uses credentials from config/credentials/test.yml.enc, however Actions can't access this file. I have seen suggestions online to set RAILS_MASTER_KEY as an environment variable with the key value from the credential key file, but I have set up RAILS_TEST_KEY (and RAILS_MASTER_KEY) to be the value of config/credentials/test.key with no luck. Does Rails know to look for this environment variable if the key file isn't present, or do I need to do something to point it to this variable?


Solution

  • Apologies, if i didn’t understand your question correctly. You can reference CI ENV variables using repository secrets. For example if you have ENV variable called RAILS_TEST_KEY in your CI yml file.

    env:
     RAILS_TEST_KEY: ${{ secrets.RAILS_TEST_KEY }}
    

    secrets.RAILS_TEST_KEY value can be set in repository secrets.

    https://docs.github.com/en/actions/reference/encrypted-secrets