Newxan

Newxan

Credo diff on Gitlab CI

Hi! :slight_smile:
So I saw that Credo now has support for checking only towards the git diff. credo/CHANGELOG.md at master · rrrene/credo · GitHub. This is very exciting since I have a large codebase and can now in theory add this to our pipeline for new merge requests.

I can get it working perfectly locally with as the documentation suggests mix credo diff --from-git-merge-base master but when I try to to add this to my gitlab ci pipeline

credo:
  stage: test
  needs: []
  except:
    - master
    - next
  script:
    - mix deps.get
    - mix credo diff --from-git-merge-base master --strict

I get the error:

$ mix credo diff --from-git-merge-base master --strict
** (diff) given value is not a Git ref: master

I’ve tried many different combinations, even experimented with changing so that Gitlab clones project instead of fetching in case it was a problem of not having the branches locally.

  variables:
    GIT_STRATEGY: clone

But so far no luck.
Any suggestions of what might be wrong?

Marked As Solved

Newxan

Newxan

After a bit more digging I found the problem.
It turns out that you do need to fetch the branch..

I also got sidetracked because it appears that there is some predefined variables in Gitlab that are only available under certain conditions.
For example CI_MERGE_REQUEST_TARGET_BRANCH_NAME and CI_MERGE_REQUEST_TARGET_BRANCH_SHA are not available simply because you have a merge request, you must also set the only: merge_requests option.

TLDR
But in the end I found a setup that I’m satisfied with:

credo:
  stage: test
  needs: []
  except:
    - master
    - next
  script:
    - mix deps.get
    - git fetch origin ${CI_DEFAULT_BRANCH}
    - TARGET_SHA1=$(git show-ref -s ${CI_DEFAULT_BRANCH})
    - echo "$TARGET_SHA1"
    - mix credo diff --from-git-merge-base $TARGET_SHA1 --strict

Since we are quick at merging and in practice really only target our default branch (next) anyways.

Where Next?

Popular in Questions Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
PeterCarter
There are pre-rolled solutions for other frameworks that do work. However, Phoenix does not seem to have these. Have people had good expe...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement