Skip to content

Commit 54c6ee3

Browse files
thbarfchabouis
andauthored
Migration de Phoenix 1.4.10 à 1.5.7 (#1457)
* Start upgrading Phoenix * Follow changelog advice * Fix deprecation warning * Fix deprecation warning * Adapt code for deprecation (pubsub) * Adapt layout rendering as recommended * Upgrade phoenix_html_sanitizer * Fix difference seen in PhoenixDiff This is not required right now, but could be confusing to others (or myself) later. * Upgrade phoenix_live_reload * Upgrade gettext * Update timex to remove compilation warnings * Add git to the CircleCI build * Use alpine-compatible git install command * Add missing openssh-client package * Try to work around CircleCI build problem * Update eternal to fix deprecation warning * Fix duplicate init_test_session/2 error * Log where the git binary is * Attempt to save the git binary * Fix incantation to share the git binary * Add quickfix for missing git binary Until etalab/transport-ops#19 is handled. * Fix major blocking point Many tests would previously fail with the following error: ``` function Phoenix.Template.HTML.encode_to_iodata!/1 is undefined (module Phoenix.Template.HTML is not available) ``` After a fair bit of digging, I found that the default config today is different: https://github.com/jayjun/phoenix/blob/master/lib/phoenix/template.ex#L223-L225 `Phoenix.HTML.Engine` should be used instead of `Phoenix.Template.HTML`. I am removing the entry completely since: - `html` will be handled fine with the default configuration - `json` will leverage `Phoenix.json_library`, which is configured just above * Add useful boilerplate for later debugging * Remove fetch_flash since we already have fetch_live_flash The default boilerplate does not use both, and fetch_live_flash includes the previous one (https://github.com/phoenixframework/phoenix_live_view/blob/v0.15.4/lib/phoenix_live_view/router.ex#L132). * Remove unused resource * Bump up Elixir dependency * Remove TODO for credo * Bump phoenix_live_view to latest * Try to fix solution tests by updating the chrome container * Update hound to latest * Stop using dialyxir release candidate & adjust configuration * Try to save some time during build debugging The build fails at PLT and I want to debug that, but each build will also recompiled dev + test each time, so I'm setting intermediate snapshots to hopefully shave off 7 minutes per build. * Fix deprecation warning * Attempt to reduce time taken by PLT construction for now * Add note * Fix linter error * Bump up yarn dependencies * Make browser window size deterministic (fixes #1504) * set chrome driver version to 86 As 88 make find_element function fail. * Add useful doc * Switch to dialyxir master version to get plt_local_path option * Save PLT files to a well-defined place * Ignore PLT files * Attempt to optimize build time (#1503, #1505) * Allow 20 minutes without STDOUT output for Dialyzer PLT construction * Attempt to fix dev/test compilation caching inefficience * Empty commit to trigger CI build * Revert to app_tree Co-authored-by: Francis <[email protected]>
1 parent 05de718 commit 54c6ee3

File tree

18 files changed

+126
-59
lines changed

18 files changed

+126
-59
lines changed

.circleci/config.yml

+58-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
version: 2
22

3+
# useful information at https://circleci.com/docs/2.0/language-elixir/
4+
35
default_docker: &default_docker
46
image: betagouv/transport:0.4.5
57
environment:
@@ -28,7 +30,7 @@ defaults_with_postgres_and_phantom: &defaults_with_postgres_and_phantom
2830
<<: *defaults
2931
docker:
3032
- *default_docker
31-
- image: selenium/standalone-chrome:3.141.59-oxygen
33+
- image: selenium/standalone-chrome:86.0
3234
- image: mdillon/postgis:11-alpine
3335
environment:
3436
POSTGRES_USER: root
@@ -41,14 +43,19 @@ jobs:
4143
steps:
4244
- checkout
4345

46+
# TODO: remove this once https://github.com/etalab/transport-ops/issues/19 is solved
47+
- run:
48+
name: Install git (required if we use git-hosted hex packages)
49+
command: apk add --update git
50+
4451
- restore_cache:
4552
keys:
46-
- elixir-v8-{{ checksum "mix.lock" }}
47-
53+
- elixir-v9-build-{{ checksum "mix.lock" }}
54+
4855
- run:
4956
name: Install hex
5057
command: mix local.hex --force
51-
58+
5259
- run:
5360
name: Install rebar
5461
command: mix local.rebar --force
@@ -69,6 +76,13 @@ jobs:
6976
name: Compile mix dependencies for MIX_ENV=test
7077
command: mix deps.compile
7178

79+
- save_cache:
80+
key: elixir-v9-build-{{ checksum "mix.lock" }}
81+
paths:
82+
- ~/transport/_build
83+
- ~/transport/deps
84+
- ~/.mix
85+
7286
- run:
7387
name: Install yarn dependencies
7488
command: cd ~/transport/apps/transport/client && yarn install
@@ -77,29 +91,42 @@ jobs:
7791
name: Compile assets
7892
command: cd ~/transport/apps/transport/client && npm run deploy
7993

94+
# NOTE: I think this should be moved to the dialyzer parallel section,
95+
# but then we need to think about how the persistence/caching will be
96+
# handled, and think about concurrent access (?) with various jobs to the cache.
97+
98+
- restore_cache:
99+
keys:
100+
- elixir-v8-plt-{{ checksum "mix.lock" }}
101+
80102
- run:
81103
name: Build PLT
82104
command: MIX_ENV=dev mix dialyzer --plt
105+
# PLT construction can stay up quite a bit without generating any output
106+
# We add a bit of tolerance here
107+
no_output_timeout: 20m
83108

109+
- save_cache:
110+
key: elixir-v8-plt-{{ checksum "mix.lock" }}
111+
paths:
112+
- ~/transport/dialyzer-plt
113+
84114
- persist_to_workspace:
85115
root: ~/transport
86116
paths:
87117
- .
88118

89-
- save_cache:
90-
key: elixir-v8-{{ checksum "mix.lock" }}
91-
paths:
92-
- ~/transport/_build
93-
- ~/transport/deps
94-
- ~/.mix
95-
96119
test_lint:
97120
<<: *defaults
98121

99122
steps:
100123
- attach_workspace:
101124
at: ~/transport
102125

126+
- run:
127+
name: Install git (required if we use git-hosted hex packages)
128+
command: apk add --update git
129+
103130
- run:
104131
name: Run linters
105132
command: |
@@ -125,6 +152,10 @@ jobs:
125152
- attach_workspace:
126153
at: ~/transport
127154

155+
- run:
156+
name: Install git (required if we use git-hosted hex packages)
157+
command: apk add --update git
158+
128159
- run:
129160
name: Run dialyzer (static analysis)
130161
command: MIX_ENV=dev mix dialyzer
@@ -135,6 +166,10 @@ jobs:
135166
- attach_workspace:
136167
at: ~/transport
137168

169+
- run:
170+
name: Install git (required if we use git-hosted hex packages)
171+
command: apk add --update git
172+
138173
- run:
139174
name: Run tests
140175
command: |
@@ -148,6 +183,10 @@ jobs:
148183
- attach_workspace:
149184
at: ~/transport
150185

186+
- run:
187+
name: Install git (required if we use git-hosted hex packages)
188+
command: apk add --update git
189+
151190
- run:
152191
name: Run tests
153192
command: |
@@ -161,6 +200,10 @@ jobs:
161200
- attach_workspace:
162201
at: ~/transport
163202

203+
- run:
204+
name: Install git (required if we use git-hosted hex packages)
205+
command: apk add --update git
206+
164207
- run:
165208
name: Run tests
166209
command: |
@@ -174,6 +217,10 @@ jobs:
174217
- attach_workspace:
175218
at: ~/transport
176219

220+
- run:
221+
name: Install git (required if we use git-hosted hex packages)
222+
command: apk add --update git
223+
177224
- run:
178225
name: Run tests
179226
command: |

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,6 @@ apps/transport/priv/static/js/*
3737
# the blog build folder
3838
/blog/public
3939
.clever.json
40+
41+
dialyzer-plt/*.plt
42+
dialyzer-plt/*.plt.hash

apps/gbfs/mix.exs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ defmodule GBFS.MixProject do
3333
{:cachex, "~> 3.3"},
3434
{:httpoison, "~> 1.5.0"},
3535
{:exshape, "~> 2.2.6"},
36-
{:phoenix, "~> 1.4"},
36+
{:phoenix, "~> 1.5.7"},
3737
{:iconv, "~> 1.0.10"},
3838
{:sweet_xml, ">= 0.0.0"},
3939
{:jason, ">= 0.0.0"},

apps/gbfs/test/support/conn_case.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ defmodule GBFS.ConnCase do
1919
using do
2020
quote do
2121
# Import conveniences for testing with connections
22-
use Phoenix.ConnTest
22+
import Plug.Conn
23+
import Phoenix.ConnTest
2324
alias GBFS.Router.Helpers, as: Routes
2425

2526
# The default endpoint for testing

apps/transport/client/javascripts/app.js

+7
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,10 @@ import LiveSocket from 'phoenix_live_view'
44
const csrfToken = document.querySelector('meta[name=\'csrf-token\']').getAttribute('content')
55
const liveSocket = new LiveSocket('/live', Socket, { params: { _csrf_token: csrfToken } })
66
liveSocket.connect()
7+
8+
// expose liveSocket on window for web console debug logs and latency simulation:
9+
// >> liveSocket.enableDebug()
10+
// >> liveSocket.enableLatencySim(1000) // enabled for duration of browser session
11+
// >> liveSocket.disableLatencySim()
12+
13+
// window.liveSocket = liveSocket

apps/transport/client/yarn.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -4827,13 +4827,13 @@ performance-now@^2.1.0:
48274827
integrity sha1-Ywn04OX6kT7BxpMHrjZLSzd8nns=
48284828

48294829
"phoenix@file:../../../deps/phoenix":
4830-
version "1.4.17"
4830+
version "1.5.7"
48314831

48324832
"phoenix_html@file:../../../deps/phoenix_html":
48334833
version "2.14.3"
48344834

48354835
"phoenix_live_view@file:../../../deps/phoenix_live_view":
4836-
version "0.14.0"
4836+
version "0.15.4"
48374837

48384838
picomatch@^2.0.4, picomatch@^2.0.5, picomatch@^2.2.1:
48394839
version "2.2.2"

apps/transport/lib/transport/application.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ defmodule Transport.Application do
1616
supervisor(TransportWeb.Endpoint, []),
1717
supervisor(ImportDataWorker, []),
1818
CSVDocuments,
19-
SearchCommunes
19+
SearchCommunes,
20+
{Phoenix.PubSub, [name: TransportWeb.PubSub, adapter: Phoenix.PubSub.PG2]}
2021
]
2122
|> add_scheduler()
2223
## manually add a children supervisor that is not scheduled

apps/transport/lib/transport_web.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ defmodule TransportWeb do
3636
namespace: TransportWeb
3737

3838
# Import convenience functions from controllers
39-
import Phoenix.Controller, only: [get_flash: 2, view_module: 1, get_csrf_token: 0]
39+
import Phoenix.Controller, only: [get_flash: 2, view_module: 1, get_csrf_token: 0, view_template: 1]
4040

4141
# Use all HTML functionality (forms, tags, etc)
4242
use TransportWeb.InputHelpers

apps/transport/lib/transport_web/router.ex

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ defmodule TransportWeb.Router do
1111
pipeline :browser do
1212
plug(:accepts, ["html"])
1313
plug(:fetch_session)
14-
plug(:fetch_flash)
1514
plug(:fetch_live_flash)
1615
plug(:protect_from_forgery)
1716
plug(:put_secure_browser_headers)

apps/transport/lib/transport_web/templates/layout/app.html.eex

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<% end %>
5959
<% end %>
6060

61-
<%= render(@view_module, @view_template, assigns) %>
61+
<%= @inner_content %>
6262
</main>
6363

6464
<%= render(LayoutView, "_footer.html", assigns) %>

apps/transport/mix.exs

+6-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ defmodule Transport.Mixfile do
55
[
66
app: :transport,
77
version: "0.0.1",
8-
elixir: "~> 1.8",
8+
elixir: "~> 1.10",
99
elixirc_paths: elixirc_paths(Mix.env()),
1010
build_path: "../../_build",
1111
config_path: "../../config/config.exs",
@@ -47,20 +47,21 @@ defmodule Transport.Mixfile do
4747
{:exconstructor, "~> 1.1"},
4848
{:gettext, "~> 0.11"},
4949
{:httpoison, "~> 1.5"},
50-
{:phoenix, "~> 1.4.10"},
50+
{:phoenix, "~> 1.5.7"},
5151
{:phoenix_html, "~> 2.13"},
5252
{:phoenix_markdown, "~> 1.0"},
53-
{:phoenix_live_view, "~> 0.14.0"},
53+
{:phoenix_live_view, "~> 0.15.0"},
5454
{:phoenix_html_sanitizer, "~> 1.1.0"},
5555
{:floki, ">= 0.0.0", only: :test},
56-
{:plug_cowboy, "~> 1.0"},
56+
{:plug_cowboy, "~> 2.1"},
5757
{:recon, "~> 2.4"},
5858
{:vex, "~> 0.8"},
5959
{:quantum, "~> 2.3"},
6060
{:timex, "~> 3.5"},
6161
{:sentry, "~> 7.1"},
6262
{:scrivener, "~> 2.5"},
63-
{:scrivener_html, "~> 1.8"},
63+
# We'll use upstream again once https://github.com/mgwidmann/scrivener_html/pull/98 is merged
64+
{:scrivener_html, git: "https://github.com/thbar/scrivener_html.git", branch: "phoenix_1.5"},
6465
{:scrivener_list, "~>2.0"},
6566
{:jason, "~> 1.1"},
6667
{:open_api_spex, "~> 3.8"},

apps/transport/test/support/channel_case.ex

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ defmodule TransportWeb.ChannelCase do
1818
using do
1919
quote do
2020
# Import conveniences for testing with channels
21-
use Phoenix.ChannelTest
21+
import Phoenix.ChannelTest
2222

2323
# The default endpoint for testing
2424
@endpoint TransportWeb.Endpoint

apps/transport/test/support/conn_case.ex

+6-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ defmodule TransportWeb.ConnCase do
1919
using do
2020
quote do
2121
# Import conveniences for testing with connections
22-
use Phoenix.ConnTest
22+
import Plug.Conn
23+
# NOTE: init_test_session delegates to Plug.Test as seen here,
24+
# https://github.com/phoenixframework/phoenix/blob/v1.5.7/lib/phoenix/test/conn_test.ex#L253
25+
# which is also imported, hence generating a compilation error.
26+
# This is due to how we configured the various "cases" I believe, and we'll have to clean that up.
27+
import Phoenix.ConnTest, except: [init_test_session: 2]
2328
import TransportWeb.Router.Helpers
2429

2530
# The default endpoint for testing

apps/transport/test/support/user_facing_case.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ defmodule TransportWeb.UserFacingCase do
99
using do
1010
quote do
1111
use Hound.Helpers
12-
hound_session()
12+
# NOTE: use a deterministic window size to make sure we do not meet failures
13+
# due to find_element needing "below the fold" search
14+
# See https://github.com/HashNuke/hound/issues/186
15+
hound_session(driver: %{chromeOptions: %{args: ["--window-size=1024,768"]}})
1316
end
1417
end
1518
end

config/config.exs

+2-8
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ config :gbfs, jcdecaux_apikey: System.get_env("JCDECAUX_APIKEY")
1414
config :gbfs, GBFS.Endpoint,
1515
secret_key_base: System.get_env("SECRET_KEY_BASE"),
1616
render_errors: [view: GBFS.ErrorView, accepts: ~w(json)],
17-
pubsub: [name: GBFS.PubSub, adapter: Phoenix.PubSub.PG2],
17+
pubsub_server: GBFS.PubSub, # TODO: verify if this is truly needed? unsure.
1818
server: false
1919

2020
# Configures the endpoint
@@ -26,19 +26,13 @@ config :transport, TransportWeb.Endpoint,
2626
layout: {TransportWeb.LayoutView, "app.html"},
2727
accepts: ~w(html json)
2828
],
29-
pubsub: [name: Transport.PubSub,
30-
adapter: Phoenix.PubSub.PG2],
29+
pubsub_server: TransportWeb.PubSub,
3130
live_view: [
3231
signing_salt: System.get_env("SECRET_KEY_BASE")
3332
]
3433

3534
config :phoenix, :json_library, Jason
3635

37-
# Configures format encoders
38-
config :phoenix, :format_encoders,
39-
html: Phoenix.Template.HTML,
40-
json: Jason
41-
4236
# Configures Elixir's Logger
4337
config :logger,
4438
handle_otp_reports: true,

dialyzer-plt/.gitkeep

Whitespace-only changes.

mix.exs

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ defmodule Transport.MixProject do
88
deps: deps(),
99
aliases: aliases(),
1010
test_coverage: [tool: ExCoveralls],
11-
dialyzer: [plt_add_deps: :transitive, plt_add_apps: [:mix]]
11+
dialyzer: [
12+
plt_add_deps: :app_tree,
13+
plt_add_apps: [:mix],
14+
plt_local_path: "dialyzer-plt",
15+
plt_core_path: "dialyzer-plt"
16+
]
1217
]
1318
end
1419

1520
defp deps do
1621
[
17-
{:dialyxir, "~> 1.0.0-rc.7", runtime: false},
22+
# NOTE: using master to be able to use `plt_local_path` option
23+
{:dialyxir, "~> 1.0.0", only: :dev, runtime: false, git: "https://github.com/jeremyjh/dialyxir.git"},
1824
{:excoveralls, "~> 0.10", only: :test}
1925
]
2026
end

0 commit comments

Comments
 (0)