diff --git a/.github/actions/continuous-integration/load-cache/action.yml b/.github/actions/continuous-integration/load-cache/action.yml new file mode 100644 index 00000000..d72ba42c --- /dev/null +++ b/.github/actions/continuous-integration/load-cache/action.yml @@ -0,0 +1,20 @@ +name: Build and cache image +runs: + using: "composite" + steps: + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - + name: Build and cache image + uses: docker/build-push-action@v6 + with: + context: . + file: ./Dockerfile + build-args: | + RAILS_ENV=test + push: false + load: true + tags: app_test:latest + cache-from: type=gha + cache-to: type=gha,mode=min diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 3e5a0a40..1cac2da2 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -1,5 +1,7 @@ # TODO: Enable GitHub Actions on the repository to test all pull requests # https://github.com///actions +name: CI Checks + on: pull_request: push: @@ -8,18 +10,77 @@ on: - develop jobs: - test: + lint-and-format: + name: Lint and format application runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Build and cache + uses: ./.github/actions/continuous-integration/load-cache + - + name: Run Ruby standard + run: | + docker run --rm app_test:latest /bin/bash -c "bundle exec standardrb -f simple" + - + name: Run ESLint + run: | + docker run --rm app_test:latest /bin/bash -c "yarn run lint:js" + - + name: Run Stylelint + run: | + docker run --rm app_test:latest /bin/bash -c "yarn run lint:css" + - + name: Run Prettier + run: | + docker run --rm app_test:latest /bin/bash -c "yarn run lint:format" - env: - RAILS_ENV: test - + static-analysis: + name: Static analysis + runs-on: ubuntu-latest steps: - - name: Check out code + - + name: Checkout uses: actions/checkout@v4 + - + name: Build and cache + uses: ./.github/actions/continuous-integration/load-cache + - + name: Run Brakeman + run: | + docker run --rm app_test:latest /bin/bash -c "bundle exec brakeman -o /dev/stdout" - - name: Build - run: script/ci/cibuild + specs: + name: Specs and coverage + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Build and cache + uses: ./.github/actions/continuous-integration/load-cache + - + name: Run RSpec and Simplecov + run: | + docker compose -p complete-app -f docker-compose.ci.yml \ + run --name app_test test /bin/bash -c "bin/rails spec" + - + name: Shutdown containers + run: docker compose -p app_test down && docker compose -p app_test rm - - name: Test - run: script/ci/test + shellcheck: + name: Lint scripts + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Run Shellceck + run: | + for file in $(git ls-files script/*) + do shellcheck -x "$file" + done diff --git a/Dockerfile b/Dockerfile index e1fbd7e2..633969a2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,7 @@ # ------------------------------------------------------------------------------ # Base # ------------------------------------------------------------------------------ -FROM ruby:3.3.6 as base +FROM ruby:3.3.6 AS base LABEL org.opencontainers.image.authors="contact@dxw.com" COPY .node-version .node-version @@ -17,12 +17,12 @@ RUN \ build-essential \ libpq-dev -ENV APP_HOME /srv/app -ENV DEPS_HOME /deps +ENV APP_HOME=/srv/app +ENV DEPS_HOME=/deps ARG RAILS_ENV -ENV RAILS_ENV ${RAILS_ENV:-production} -ENV NODE_ENV ${RAILS_ENV:-production} +ENV RAILS_ENV=${RAILS_ENV:-production} +ENV NODE_ENV=${RAILS_ENV:-production} # ------------------------------------------------------------------------------ # Dependencies @@ -34,7 +34,7 @@ RUN apt-get update && apt-get install -y yarn WORKDIR ${DEPS_HOME} # Install Ruby dependencies -ENV BUNDLE_GEM_GROUPS ${RAILS_ENV} +ENV BUNDLE_GEM_GROUPS=${RAILS_ENV} COPY Gemfile ${DEPS_HOME}/Gemfile COPY Gemfile.lock ${DEPS_HOME}/Gemfile.lock @@ -109,8 +109,8 @@ RUN \ ARG CURRENT_GIT_SHA ARG TIME_OF_BUILD -ENV CURRENT_GIT_SHA ${CURRENT_GIT_SHA} -ENV TIME_OF_BUILD ${TIME_OF_BUILD} +ENV CURRENT_GIT_SHA=${CURRENT_GIT_SHA} +ENV TIME_OF_BUILD=${TIME_OF_BUILD} COPY ./docker-entrypoint.sh / RUN chmod +x /docker-entrypoint.sh @@ -123,7 +123,7 @@ CMD ["bundle", "exec", "rails", "server"] # ------------------------------------------------------------------------------ # Test # ------------------------------------------------------------------------------ -FROM web as test +FROM web AS test RUN \ apt-get update && \ diff --git a/script/ci/cibuild b/script/ci/cibuild deleted file mode 100755 index 36639123..00000000 --- a/script/ci/cibuild +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -# Setup environment for CI to run tests. This is primarily designed to run on -# the continuous integration server. - -set -e - -docker compose -f docker-compose.ci.yml -p app build diff --git a/script/ci/test b/script/ci/test deleted file mode 100755 index db27458c..00000000 --- a/script/ci/test +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -# Run the test suite for the application. This is primarily designed to run on -# CI with a clean build context. To run locally first remove any generic image -# by running `docker rmi app:latest` - -set -e - -docker compose -f docker-compose.ci.yml \ - -p app \ - run --rm test \ - script/all/test "$@"