From 44bec0a1279fdc960da16f7dac8db922d0a8d2d6 Mon Sep 17 00:00:00 2001 From: Kieran Date: Fri, 19 Jan 2024 23:43:25 -0800 Subject: [PATCH] Add CI (#4) * Added credo * Added and ran Prettier; First pass at GH Actions * Updated actions workflow to hopefully work on this branch * Name the folder correctly how about * Added proper container prefix to commands * Apparently you have to get back into the root after commands * CI is working, update branches to final value --- .eslintrc.js | 16 ------- .github/workflows/lint_and_test.yml | 71 +++++++++++++++++++++++++++++ .github/workflows/list_and_test.yml | 0 .gitignore | 1 + .prettierignore | 3 +- Dockerfile | 6 ++- README.md | 14 +++--- assets/css/app.css | 6 +-- assets/package.json | 3 ++ assets/yarn.lock | 4 -- docker-compose.ci.yml | 16 +++++++ docker-compose.yml | 1 - mix.exs | 3 +- mix.lock | 2 + package.json | 6 +++ yarn.lock | 8 ++++ 16 files changed, 125 insertions(+), 35 deletions(-) delete mode 100644 .eslintrc.js create mode 100644 .github/workflows/lint_and_test.yml create mode 100644 .github/workflows/list_and_test.yml create mode 100644 assets/package.json delete mode 100644 assets/yarn.lock create mode 100644 docker-compose.ci.yml create mode 100644 package.json create mode 100644 yarn.lock diff --git a/.eslintrc.js b/.eslintrc.js deleted file mode 100644 index 2eae707..0000000 --- a/.eslintrc.js +++ /dev/null @@ -1,16 +0,0 @@ -module.exports = { - env: { - browser: true, - commonjs: true, - es6: true, - node: true - }, - parserOptions: { - sourceType: 'module', - ecmaVersion: 2022 - }, - extends: ['prettier'], - rules: { - 'prettier/prettier': 'error' - } -} diff --git a/.github/workflows/lint_and_test.yml b/.github/workflows/lint_and_test.yml new file mode 100644 index 0000000..09f9595 --- /dev/null +++ b/.github/workflows/lint_and_test.yml @@ -0,0 +1,71 @@ +name: Perform linting and run tests + +on: + push: + branches: + - master + pull_request: + branches: + - master + workflow_dispatch: + +jobs: + build-and-test: + name: Build, Lint, and Test + runs-on: ubuntu-latest + if: "! contains(toJSON(github.event.commits.*.message), '[skip ci]')" + env: + COMPOSE_FILE: ./docker-compose.ci.yml + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Create and populate ENV file + run: | + echo MIX_ENV=test >> .env + echo POSTGRES_HOST=postgres >> .env + echo POSTGRES_USER=postgres >> .env + echo POSTGRES_PASSWORD=postgres >> .env + + - name: Pull prebuilt images + run: docker compose pull + + - name: Setup Docker layer caching + uses: jpribyl/action-docker-layer-caching@v0.1.1 + continue-on-error: true + with: + key: ci-docker-cache-{hash} + restore-keys: | + ci-docker-cache- + layer-ci-docker-cache- + + - name: Build and Run Docker image + run: docker compose up --detach + + # NOTE: All exec commands use the -T flag to compensate for + # a bug in the GitHub Actions runner where its stdin/stderr + # will erroneously report that it's a TTY. + # Aside from handling this bug the -T flag is not required + # See https://github.com/actions/runner/issues/241 and https://github.com/docker/compose/issues/8537 + - name: Install Elixir and JS deps + run: | + docker compose exec -T phx yarn install && cd assets && yarn install && cd .. + docker compose exec -T phx mix deps.get + + - name: Create and Migrate database + run: | + docker compose exec -T phx mix ecto.create + docker compose exec -T phx mix ecto.migrate + + - name: Check JS formatting + run: docker compose exec -T phx yarn run prettier . --check + + - name: Check Elixir formatting + run: docker compose exec -T phx mix format --check-formatted + + - name: Check Credo + run: docker compose exec -T phx mix credo + + - name: Run Elixir tests + run: docker compose exec -T phx mix test diff --git a/.github/workflows/list_and_test.yml b/.github/workflows/list_and_test.yml new file mode 100644 index 0000000..e69de29 diff --git a/.gitignore b/.gitignore index 21e883a..81199f4 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ pinchflat-*.tar # In case you use Node.js/npm, you want to ignore these. npm-debug.log +/node_modules/ /assets/node_modules/ /.elixir_ls diff --git a/.prettierignore b/.prettierignore index ed4e1fc..b6c9159 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,2 +1,3 @@ assets/vendor/ -assets/node_modules/ +deps/ +_build/ diff --git a/Dockerfile b/Dockerfile index fd31fa7..9c93dc8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -12,7 +12,7 @@ RUN bash nodesource_setup.sh RUN apt-get install nodejs RUN npm install -g yarn -# Install Phoenix packages +# Install baseline Elixir packages RUN mix local.hex --force RUN mix local.rebar --force @@ -27,5 +27,7 @@ COPY . ./ # Needs permissions to be updated AFTER the copy step RUN chmod +x ./docker-run.sh -# # Compile the project. +# Install Elixir deps +RUN mix deps.get + EXPOSE 4008 diff --git a/README.md b/README.md index d29b56f..122fa67 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ To start your Phoenix server: - * Run `mix setup` to install and setup dependencies - * Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server` +- Run `mix setup` to install and setup dependencies +- Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server` Now you can visit [`localhost:4000`](http://localhost:4000) from your browser. @@ -11,8 +11,8 @@ Ready to run in production? Please [check our deployment guides](https://hexdocs ## Learn more - * Official website: https://www.phoenixframework.org/ - * Guides: https://hexdocs.pm/phoenix/overview.html - * Docs: https://hexdocs.pm/phoenix - * Forum: https://elixirforum.com/c/phoenix-forum - * Source: https://github.com/phoenixframework/phoenix +- Official website: https://www.phoenixframework.org/ +- Guides: https://hexdocs.pm/phoenix/overview.html +- Docs: https://hexdocs.pm/phoenix +- Forum: https://elixirforum.com/c/phoenix-forum +- Source: https://github.com/phoenixframework/phoenix diff --git a/assets/css/app.css b/assets/css/app.css index 378c8f9..5dccbd4 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -1,5 +1,5 @@ -@import "tailwindcss/base"; -@import "tailwindcss/components"; -@import "tailwindcss/utilities"; +@import 'tailwindcss/base'; +@import 'tailwindcss/components'; +@import 'tailwindcss/utilities'; /* This file is for your main application CSS */ diff --git a/assets/package.json b/assets/package.json new file mode 100644 index 0000000..9cd9d2b --- /dev/null +++ b/assets/package.json @@ -0,0 +1,3 @@ +{ + "description": "Use this one for actual JS deps used in-app" +} diff --git a/assets/yarn.lock b/assets/yarn.lock deleted file mode 100644 index fb57ccd..0000000 --- a/assets/yarn.lock +++ /dev/null @@ -1,4 +0,0 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - diff --git a/docker-compose.ci.yml b/docker-compose.ci.yml new file mode 100644 index 0000000..432e233 --- /dev/null +++ b/docker-compose.ci.yml @@ -0,0 +1,16 @@ +version: '3' +services: + postgres: + image: 'postgres:16-alpine' + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + + phx: + build: . + volumes: + - '.:/app' + ports: + - '4008:4008' + command: tail -F /dev/null + env_file: .env diff --git a/docker-compose.yml b/docker-compose.yml index 4bb5933..34d2e2a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,6 @@ services: - '4008:4008' depends_on: - postgres - # command: 'sh -c "trap : TERM INT; tail -f /dev/null & wait"' command: - ./docker-run.sh stdin_open: true diff --git a/mix.exs b/mix.exs index 726bc74..83b991b 100644 --- a/mix.exs +++ b/mix.exs @@ -51,7 +51,8 @@ defmodule Pinchflat.MixProject do {:jason, "~> 1.2"}, {:dns_cluster, "~> 0.1.1"}, {:plug_cowboy, "~> 2.5"}, - {:mox, "~> 1.0", only: :test} + {:mox, "~> 1.0", only: :test}, + {:credo, "~> 1.7", only: [:dev, :test], runtime: false} ] end diff --git a/mix.lock b/mix.lock index 3c8ee07..9a2d029 100644 --- a/mix.lock +++ b/mix.lock @@ -1,8 +1,10 @@ %{ + "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, "castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"}, "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, + "credo": {:hex, :credo, "1.7.3", "05bb11eaf2f2b8db370ecaa6a6bda2ec49b2acd5e0418bc106b73b07128c0436", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "35ea675a094c934c22fb1dca3696f3c31f2728ae6ef5a53b5d648c11180a4535"}, "db_connection": {:hex, :db_connection, "2.6.0", "77d835c472b5b67fc4f29556dee74bf511bbafecdcaf98c27d27fa5918152086", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c2f992d15725e721ec7fbc1189d4ecdb8afef76648c746a8e1cad35e3b8a35f3"}, "decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"}, "dns_cluster": {:hex, :dns_cluster, "0.1.2", "3eb5be824c7888dadf9781018e1a5f1d3d1113b333c50bce90fb1b83df1015f2", [:mix], [], "hexpm", "7494272040f847637bbdb01bcdf4b871e82daf09b813e7d3cb3b84f112c6f2f8"}, diff --git a/package.json b/package.json new file mode 100644 index 0000000..6f12368 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "description": "Prettier is used for linting of all files so this package has to live in the root of the project. Use the other package.json files for dependencies.", + "devDependencies": { + "prettier": "3.2.4" + } +} diff --git a/yarn.lock b/yarn.lock new file mode 100644 index 0000000..51d7937 --- /dev/null +++ b/yarn.lock @@ -0,0 +1,8 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +prettier@3.2.4: + version "3.2.4" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-3.2.4.tgz#4723cadeac2ce7c9227de758e5ff9b14e075f283" + integrity sha512-FWu1oLHKCrtpO1ypU6J0SbK2d9Ckwysq6bHj/uaCP26DxrPpppCLQRGVuqAxSTvhF00AcvDRyYrLNW7ocBhFFQ==