我一直在尝试使用Rails设置GitHub-actions,但是我遇到了RAILS_MASTER_KEY
(我猜测)的问题。
这是我在最后一步# 构建和运行测试
中收到的错误信息:
rails aborted!
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/runner/work/my-project/my-project/config/environment.rb:5:in `<main>'
/home/runner/work/my-project/my-project/bin/rails:9:in `<top (required)>'
/home/runner/work/my-project/my-project/bin/spring:15:in `require'
/home/runner/work/my-project/my-project/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'
Caused by:
ArgumentError: key must be 16 bytes
.github/workflows/main.yml
:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres:11
env:
POSTGRES_PASSWORD: xxxxxx
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
# Download a copy of the code in the repository before running CI tests
- name: Checkout repository
uses: actions/checkout@v2
# Setup Ruby
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.6
# NPM install
- name: NPM install with caching
uses: bahmutov/npm-install@v1.1.0
# with:
# cmd: install
# Build and run tests
- name: Build and run tests
env:
DATABASE_URL: postgres://postgres:@localhost:5432/test
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
run: |
sudo apt-get -yqq install libpq-dev
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rails db:prepare
bundle exec rails test
我推断这与我的RAILS_MASTER_KEY变量有关。
我检查了存储在我的项目环境变量中的密钥,发现它恰好为32字节。我不确定如何最好地进行下一步操作,而且我不愿删除密钥,因为我担心会破坏应用程序的其他部分。在我的观点中,设置一个32字节长度合法的密钥选项将更加可取,只是我不知道如何以及在哪里进行设置……
对于如何解决这个问题,您有什么想法吗?
tmate
来“ssh”到运行器并“四处查看”非常有用。我建议在“构建和运行测试”步骤之前添加 tmate 步骤,然后从运行器内部检查环境变量,尝试使用不同的命令运行测试等。https://github.com/marketplace/actions/debugging-with-tmate - Casey Flynnenv:
? 如果它仍然只设置在以下作业步骤上,则在使用tmate进行检查时不会出现。 - Casey Flynn