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/workflow/lint_and_test.yml b/.github/workflow/lint_and_test.yml new file mode 100644 index 0000000..48b10d1 --- /dev/null +++ b/.github/workflow/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 yarn install && cd assets && yarn install + docker compose exec -T mix deps.get + + - name: Create and Migrate database + run: | + docker compose exec -T mix ecto.create + docker compose exec -T mix ecto.migrate + + - name: Check JS formatting + run: docker compose exec -T yarn run prettier . --check + + - name: Check Elixir formatting + run: docker compose exec -T mix format --check-formatted + + - name: Check Credo + run: docker compose exec -T mix credo + + - name: Run Elixir tests + run: docker compose exec -T mix test 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/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==