From 4d9ed97690df2ea37974b058876a754b4a015871 Mon Sep 17 00:00:00 2001 From: Ayiko Fred Date: Sat, 13 Jan 2024 18:58:34 +0300 Subject: [PATCH] Add CI --- .github/workflows/ci.yaml | 98 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 .github/workflows/ci.yaml diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..90c018d --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,98 @@ +name: Elixir CI + +on: + push: + branches: ["main"] + pull_request: + branches: ["main"] + +permissions: + contents: read + +jobs: + test: + # Set up a Postgres DB service. By default, Phoenix applications + # use Postgres. + services: + db: + image: postgres:15 + ports: ["5432:5432"] + env: + 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: ["25.3.2"] + elixir: ["1.15.7"] + steps: + - name: Set up Elixir + uses: erlef/setup-beam@61e01a43a562a89bfc54c7f9a378ff67b03e4a21 # v1.16.0 + with: + otp-version: ${{matrix.otp}} + elixir-version: ${{matrix.elixir}} + + # Step: Check out the code. + - name: Checkout code + uses: actions/checkout@v3 + + # Step: Define how to cache deps. Restores existing cache if present. + - 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 }}- + + # Step: Define how to cache the `_build` directory. After the first run, + # this speeds up tests runs a lot. This includes not re-compiling our + # project's downloaded deps every run. + - 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- + + # Step: Conditionally bust the cache when job is re-run. + # Sometimes, we may have issues with incremental builds that are fixed by + # doing a full recompile. In order to not waste dev time on such trivial + # issues (while also reaping the time savings of incremental builds for + # *most* day-to-day development), force a full recompile only on builds + # that are retried. + - name: Keep it clean to avoid incremental build problems (flakiness) + if: github.run_attempt != '1' + run: | + mix deps.clean --all + mix clean + shell: sh + + - 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: Credo Check + run: mix credo + + - name: Run tests + run: mix test --cover --warnings-as-errors \ No newline at end of file