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

hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
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
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
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

Other popular topics 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
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
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
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New

We're in Beta

About us Mission Statement