From 3607dfefcae4a941c05f9e350354226d1c5fa920 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 16:53:55 -0600 Subject: [PATCH 1/6] Add mix alias to easily add copyright headers to files --- mix.exs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 14448f12f..166cbdca5 100644 --- a/mix.exs +++ b/mix.exs @@ -229,7 +229,8 @@ defmodule Pleroma.Mixfile do "ecto.reset": ["ecto.drop", "ecto.setup"], test: ["ecto.create --quiet", "ecto.migrate", "test"], docs: ["pleroma.docs", "docs"], - analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"] + analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"], + copyright: &add_copyright/1 ] end @@ -332,4 +333,20 @@ defmodule Pleroma.Mixfile do |> Enum.filter(fn string -> string && string != "" end) |> Enum.join() end + + defp add_copyright(_) do + line1 = "# Pleroma: A lightweight social networking server\\n" + + line2 = + "# Copyright © 2017-#{NaiveDateTime.utc_now().year} Pleroma Authors \\n" + + line3 = "# SPDX-License-Identifier: AGPL-3.0-only\\n\\n" + template = line1 <> line2 <> line3 + + find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " + grep = "grep -L '# Copyright' {} \\; |" + xargs = "xargs -n1 sed -i '' '1s;^;#{template};'" + + :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) + end end From 41a637c3a66cc68efddb84d3e888c6c21787c1c9 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 17:25:43 -0600 Subject: [PATCH 2/6] Split out year --- mix.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 166cbdca5..1bfca0b47 100644 --- a/mix.exs +++ b/mix.exs @@ -335,10 +335,10 @@ defmodule Pleroma.Mixfile do end defp add_copyright(_) do + year = NaiveDateTime.utc_now().year line1 = "# Pleroma: A lightweight social networking server\\n" - line2 = - "# Copyright © 2017-#{NaiveDateTime.utc_now().year} Pleroma Authors \\n" + line2 = "# Copyright © 2017-#{year} Pleroma Authors \\n" line3 = "# SPDX-License-Identifier: AGPL-3.0-only\\n\\n" template = line1 <> line2 <> line3 From 23c6cea889658b5a03b113854f0489ee2da147c7 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 15 Jan 2021 17:26:02 -0600 Subject: [PATCH 3/6] Add a mix alias to bump copyright --- mix.exs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/mix.exs b/mix.exs index 1bfca0b47..281cca643 100644 --- a/mix.exs +++ b/mix.exs @@ -230,7 +230,8 @@ defmodule Pleroma.Mixfile do test: ["ecto.create --quiet", "ecto.migrate", "test"], docs: ["pleroma.docs", "docs"], analyze: ["credo --strict --only=warnings,todo,fixme,consistency,readability"], - copyright: &add_copyright/1 + copyright: &add_copyright/1, + "copyright.bump": &bump_copyright/1 ] end @@ -349,4 +350,13 @@ defmodule Pleroma.Mixfile do :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) end + + defp bump_copyright(_) do + year = NaiveDateTime.utc_now().year + find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) |" + + xargs = "xargs sed -i '' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" + + :os.cmd(String.to_charlist("#{find}#{xargs}")) + end end From 99c2e8ed5c797078188911d05b693388a88ade3d Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 16 Jan 2021 02:12:41 +0100 Subject: [PATCH 4/6] mix.exs: GNU sed doesn't into proper getopt() --- mix.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 281cca643..5404a5c11 100644 --- a/mix.exs +++ b/mix.exs @@ -346,7 +346,7 @@ defmodule Pleroma.Mixfile do find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " grep = "grep -L '# Copyright' {} \\; |" - xargs = "xargs -n1 sed -i '' '1s;^;#{template};'" + xargs = "xargs -n1 sed -i'' '1s;^;#{template};'" :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) end @@ -355,7 +355,7 @@ defmodule Pleroma.Mixfile do year = NaiveDateTime.utc_now().year find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) |" - xargs = "xargs sed -i '' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" + xargs = "xargs sed -i'' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" :os.cmd(String.to_charlist("#{find}#{xargs}")) end From a17a9dcc4d5f3d8f27769d334462c54d6b457230 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 16 Jan 2021 02:17:24 +0100 Subject: [PATCH 5/6] mix.exs: Put template into one variable with ~s[] --- mix.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mix.exs b/mix.exs index 5404a5c11..79d9783c4 100644 --- a/mix.exs +++ b/mix.exs @@ -337,12 +337,12 @@ defmodule Pleroma.Mixfile do defp add_copyright(_) do year = NaiveDateTime.utc_now().year - line1 = "# Pleroma: A lightweight social networking server\\n" + template = ~s[\ +# Pleroma: A lightweight social networking server +# Copyright © 2017-#{year} Pleroma Authors +# SPDX-License-Identifier: AGPL-3.0-only - line2 = "# Copyright © 2017-#{year} Pleroma Authors \\n" - - line3 = "# SPDX-License-Identifier: AGPL-3.0-only\\n\\n" - template = line1 <> line2 <> line3 +] |> String.replace("\n", "\\n") find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " grep = "grep -L '# Copyright' {} \\; |" From 3e0d1588a45d1e0d6b23ad2d39050098bc445269 Mon Sep 17 00:00:00 2001 From: "Haelwenn (lanodan) Monnier" Date: Sat, 16 Jan 2021 02:38:37 +0100 Subject: [PATCH 6/6] mix.exs: Make copyright regexes more precise - Add copyright checks for Pleroma's not any copyright - Copyright bump fixes the whole line instead of just the year --- mix.exs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mix.exs b/mix.exs index 79d9783c4..26b52b0cb 100644 --- a/mix.exs +++ b/mix.exs @@ -345,18 +345,19 @@ defmodule Pleroma.Mixfile do ] |> String.replace("\n", "\\n") find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) -exec " - grep = "grep -L '# Copyright' {} \\; |" + grep = "grep -L '# Copyright © [0-9\-]* Pleroma' {} \\;" xargs = "xargs -n1 sed -i'' '1s;^;#{template};'" - :os.cmd(String.to_charlist("#{find}#{grep}#{xargs}")) + :os.cmd(String.to_charlist("#{find}#{grep} | #{xargs}")) end defp bump_copyright(_) do year = NaiveDateTime.utc_now().year - find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\) |" + find = "find lib test priv -type f \\( -name '*.ex' -or -name '*.exs' \\)" - xargs = "xargs sed -i'' 's/# Copyright © 2017-20[0-9][0-9]/# Copyright © 2017-#{year}/'" + xargs = + "xargs sed -i'' 's;# Copyright © [0-9\-]* Pleroma.*$;# Copyright © 2017-#{year} Pleroma Authors ;'" - :os.cmd(String.to_charlist("#{find}#{xargs}")) + :os.cmd(String.to_charlist("#{find} | #{xargs}")) end end