From be4c30735665a7293376407132299052621026bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Miko=C5=82ajczak?= Date: Thu, 25 Jul 2024 18:47:36 +0200 Subject: [PATCH] GitHub Actions workflow (#2) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * GitHub Actions workflow Signed-off-by: marcin mikołajczak * update test Signed-off-by: marcin mikołajczak --------- Signed-off-by: marcin mikołajczak --- .github/workflows/pl.yaml | 90 +++++++++++++++++++ .../20200806175913_rename_instance_chat.exs | 2 - test/mix/tasks/pleroma/database_test.exs | 4 +- .../transmogrifier/question_handling_test.exs | 2 +- .../controllers/media_controller_test.exs | 2 + .../mastodon_api/update_credentials_test.exs | 6 ++ test/pleroma/webhook_test.ex | 57 ------------ 7 files changed, 102 insertions(+), 61 deletions(-) create mode 100644 .github/workflows/pl.yaml delete mode 100644 test/pleroma/webhook_test.ex diff --git a/.github/workflows/pl.yaml b/.github/workflows/pl.yaml new file mode 100644 index 0000000000..5f0d082a90 --- /dev/null +++ b/.github/workflows/pl.yaml @@ -0,0 +1,90 @@ +# Adapter from https://fly.io/phoenix-files/github-actions-for-elixir-ci/ + +name: pl CI + +on: + push: + branches: [ "fork" ] + pull_request: + branches: [ "fork" ] + +env: + ELIXIR_VER: 1.15.8 + POSTGRES_DB: pleroma_test + MIX_ENV: test + +permissions: + contents: read + +jobs: + test: + services: + db: + image: postgres:12 + ports: ['5432:5432'] + env: + POSTGRES_DB: pleroma_test + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + runs-on: ubuntu-latest + name: Test on OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} + strategy: + matrix: + otp: ['26.2.5'] + elixir: ['1.15.8'] + steps: + - name: Install system dependencies + run: sudo apt install -y imagemagick ffmpeg libimage-exiftool-perl + + - name: Set up Elixir + uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + + - name: Checkout code + uses: actions/checkout@v3 + + - name: Cache deps + id: cache-deps + uses: actions/cache@v3 + env: + cache-name: cache-elixir-deps + with: + path: deps + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + + - name: Cache compiled build + id: cache-build + uses: actions/cache@v3 + env: + cache-name: cache-compiled-build + with: + path: _build + key: ${{ runner.os }}-mix-${{ env.cache-name }}-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix-${{ env.cache-name }}- + ${{ runner.os }}-mix- + + - name: Install dependencies + run: mix deps.get + + - name: Compiles without warnings + run: mix compile --warnings-as-errors + + - name: Check Formatting + run: mix format --check-formatted + + - name: Run tests + run: | + mix ecto.create + mix ecto.migrate + mix pleroma.test_runner --cover --preload-modules \ No newline at end of file diff --git a/priv/repo/migrations/20200806175913_rename_instance_chat.exs b/priv/repo/migrations/20200806175913_rename_instance_chat.exs index 44d3530996..a89c15057e 100644 --- a/priv/repo/migrations/20200806175913_rename_instance_chat.exs +++ b/priv/repo/migrations/20200806175913_rename_instance_chat.exs @@ -5,8 +5,6 @@ defmodule Pleroma.Repo.Migrations.RenameInstanceChat do use Ecto.Migration - alias Pleroma.ConfigDB - def up, do: :noop def down, do: :noop end diff --git a/test/mix/tasks/pleroma/database_test.exs b/test/mix/tasks/pleroma/database_test.exs index a51a3bf3dc..fb729a1879 100644 --- a/test/mix/tasks/pleroma/database_test.exs +++ b/test/mix/tasks/pleroma/database_test.exs @@ -387,6 +387,7 @@ test "We don't have unexpected tables which may contain objects that are referen ["data_migration_failed_ids"], ["data_migrations"], ["deliveries"], + ["domains"], ["filters"], ["following_relationships"], ["hashtags"], @@ -416,7 +417,8 @@ test "We don't have unexpected tables which may contain objects that are referen ["user_invite_tokens"], ["user_notes"], ["user_relationships"], - ["users"] + ["users"], + ["webhooks"] ] end diff --git a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs index 100210826a..ca921d77c3 100644 --- a/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs +++ b/test/pleroma/web/activity_pub/transmogrifier/question_handling_test.exs @@ -182,7 +182,7 @@ test "it strips voters list and displays voters count instead" do }) object = Object.normalize(activity, fetch: false) - {:ok, _, _} = CommonAPI.vote(other_user, object, [1]) + {:ok, _, _} = CommonAPI.vote(object, other_user, [1]) {:ok, modified} = Transmogrifier.prepare_outgoing(activity.data) diff --git a/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs index 4adbaa6409..6fc358f5fa 100644 --- a/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/media_controller_test.exs @@ -81,6 +81,8 @@ test "/api/v2/media, upload_limit", %{conn: conn, user: user} do upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8 + File.mkdir_p!(Path.absname("test/tmp")) + assert :ok == File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>) diff --git a/test/pleroma/web/mastodon_api/update_credentials_test.exs b/test/pleroma/web/mastodon_api/update_credentials_test.exs index b1cb2e98fb..b07e1a7de4 100644 --- a/test/pleroma/web/mastodon_api/update_credentials_test.exs +++ b/test/pleroma/web/mastodon_api/update_credentials_test.exs @@ -307,6 +307,8 @@ test "updates the user's avatar", %{user: user, conn: conn} do test "updates the user's avatar, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8 + File.mkdir_p!(Path.absname("test/tmp")) + assert :ok == File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>) @@ -354,6 +356,8 @@ test "updates the user's banner", %{user: user, conn: conn} do test "updates the user's banner, upload_limit, returns a HTTP 413", %{conn: conn, user: user} do upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8 + File.mkdir_p!(Path.absname("test/tmp")) + assert :ok == File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>) @@ -406,6 +410,8 @@ test "updates the user's background, upload_limit, returns a HTTP 413", %{ } do upload_limit = Config.get([:instance, :upload_limit]) * 8 + 8 + File.mkdir_p!(Path.absname("test/tmp")) + assert :ok == File.write(Path.absname("test/tmp/large_binary.data"), <<0::size(upload_limit)>>) diff --git a/test/pleroma/webhook_test.ex b/test/pleroma/webhook_test.ex deleted file mode 100644 index 21763f1e00..0000000000 --- a/test/pleroma/webhook_test.ex +++ /dev/null @@ -1,57 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2022 Pleroma Authors -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.WebhookTest do - use Pleroma.DataCase, async: true - - alias Pleroma.Repo - alias Pleroma.Webhook - - test "creating a webhook" do - %{id: id} = Webhook.create(%{url: "https://example.com/webhook", events: [:"report.created"]}) - - assert %{url: "https://example.com/webhook"} = Webhook.get(id) - end - - test "editing a webhook" do - %{id: id} = - webhook = Webhook.create(%{url: "https://example.com/webhook", events: [:"report.created"]}) - - Webhook.update(webhook, %{events: [:"account.created"]}) - - assert %{events: [:"account.created"]} = Webhook.get(id) - end - - test "filter webhooks by type" do - %{id: id1} = - Webhook.create(%{url: "https://example.com/webhook1", events: [:"report.created"]}) - - %{id: id2} = - Webhook.create(%{ - url: "https://example.com/webhook2", - events: [:"account.created", :"report.created"] - }) - - Webhook.create(%{url: "https://example.com/webhook3", events: [:"account.created"]}) - - assert [%{id: ^id1}, %{id: ^id2}] = Webhook.get_by_type(:"report.created") - end - - test "change webhook state" do - %{id: id, enabled: true} = - webhook = Webhook.create(%{url: "https://example.com/webhook", events: [:"report.created"]}) - - Webhook.set_enabled(webhook, false) - assert %{enabled: false} = Webhook.get(id) - end - - test "rotate webhook secrets" do - %{id: id, secret: secret} = - webhook = Webhook.create(%{url: "https://example.com/webhook", events: [:"report.created"]}) - - Webhook.rotate_secret(webhook) - %{secret: new_secret} = Webhook.get(id) - assert secret != new_secret - end -end