Skip to content

Commit db89f32

Browse files
authored
Merge pull request #134 from NHSDigital/develop
dms-2024-i5-r3
2 parents 2363d5d + 82f2220 commit db89f32

File tree

16 files changed

+269
-305
lines changed

16 files changed

+269
-305
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
name: Static Code Analysis
3+
4+
on: [pull_request]
5+
6+
jobs:
7+
brakeman:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Ruby + Bundle
13+
uses: ruby/setup-ruby@v1
14+
with:
15+
bundler-cache: true
16+
- name: Run Brakeman analysis
17+
run: bundle exec brakeman --parser-timeout 60
18+
19+
bundle-audit:
20+
runs-on: ubuntu-latest
21+
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Set up Ruby + Bundle
25+
uses: ruby/setup-ruby@v1
26+
with:
27+
bundler-cache: true
28+
- name: Audit the bundle
29+
# Ignore bootstrap version 3 warning: https://nhsd-jira.digital.nhs.uk/browse/NDRS2-1676
30+
run: bundle exec bundle-audit check --update --ignore CVE-2024-6484
31+
# run: bundle exec bundle-audit check --update
32+
33+
notify:
34+
# Run only on main, but regardless of whether tests past:
35+
if: ${{ always() }}
36+
# if: ${{ always() && github.ref == 'refs/heads/main' }}
37+
38+
needs:
39+
- brakeman
40+
- bundle-audit
41+
42+
runs-on: ubuntu-latest
43+
44+
steps:
45+
- uses: 8398a7/action-slack@v3
46+
with:
47+
status: custom
48+
fields: workflow,commit,author
49+
custom_payload: |
50+
{
51+
channel: '${{ secrets.SLACK_CHANNEL }}',
52+
username: 'GitHub CI',
53+
icon_emoji: ':robot_face:',
54+
attachments: [{
55+
text: '${{ github.event.commits[0].message }}',
56+
fields: [
57+
{ title: 'Author', value: '${{ github.actor }}', short: true },
58+
{ title: 'Revision', value: '${{ github.sha }}', short: true }
59+
]
60+
},{
61+
color: '${{ needs.brakeman.result }}' === 'success' ? 'good' : '${{ needs.brakeman.result }}' === 'failure' ? 'danger' : 'warning',
62+
text: `Brakeman checks returned *${{ needs.brakeman.result }}*.`
63+
},{
64+
color: '${{ needs.bundle-audit.result }}' === 'success' ? 'good' : '${{ needs.bundle-audit.result }}' === 'failure' ? 'danger' : 'warning',
65+
text: `Bundle Audit checks returned *${{ needs.bundle-audit.result }}*.`
66+
}]
67+
}
68+
env:
69+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.github/workflows/test.yml

Lines changed: 0 additions & 133 deletions
This file was deleted.

.github/workflows/tests.yml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
---
2+
# This file is @generated by `bin/rails generate test_strategy test_strategy_timings.csv`
3+
# Please edit the template and regenerate, rather than edit this file.
4+
5+
name: Tests
6+
7+
on: [pull_request]
8+
9+
permissions:
10+
contents: read
11+
actions: read
12+
13+
jobs:
14+
remaining_test_matrix:
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
ruby-version:
19+
- '3.1.6'
20+
test-group:
21+
- "[a-b]"
22+
- "[c]"
23+
- "[d-m]"
24+
- "[n-z]"
25+
26+
name: "Ruby ${{ matrix.ruby-version }} Tests (${{ matrix.test-group }})"
27+
28+
runs-on: ubuntu-latest
29+
30+
services:
31+
postgres:
32+
image: postgres
33+
env:
34+
POSTGRES_USER: rails
35+
POSTGRES_PASSWORD: rails_password
36+
options: >-
37+
--health-cmd pg_isready
38+
--health-interval 10s
39+
--health-timeout 5s
40+
--health-retries 5
41+
--name postgres
42+
ports:
43+
- 5432:5432
44+
45+
env:
46+
DB_HOST: localhost
47+
DB_PORT: 5432
48+
DB_USERNAME: rails
49+
DB_PASSWORD: rails_password
50+
51+
# Prep the whole stack in test-only mode:
52+
RAILS_ENV: test
53+
54+
steps:
55+
- uses: actions/checkout@v3
56+
- name: Set timezone to Europe/London
57+
run: sudo timedatectl set-timezone Europe/London
58+
- name: Use bundled npm files
59+
run: printf 'disable-self-update-check true\nyarn-offline-mirror "./vendor/npm-packages-offline-cache"\nyarn-offline-mirror-pruning false\n' > .yarnrc
60+
- name: Set up Ruby + Bundle
61+
uses: ruby/setup-ruby@v1
62+
with:
63+
bundler-cache: true
64+
ruby-version: ${{ matrix.ruby-version }}
65+
- name: Inject configuration
66+
run: cp config/database.yml{.ci,}
67+
- name: Prepare the database
68+
run: bin/rails db:setup
69+
- name: Precompile assets
70+
# Since ruby/setup-ruby@v1 moved to Node.js v18 we need the extra options
71+
# until we move to newer webpacker / stop using it.
72+
# I've tried using a newer hash function in config/webpack/environment.js
73+
# by adding the following line, but this didn't help with github actions
74+
# # environment.config.set('output.hashFunction', 'sha256')
75+
# https://stackoverflow.com/questions/69692842/error-message-error0308010cdigital-envelope-routinesunsupported/73465262#73465262
76+
run: NODE_OPTIONS=--openssl-legacy-provider bin/rails yarn:install assets:clobber assets:precompile
77+
- name: Run tests
78+
run: PARALLEL_WORKERS=1 bin/rails test 'test/**/${{ matrix.test-group }}*_test.rb'
79+
80+
# A utility job upon which Branch Protection can depend,
81+
# thus remaining agnostic of the matrix.
82+
remaining_tests:
83+
if: ${{ always() }}
84+
runs-on: ubuntu-latest
85+
# name: Matrix
86+
needs: remaining_test_matrix
87+
steps:
88+
- name: Check build matrix status
89+
if: ${{ needs.remaining_test_matrix.result != 'success' }}
90+
run: exit 1
91+
92+
notify:
93+
# Run only on master, but regardless of whether tests past:
94+
if: ${{ always() }}
95+
# if: ${{ always() && github.ref == 'refs/heads/master' }}
96+
97+
needs:
98+
- remaining_tests
99+
100+
runs-on: ubuntu-latest
101+
102+
steps:
103+
- uses: actions/setup-node@v3
104+
# with:
105+
# node-version: '16.x'
106+
- id: slack-payload-generator
107+
env:
108+
COMMIT_MESSAGE: ${{ github.event.commits[0].message }}
109+
run: |-
110+
node -e "
111+
const passed = '${{ needs.integration_tests.result }}' === 'success' && '${{ needs.models_tests.result }}' === 'success' && '${{ needs.remaining_tests.result }}' === 'success'
112+
113+
const text = process.env.COMMIT_MESSAGE
114+
115+
let attachments = [
116+
{
117+
fallback: text,
118+
text: text,
119+
fields: [
120+
{ title: 'Author', value: '${{ github.actor }}', short: true },
121+
{ title: 'Revision', value: '${{ github.sha }}', short: true }
122+
]
123+
// ts: @commit.author[:time].to_i
124+
}
125+
]
126+
127+
if (passed) {
128+
attachments.push({
129+
color: 'good',
130+
text: 'Tests passed'
131+
})
132+
} else {
133+
attachments.push({
134+
color: 'danger',
135+
text: 'Test(s) failed'
136+
})
137+
}
138+
139+
let payload = {
140+
channel: '${{ secrets.SLACK_CHANNEL }}',
141+
username: 'GitHub CI',
142+
icon_emoji: ':robot_face:',
143+
attachments: attachments
144+
}
145+
146+
console.log('json=' + JSON.stringify(payload))
147+
" >> "$GITHUB_OUTPUT"
148+
- uses: 8398a7/action-slack@v3
149+
with:
150+
status: custom
151+
fields: workflow,commit,author
152+
custom_payload: ${{ steps.slack-payload-generator.outputs.json }}
153+
env:
154+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

config/application.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
module Mbis
1414
class Application < Rails::Application
1515
# Initialize configuration defaults for originally generated Rails version.
16-
config.load_defaults 6.1
16+
config.load_defaults 7.0
1717

1818
# Configuration for the application, engines, and railties goes here.
1919
#
@@ -70,5 +70,18 @@ class Application < Rails::Application
7070

7171
# TODO: Old Rails 6.0 default; disable this
7272
ActiveSupport.utc_to_local_returns_utc_offset_times = false
73+
74+
# TODO: Old Rails 6.1 default; disable this
75+
# Fails rails test test/models/concerns/workflow/model_test.rb:180
76+
config.active_support.executor_around_test_case = false
77+
78+
# TODO: Old Rails 6.1 default; disable this
79+
# Fixtures are incomplete, e.g. test/fixtures/memberships.yml needs to be defined
80+
config.active_record.verify_foreign_keys_for_fixtures = false
81+
82+
# Old Rails 6.1 default, required by devise_saml_authenticatable version 1.9.1
83+
# cf. https://github.com/apokalipto/devise_saml_authenticatable/issues/237
84+
# If we don't have this, the redirect when logging out from ADFS throws an application error.
85+
Rails.application.config.action_controller.raise_on_open_redirects = false
7386
end
7487
end

0 commit comments

Comments
 (0)