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

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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New
makeitrein
Hey all, just started picking up Elixir last week and am writing a scraper as a learning project. Baby step #1 is extracting the number ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
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
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
beno
I will often find my self writing things similar to: case some_value do nil -> something() "" -> something() _ -> someth...
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

dotdotdotPaul
Okay, I'm having a heck of a time trying to figure out how to best handle the validation of belongs_to associations in Ecto. I'm sure I'...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
yawaramin
In the Dialyzer docs ( http://erlang.org/doc/man/dialyzer.html#requesting-or-suppressing-warnings-in-source-files ), there is a way to tu...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New

We're in Beta

About us Mission Statement