Skip to content

Commit 3e8c0bb

Browse files
authored
Merge branch 'main' into add-rails-8
2 parents 90bb842 + 36783c4 commit 3e8c0bb

31 files changed

+526
-136
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Build and publish
2+
3+
on:
4+
workflow_call: {}
5+
6+
jobs:
7+
build:
8+
name: Build
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
packages: read
13+
env:
14+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_6.1.gemfile
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Ruby
19+
uses: ruby/setup-ruby@v1
20+
with:
21+
bundler-cache: true
22+
23+
- name: Build gem
24+
run: bundle exec rake build
25+
26+
- name: Archive coverage
27+
if: success()
28+
uses: actions/upload-artifact@v4
29+
with:
30+
name: gem-pkg
31+
path: pkg/*.gem
32+
33+
publish:
34+
name: Publish
35+
needs: build
36+
if: github.ref_type == 'tag'
37+
runs-on: ubuntu-latest
38+
permissions:
39+
contents: read
40+
packages: write
41+
42+
steps:
43+
- name: Set up Ruby
44+
uses: ruby/setup-ruby@v1
45+
with:
46+
ruby-version: '3.2'
47+
48+
- uses: actions/download-artifact@v4
49+
with:
50+
name: gem-pkg
51+
path: pkg/
52+
53+
- name: Publish to GPR
54+
run: |
55+
mkdir -p $HOME/.gem
56+
touch $HOME/.gem/credentials
57+
chmod 0600 $HOME/.gem/credentials
58+
printf -- "---\n:github: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
59+
gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} pkg/*.gem
60+
env:
61+
GEM_HOST_API_KEY: "Bearer ${{secrets.GITHUB_TOKEN}}"
62+
OWNER: ${{ github.repository_owner }}
63+

.github/workflows/changelog.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Changelog
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- '**'
7+
8+
jobs:
9+
changelog-updated:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
with:
14+
fetch-depth: 1
15+
- name: Check if changelog updated
16+
id: changed-files-specific
17+
uses: tj-actions/changed-files@v44
18+
with:
19+
base_sha: ${{ github.event.pull_request.base.sha }}
20+
files: |
21+
CHANGELOG.md
22+
env:
23+
GITHUB_TOKEN: ${{ github.token }}
24+
25+
- name: Fail job if changelog not updated
26+
if: steps.changed-files-specific.outputs.any_changed == 'false'
27+
run: |
28+
exit 1
29+

.github/workflows/ci.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@ name: CI
22

33
on:
44
push:
5-
branches: [ main ]
6-
pull_request:
7-
branches: [ main ]
5+
branches:
6+
- '**'
7+
tags:
8+
- '**'
89

910
jobs:
1011
test:
1112
if: github.ref_type == 'branch' && github.ref_name != 'main'
1213
uses: ./.github/workflows/test.yml
13-
# code_quality:
14-
# if: github.ref_type == 'branch' && github.ref_name != 'main'
15-
# uses: ./.github/workflows/code_quality.yml
14+
15+
code_quality:
16+
if: github.ref_type == 'branch' && github.ref_name != 'main'
17+
uses: ./.github/workflows/code_quality.yml
18+
19+
build_publish:
20+
uses: ./.github/workflows/build_publish.yml

.github/workflows/code_quality.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'Code quality'
2+
on:
3+
workflow_call: {}
4+
5+
jobs:
6+
rubocop:
7+
name: Rubocop
8+
runs-on: ubuntu-latest
9+
env:
10+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/rails_7.2.gemfile
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- uses: ruby/setup-ruby@v1
15+
with:
16+
bundler-cache: true
17+
18+
- name: Inspecting with Rubocop
19+
run: bundle exec rubocop
20+

.github/workflows/test.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ jobs:
2424
env:
2525
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
2626
steps:
27-
- uses: actions/checkout@v3
28-
27+
- uses: actions/checkout@v4
2928
- name: Set up Ruby
3029
uses: ruby/setup-ruby@v1
3130
with:

.rubocop_todo.yml

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-07-02 19:48:59 UTC using RuboCop version 1.64.1.
3+
# on 2025-06-04 10:53:17 UTC using RuboCop version 1.75.2.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 11
9+
# Offense count: 12
1010
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
1111
# SupportedStyles: Gemfile, gems.rb, gemspec
1212
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
1313
Gemspec/DevelopmentDependencies:
1414
Exclude:
15-
- "rpi_auth.gemspec"
15+
- 'rpi_auth.gemspec'
1616

17-
# Offense count: 1
17+
# Offense count: 2
1818
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
1919
Metrics/AbcSize:
2020
Max: 23
@@ -28,20 +28,12 @@ RSpec/ExampleLength:
2828
RSpec/MultipleExpectations:
2929
Max: 4
3030

31-
# Offense count: 8
31+
# Offense count: 9
3232
# Configuration parameters: AllowSubject.
3333
RSpec/MultipleMemoizedHelpers:
3434
Max: 6
3535

36-
# Offense count: 10
36+
# Offense count: 13
3737
# Configuration parameters: AllowedGroups.
3838
RSpec/NestedGroups:
3939
Max: 5
40-
41-
# Offense count: 1
42-
# Configuration parameters: Include, CustomTransform, IgnoreMethods, IgnoreMetadata.
43-
# Include: **/*_spec.rb
44-
RSpec/SpecFilePathFormat:
45-
Exclude:
46-
- "spec/rpi_auth/models/authenticatable_spec.rb"
47-
- "spec/rpi_auth/models/with_tokens_spec.rb"

CHANGELOG.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,42 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
### Fixed
13+
- Reinstated static code analysis checks in CI (#73)
1314

1415
### Removed
1516

17+
## [v4.3.0]
18+
19+
### Added
20+
21+
- Add optional `on_login_success` callback (#90)
22+
23+
### Fixed
24+
25+
- Return boolean from `AccountTypes#student_account?` (#91)
26+
27+
### Removed
28+
29+
## [v4.2.1]
30+
31+
### Fixed
32+
33+
- Refresh access tokens before expiry (#89)
34+
35+
## [v4.2.0]
36+
37+
### Added
38+
39+
- Allow OmniAuth setup phase to be configured (#76)
40+
- Add `RpiAuth::Models::Roles#parsed_roles` (extracted from experience-cs) (#87)
41+
- Add `RpiAuth::Models::AccountTypes#student_account?` (extracted from experience-cs) (#87)
42+
43+
## [v4.1.1]
44+
45+
### Fixed
46+
47+
- Fix requiring of oauth2 to avoid `NoMethodError: undefined method 'config' for module OAuth2` (#86)
48+
1649
## [v4.1.0]
1750

1851
### Added
@@ -140,7 +173,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
140173
- rails model concern to allow host app to add auth behaviour to a model
141174
- callback, logout and failure routes to handle auth
142175

143-
[Unreleased]: https://github.com/RaspberryPiFoundation/rpi-auth/compare/v4.1.0...HEAD
176+
[Unreleased]: https://github.com/RaspberryPiFoundation/rpi-auth/compare/v4.3.0...HEAD
177+
[v4.3.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.3.0
178+
[v4.2.1]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.2.1
179+
[v4.2.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.2.0
180+
[v4.1.1]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.1.1
144181
[v4.1.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.1.0
145182
[v4.0.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v4.0.0
146183
[v3.6.0]: https://github.com/RaspberryPiFoundation/rpi-auth/releases/tag/v3.6.0

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ link_to 'Log out', rpi_auth_logout_path, params: { returnTo: '/thanks-dude' }
170170

171171
This has to be a relative URL, i.e. it has to start with a slash. This is to ensure there's no open redirect.
172172

173+
### Callback on successful login
174+
175+
If the RpiAuth configuration option `on_login_success` is set to a `Proc`, this will be called in the context of the `RpiAuth::AuthController#callback` action, i.e. `current_user` will be available. This is intended to allow apps to record successful logins.
176+
173177
### Globbed/catch-all routes
174178

175179
If your app has a catch-all route at the end of the routing table, you must

app/controllers/rpi_auth/auth_controller.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ def callback
2727
auth = request.env['omniauth.auth']
2828
self.current_user = RpiAuth.user_model.from_omniauth(auth)
2929

30+
run_login_success_callback
31+
3032
redirect_to ensure_relative_url(login_redirect_path)
3133
end
3234

@@ -53,6 +55,16 @@ def failure
5355

5456
private
5557

58+
def run_login_success_callback
59+
return unless RpiAuth.configuration.on_login_success.is_a?(Proc)
60+
61+
begin
62+
instance_exec(&RpiAuth.configuration.on_login_success)
63+
rescue StandardError => e
64+
Rails.logger.warn("Caught #{e} while processing on_login_success proc.")
65+
end
66+
end
67+
5668
def login_redirect_path
5769
unless RpiAuth.configuration.success_redirect.is_a?(Proc)
5870
return RpiAuth.configuration.success_redirect || request.env['omniauth.origin']

gemfiles/rails_6.1.gemfile.lock

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PATH
22
remote: ..
33
specs:
4-
rpi_auth (4.1.0)
4+
rpi_auth (4.3.0)
55
oauth2
66
omniauth-rails_csrf_protection (~> 1.0.0)
77
omniauth_openid_connect (~> 0.7.1)
@@ -100,13 +100,13 @@ GEM
100100
email_validator (2.2.4)
101101
activemodel
102102
erubi (1.13.1)
103-
faraday (2.13.0)
103+
faraday (2.13.4)
104104
faraday-net_http (>= 2.0, < 3.5)
105105
json
106106
logger
107107
faraday-follow_redirects (0.3.0)
108108
faraday (>= 1, < 3)
109-
faraday-net_http (3.4.0)
109+
faraday-net_http (3.4.1)
110110
net-http (>= 0.5.0)
111111
ffi (1.17.1)
112112
globalid (1.2.1)
@@ -116,14 +116,14 @@ GEM
116116
i18n (1.14.7)
117117
concurrent-ruby (~> 1.0)
118118
json (2.10.2)
119-
json-jwt (1.16.7)
119+
json-jwt (1.17.0)
120120
activesupport (>= 4.2)
121121
aes_key_wrap
122122
base64
123123
bindata
124124
faraday (~> 2.0)
125125
faraday-follow_redirects
126-
jwt (2.10.1)
126+
jwt (3.1.2)
127127
base64
128128
language_server-protocol (3.17.0.4)
129129
lint_roller (1.1.0)
@@ -162,13 +162,14 @@ GEM
162162
nokogiri (1.18.7)
163163
mini_portile2 (~> 2.8.2)
164164
racc (~> 1.4)
165-
oauth2 (2.0.9)
166-
faraday (>= 0.17.3, < 3.0)
167-
jwt (>= 1.0, < 3.0)
165+
oauth2 (2.0.12)
166+
faraday (>= 0.17.3, < 4.0)
167+
jwt (>= 1.0, < 4.0)
168+
logger (~> 1.2)
168169
multi_xml (~> 0.5)
169170
rack (>= 1.2, < 4)
170-
snaky_hash (~> 2.0)
171-
version_gem (~> 1.1)
171+
snaky_hash (~> 2.0, >= 2.0.3)
172+
version_gem (>= 1.1.8, < 3)
172173
omniauth (2.1.3)
173174
hashie (>= 3.4.6)
174175
rack (>= 2.2.3)
@@ -308,9 +309,9 @@ GEM
308309
simplecov_json_formatter (~> 0.1)
309310
simplecov-html (0.13.1)
310311
simplecov_json_formatter (0.1.4)
311-
snaky_hash (2.0.1)
312-
hashie
313-
version_gem (~> 1.1, >= 1.1.1)
312+
snaky_hash (2.0.3)
313+
hashie (>= 0.1.0, < 6)
314+
version_gem (>= 1.1.8, < 3)
314315
sprockets (4.2.1)
315316
concurrent-ruby (~> 1.0)
316317
rack (>= 2.2.4, < 4)
@@ -334,7 +335,7 @@ GEM
334335
validate_url (1.0.15)
335336
activemodel (>= 3.0.0)
336337
public_suffix
337-
version_gem (1.1.7)
338+
version_gem (1.1.8)
338339
webfinger (2.1.3)
339340
activesupport
340341
faraday (~> 2.0)

0 commit comments

Comments
 (0)