Skip to content

Commit

Permalink
Détection automatique des liens morts dans le JSON et corrections ass…
Browse files Browse the repository at this point in the history
…ociées (#52)

* Create .tool-versions

* Install Elixir

* Revert versions

* Make sure those links do not regress

* Run the tests during CI

* Fix broken links (#50)
  • Loading branch information
thbar authored Feb 5, 2024
1 parent 07ff238 commit 74c89e7
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 4 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: erlef/setup-beam@v1
with:
version-file: .tool-versions
version-type: strict
- name: Installation Python 3.12
uses: actions/setup-python@v5
with:
Expand All @@ -38,3 +42,6 @@ jobs:
- name: Vérification du schéma dynamique et des fichiers d'exemples associés
run: |
frictionless validate --type schema dynamique/schema-dynamique.json
- name: Vérification de l'absence de liens cassés dans les schémas
run: |
elixir checks.exs
5 changes: 5 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# See useful links for maintenance here:
# https://github.com/etalab/transport-site/blob/master/.tool-versions

elixir 1.15.5-otp-24
erlang 24.3.4.13
41 changes: 41 additions & 0 deletions checks.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Mix.install([
{:jason, "~> 1.4"},
{:req, "~> 0.4.8"}
])

defmodule Deadlinks do
# scan an Elixir structure to find links
def scan(x) when is_list(x) or is_map(x) do
x
|> Enum.map(&scan(&1))
|> List.flatten()
|> Enum.reject(&is_nil(&1))
end

def scan(x) when is_tuple(x), do: scan(x |> Tuple.to_list())
def scan(value = "http" <> _), do: value
def scan(_), do: nil
end

broken_json_links =
"**/*.json"
|> Path.wildcard()
|> Enum.map(fn x ->
x
|> File.read!()
|> Jason.decode!()
end)
|> Deadlinks.scan()
|> Enum.uniq()
|> Enum.map(fn x ->
Req.head!(x)
|> Map.take([:status])
|> Map.put(:url, x)
end)
|> Enum.reject(fn %{status: x} -> x == 200 end)

unless broken_json_links == [] do
IO.puts("Some links are broken, please fix them:\n")
IO.puts(broken_json_links |> Enum.map(&inspect(&1)) |> Enum.join("\n"))
System.halt(1)
end
4 changes: 2 additions & 2 deletions dynamique/schema-dynamique.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"description": "Spécification du fichier d'échange relatif aux données concernant la localisation géographique et les caractéristiques techniques des stations et des points de recharge pour véhicules électriques",
"countryCode": "FR",
"homepage": "https://github.com/etalab/schema-irve",
"path": "https://github.com/etalab/schema-irve/raw/v2.2.1/schema.json",
"path": "https://raw.githubusercontent.com/etalab/schema-irve/v2.2.1/dynamique/schema-dynamique.json",
"resources": [
{
"title": "Exemple de fichier IRVE valide",
"path": "https://github.com/etalab/schema-irve/raw/v2.2.1/exemple-valide-dynamique.csv"
"path": "https://raw.githubusercontent.com/etalab/schema-irve/v2.2.1/dynamique/exemple-valide-dynamique.csv"
}
],
"sources": [
Expand Down
4 changes: 2 additions & 2 deletions statique/schema-statique.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
"description": "Spécification du fichier d'échange relatif aux données concernant la localisation géographique et les caractéristiques techniques des stations et des points de recharge pour véhicules électriques",
"countryCode": "FR",
"homepage": "https://github.com/etalab/schema-irve",
"path": "https://github.com/etalab/schema-irve/raw/v2.2.1/schema.json",
"path": "https://raw.githubusercontent.com/etalab/schema-irve/v2.2.1/statique/schema-statique.json",
"resources": [
{
"title": "Exemple de fichier IRVE valide",
"path": "https://github.com/etalab/schema-irve/raw/v2.2.1/exemple-valide.csv"
"path": "https://raw.githubusercontent.com/etalab/schema-irve/v2.2.1/statique/exemple-valide-statique.csv"
}
],
"sources": [
Expand Down

0 comments on commit 74c89e7

Please sign in to comment.