From e900d00de88b9937af311ec8438a1b8024861e21 Mon Sep 17 00:00:00 2001 From: Zach Daniel Date: Tue, 31 Jan 2023 11:15:09 -0500 Subject: [PATCH] ci: remove tweets/switch to standardized CI pipeline --- .check.exs | 5 +- .doctor.exs | 18 +++ .github/workflows/elixir.yml | 172 ---------------------------- .github/workflows/project-ci.yml | 154 +++++++++++++++++++++++++ .github/workflows/test-subjects.yml | 83 ++++++++++++++ lib/ash/ci_string.ex | 7 ++ mix.exs | 3 +- mix.lock | 1 + 8 files changed, 267 insertions(+), 176 deletions(-) create mode 100644 .doctor.exs delete mode 100644 .github/workflows/elixir.yml create mode 100644 .github/workflows/project-ci.yml create mode 100644 .github/workflows/test-subjects.yml diff --git a/.check.exs b/.check.exs index 186181ec..8423bbfc 100644 --- a/.check.exs +++ b/.check.exs @@ -11,9 +11,8 @@ ## ...or adjusted (e.g. use one-line formatter for more compact credo output) # {:credo, "mix credo --format oneline"}, - {:check_formatter, command: "mix spark.formatter --check"}, - # TODO: upgrade to the new version of ex_check that should do this on the right elixir version - # {:unused_deps, command: "mix deps.unlock --check-unused"} + {:check_formatter, command: "mix spark.formatter --check"} + # {:doctor, false} ## custom new tools may be added (mix tasks or arbitrary commands) # {:my_mix_task, command: "mix release", env: %{"MIX_ENV" => "prod"}}, diff --git a/.doctor.exs b/.doctor.exs new file mode 100644 index 00000000..615f3d8a --- /dev/null +++ b/.doctor.exs @@ -0,0 +1,18 @@ +%Doctor.Config{ + ignore_modules: [ + ~r/Comparable\..*/, + ~r/Ash\.Query\.Operator\.Basic.*/ + ], + ignore_paths: [], + min_module_doc_coverage: 40, + min_module_spec_coverage: 0, + min_overall_doc_coverage: 48, + min_overall_moduledoc_coverage: 100, + min_overall_spec_coverage: 0, + exception_moduledoc_required: true, + raise: false, + reporter: Doctor.Reporters.Full, + struct_type_spec_required: true, + umbrella: false, + failed: false +} diff --git a/.github/workflows/elixir.yml b/.github/workflows/elixir.yml deleted file mode 100644 index f3692268..00000000 --- a/.github/workflows/elixir.yml +++ /dev/null @@ -1,172 +0,0 @@ -name: Ash CI - -on: - push: - branches: [main] - tags-ignore: ["v*"] - pull_request: - branches: [main] - create: - tags: ["v*"] - branches: main -jobs: - build: - runs-on: ubuntu-latest - name: OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} - strategy: - fail-fast: false - matrix: - include: - - elixir: 1.13.1 - otp: 24 - - elixir: 1.14.1 - otp: 25 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - run: sudo apt-get install --yes erlang-dev - - uses: actions/checkout@v2 - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{matrix.otp}} - elixir-version: ${{matrix.elixir}} - - uses: actions/cache@v1 - id: cache-deps - with: - path: deps - key: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - restore-keys: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2- - - uses: actions/cache@v1 - id: cache-build - with: - path: _build - key: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-2-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - restore-keys: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-2- - - run: mix deps.get - - run: mix check --except dialyzer - if: startsWith(github.ref, 'refs/tags/v') - - run: mix check - if: "!startsWith(github.ref, 'refs/tags/v')" - release: - needs: [build] - if: startsWith(github.ref, 'refs/tags/v') - runs-on: ubuntu-latest - name: Release - strategy: - matrix: - otp: ["24"] - elixir: ["1.14.0"] - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - steps: - - run: sudo apt-get install --yes erlang-dev - - uses: actions/checkout@v2 - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{matrix.otp}} - elixir-version: ${{matrix.elixir}} - - uses: actions/cache@v1 - id: cache-deps - with: - path: deps - key: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} - restore-keys: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2- - - run: mix deps.get - - run: mix compile - - run: mix hex.publish --yes - if: startsWith(github.ref, 'refs/tags/v') - env: - HEX_API_KEY: ${{ secrets.HEX_API_KEY }} - - uses: little-core-labs/get-git-tag@v3.0.1 - id: tagName - - uses: ethomson/send-tweet-action@v1 - if: startsWith(github.ref, 'refs/tags/v') - with: - status: | - Ash version "${{ steps.tagName.outputs.tag }}" released! - - #myelixirstatus - - See the changelog for more info: - https://github.com/ash-project/ash/blob/main/CHANGELOG.md - consumer-key: ${{ secrets.TWITTER_CONSUMER_API_KEY }} - consumer-secret: ${{ secrets.TWITTER_CONSUMER_API_SECRET }} - access-token: ${{ secrets.TWITTER_ACCESS_TOKEN }} - access-token-secret: ${{ secrets.TWITTER_ACCESS_TOKEN_SECRET }} - test-subprojects: - runs-on: ubuntu-latest - name: Subproject-${{matrix.project}} - OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} - strategy: - fail-fast: false - matrix: - project: - [ - "ash_postgres", - "ash_csv", - "ash_graphql", - "ash_json_api", - "ash_phoenix", - "ash_admin", - "ash_archival", - ] - otp: ["24"] - elixir: ["1.14.0"] - services: - pg: - image: postgres:13 - env: - POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: postgres - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - ports: ["5432:5432"] - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - ASH_CI: true - ASH_VERSION: local - steps: - - run: sudo apt-get install --yes erlang-dev - - uses: actions/checkout@v2 - with: - repository: ash-project/ash - path: ash - - uses: actions/checkout@v2 - with: - repository: ash-project/${{matrix.project}} - path: ${{matrix.project}} - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{matrix.otp}} - elixir-version: ${{matrix.elixir}} - - uses: actions/cache@v1 - id: cache-deps - with: - path: ${{matrix.project}}/deps - key: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2-${{ hashFiles(format('{0}{1}', github.workspace, '/ash/mix.lock')) }} - restore-keys: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2- - - uses: actions/cache@v1 - id: cache-build - with: - path: ${{matrix.project}}/_build - key: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-3-${{ hashFiles(format('{0}{1}', github.workspace, '/ash/mix.lock')) }} - restore-keys: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-3- - - name: mix deps.get inside ./${{matrix.project}} - run: mix deps.get - working-directory: ./${{matrix.project}} - - run: mix test.create - if: ${{matrix.project == 'ash_postgres'}} - working-directory: ./${{matrix.project}} - - run: mix test.migrate - if: ${{matrix.project == 'ash_postgres'}} - working-directory: ./${{matrix.project}} - - run: mix test.migrate_tenants - if: ${{matrix.project == 'ash_postgres'}} - working-directory: ./${{matrix.project}} - - name: mix compile --force --warnings-as-errors inside ./${{matrix.project}} - run: mix compile --force --warnings-as-errors - env: - MIX_ENV: test - working-directory: ./${{matrix.project}} - - name: mix test inside ./${{matrix.project}} - run: mix test - working-directory: ./${{matrix.project}} diff --git a/.github/workflows/project-ci.yml b/.github/workflows/project-ci.yml new file mode 100644 index 00000000..5db19a5f --- /dev/null +++ b/.github/workflows/project-ci.yml @@ -0,0 +1,154 @@ +name: Ash CI +on: + push: + tags: + - "v*" + branches: [main] + workflow_call: +jobs: + deps: + name: mix deps.get + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-deps-get@main + + auditor: + name: mix hex.audit + runs-on: ubuntu-latest + needs: deps + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-hex-audit@main + + build-test: + name: MIX_ENV=test mix.compile + runs-on: ubuntu-latest + needs: deps + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/install-elixir@main + - uses: team-alembic/staple-actions/actions/mix-compile@main + with: + mix-env: test + formatter: + name: mix format --check-formatted + runs-on: ubuntu-latest + needs: build-test + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-format@main + with: + mix-env: test + + # Need to clean lots of things up before we can add this + # doctor: + # name: mix doctor --full --raise + # runs-on: ubuntu-latest + # needs: build-test + # steps: + # - uses: actions/checkout@v3 + # - uses: team-alembic/staple-actions/actions/mix-doctor@main + # with: + # mix-env: test + test: + name: mix test + runs-on: ubuntu-latest + needs: build-test + services: + postgres: + image: postgres + env: + POSTGRES_HOST_AUTH_METHOD: trust + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-test@main + with: + mix-env: test + env: + PGUSER: postgres + PGPASS: postgres + PGHOST: postgres + dialyzer: + name: mix dialyzer + runs-on: ubuntu-latest + needs: build-test + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-dialyzer@main + with: + mix-env: test + + build-dev: + name: MIX_ENV=dev mix.compile + runs-on: ubuntu-latest + needs: + - credo + - doctor + - formatter + - auditor + - test + - dialyzer + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-compile@main + with: + mix-env: dev + build-docs: + name: mix docs + runs-on: ubuntu-latest + needs: build-dev + steps: + - uses: actions/checkout@v3 + - uses: team-alembic/staple-actions/actions/mix-docs@main + with: + mix-env: dev + - uses: actions/upload-pages-artifact@v1 + with: + path: doc/ + deploy-docs: + name: Deploy docs to GitHub pages. + runs-on: ubuntu-latest + needs: build-docs + permissions: + pages: write + id-token: write + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub pages + id: deployment + uses: actions/deploy-pages@v1 + release: + needs: [build-dev] + if: startsWith(github.ref, 'refs/tags/v') + runs-on: ubuntu-latest + name: Release + steps: + - run: sudo apt-get install --yes erlang-dev + - uses: actions/checkout@v2 + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + - uses: actions/cache@v1 + id: cache-deps + with: + path: deps + key: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2-${{ hashFiles(format('{0}{1}', github.workspace, '/mix.lock')) }} + restore-keys: otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2- + - run: mix deps.get + - run: mix compile + - run: mix hex.publish --yes + if: startsWith(github.ref, 'refs/tags/v') + env: + HEX_API_KEY: ${{ secrets.HEX_API_KEY }} diff --git a/.github/workflows/test-subjects.yml b/.github/workflows/test-subjects.yml new file mode 100644 index 00000000..7572db25 --- /dev/null +++ b/.github/workflows/test-subjects.yml @@ -0,0 +1,83 @@ +name: Ash CI +on: + push: + workflow_call: +jobs: + test-subprojects: + runs-on: ubuntu-latest + name: Subproject-${{matrix.project}} - OTP ${{matrix.otp}} / Elixir ${{matrix.elixir}} + strategy: + fail-fast: false + matrix: + project: + [ + "ash-project/ash_postgres", + "ash-project/ash_csv", + "ash-project/ash_graphql", + "ash-project/ash_json_api", + "ash-project/ash_phoenix", + "ash-project/ash_admin", + "ash-project/ash_archival", + "team-alembic/ash_authentication", + "team-alembic/ash_authentication_phoenix", + ] + otp: ["24"] + elixir: ["1.14.0"] + services: + pg: + image: postgres:13 + env: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + POSTGRES_DB: postgres + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + ports: ["5432:5432"] + env: + ASH_CI: true + ASH_VERSION: local + steps: + - run: sudo apt-get install --yes erlang-dev + - uses: actions/checkout@v2 + with: + repository: ash-project/ash + path: ash + - uses: actions/checkout@v2 + with: + repository: ${{matrix.project}} + path: ${{matrix.project}} + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + - uses: actions/cache@v1 + id: cache-deps + with: + path: ${{matrix.project}}/deps + key: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2-${{ hashFiles(format('{0}{1}', github.workspace, '/ash/mix.lock')) }} + restore-keys: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-deps-2- + - uses: actions/cache@v1 + id: cache-build + with: + path: ${{matrix.project}}/_build + key: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-3-${{ hashFiles(format('{0}{1}', github.workspace, '/ash/mix.lock')) }} + restore-keys: ${{matrix.project}}-otp-${{matrix.otp}}-elixir-${{matrix.elixir}}-build-3- + - name: mix deps.get inside ./${{matrix.project}} + run: mix deps.get + working-directory: ./${{matrix.project}} + - run: mix test.create + if: ${{matrix.project == 'ash-project/ash_postgres'}} + working-directory: ./${{matrix.project}} + - run: mix test.migrate + if: ${{matrix.project == 'ash-project/ash_postgres'}} + working-directory: ./${{matrix.project}} + - run: mix test.migrate_tenants + if: ${{matrix.project == 'ash-project/ash_postgres'}} + working-directory: ./${{matrix.project}} + - name: mix compile --force --warnings-as-errors inside ./${{matrix.project}} + run: mix compile --force --warnings-as-errors + env: + MIX_ENV: test + working-directory: ./${{matrix.project}} + - name: mix test inside ./${{matrix.project}} + run: mix test + working-directory: ./${{matrix.project}} diff --git a/lib/ash/ci_string.ex b/lib/ash/ci_string.ex index bc6e6776..1bcf89d5 100644 --- a/lib/ash/ci_string.ex +++ b/lib/ash/ci_string.ex @@ -11,6 +11,13 @@ defmodule Ash.CiString do defstruct [:string, casted?: false, case: nil] + @type t :: %__MODULE__{ + string: String.t(), + casted?: boolean(), + case: nil | :lower | :upper + } + + @doc "Creates a case insensitive string" def sigil_i(value, mods) do cond do ?l in mods -> diff --git a/mix.exs b/mix.exs index 12afb355..ba8b0bdd 100644 --- a/mix.exs +++ b/mix.exs @@ -291,7 +291,8 @@ defmodule Ash.MixProject do {:git_ops, "~> 2.5", only: :dev}, {:mix_test_watch, "~> 1.0", only: :dev, runtime: false}, {:parse_trans, "3.3.0", only: [:dev, :test], override: true}, - {:benchee, "~> 1.1", only: [:dev, :test]} + {:benchee, "~> 1.1", only: [:dev, :test]}, + {:doctor, "~> 0.21", only: [:dev, :test]} ] end diff --git a/mix.lock b/mix.lock index 9338d12b..e9499190 100644 --- a/mix.lock +++ b/mix.lock @@ -8,6 +8,7 @@ "deep_merge": {:hex, :deep_merge, "1.0.0", "b4aa1a0d1acac393bdf38b2291af38cb1d4a52806cf7a4906f718e1feb5ee961", [:mix], [], "hexpm", "ce708e5f094b9cd4e8f2be4f00d2f4250c4095be93f8cd6d018c753894885430"}, "dialyxir": {:hex, :dialyxir, "1.2.0", "58344b3e87c2e7095304c81a9ae65cb68b613e28340690dfe1a5597fd08dec37", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "61072136427a851674cab81762be4dbeae7679f85b1272b6d25c3a839aff8463"}, "docsh": {:hex, :docsh, "0.7.2", "f893d5317a0e14269dd7fe79cf95fb6b9ba23513da0480ec6e77c73221cae4f2", [:rebar3], [{:providers, "1.8.1", [hex: :providers, repo: "hexpm", optional: false]}], "hexpm", "4e7db461bb07540d2bc3d366b8513f0197712d0495bb85744f367d3815076134"}, + "doctor": {:hex, :doctor, "0.21.0", "20ef89355c67778e206225fe74913e96141c4d001cb04efdeba1a2a9704f1ab5", [:mix], [{:decimal, "~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}], "hexpm", "a227831daa79784eb24cdeedfa403c46a4cb7d0eab0e31232ec654314447e4e0"}, "earmark": {:hex, :earmark, "1.4.24", "1923e201c3742af421860b983560967cc3e3deacc59c12966bc991a5435565e6", [:mix], [{:earmark_parser, "~> 1.4.25", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "9724242f241f2ad634756d8f2bb57a3d0992cedd10c51842fa655703b4da7c67"}, "earmark_parser": {:hex, :earmark_parser, "1.4.25", "2024618731c55ebfcc5439d756852ec4e85978a39d0d58593763924d9a15916f", [:mix], [], "hexpm", "56749c5e1c59447f7b7a23ddb235e4b3defe276afc220a6227237f3efe83f51e"}, "ecto": {:hex, :ecto, "3.7.2", "44c034f88e1980754983cc4400585970b4206841f6f3780967a65a9150ef09a8", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "a600da5772d1c31abbf06f3e4a1ffb150e74ed3e2aa92ff3cee95901657a874e"},