firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.03k stars 115 forks source link

4.49.0 breaks ssh git remote ? #1238

Closed stiv-pro closed 1 month ago

stiv-pro commented 1 month ago
$ git remote get-url origin
ssh://git@xxxxxxxxxxxxxxxxxxxxxx.git

----------------------------------------------------------------------------------------------------------------------
$ gitlab-ci-local --version
4.49.0

----------------------------------------------------------------------------------------------------------------------
$ gitlab-ci-local
Error: ssh not supported!
    at Function.remoteFileExist (/snapshot/firecow-gitlab-ci-local/src/utils.ts:285:23)
    at Function.init (/snapshot/firecow-gitlab-ci-local/src/parser-includes.ts:113:39)
    at Parser.init (/snapshot/firecow-gitlab-ci-local/src/parser.ts:95:44)
    at Function.create (/snapshot/firecow-gitlab-ci-local/src/parser.ts:59:9)
    at handler (/snapshot/firecow-gitlab-ci-local/src/handler.ts:77:18)
    at Object.handler (/snapshot/firecow-gitlab-ci-local/src/index.ts:36:21)

----------------------------------------------------------------------------------------------------------------------
$ apt-cache policy gitlab-ci-local
gitlab-ci-local:
  Installé : 4.49.0
  Candidat : 4.49.0
 Table de version :
 *** 4.49.0 500
        500 https://gitlab-ci-local-ppa.firecow.dk ./ Packages
        100 /var/lib/dpkg/status
     4.48.2 500
        500 https://gitlab-ci-local-ppa.firecow.dk ./ Packages
        ...

----------------------------------------------------------------------------------------------------------------------
$ sudo apt install gitlab-ci-local=4.48.2
Dépaquetage de gitlab-ci-local (4.48.2) sur (4.49.0) ...
Paramétrage de gitlab-ci-local (4.48.2) ...

----------------------------------------------------------------------------------------------------------------------
$ gitlab-ci-local 
parsing and downloads finished in 2.15 s

OS ubuntu 24.04 No need to tell more than that I think ? By the way, thank you mainteners and contributors for this project !

PigeonF commented 1 month ago

Using b723ffd (which is tagged as 4.49.0) I cannot reproduce the same issue locally (maybe there is more to the remote URL than the ssh prefix?)

---
job:
  script:
    - echo "Heya"
$ git remote show
origin
$ git remote get-url origin
ssh://git@github.com:firecow/gitlab-ci-local.git
$ gitlab-ci-local
git remote get-url origin didn't provide valid matches
parsing and downloads finished in 71 ms
job starting shell (test)
job $ echo "Heya"
job > Heya
job finished in 19 ms

 PASS  job
pipeline finished in 184 ms

You can create a second remote called gcl-origin which is preferred over origin. So in this case

$ git remote add gcl-origin https://github.com/firecow/gitlab-ci-local.git
$ git remote show
gcl-origin
origin
$ gitlab-ci-local
parsing and downloads finished in 42 ms
job starting shell (test)
job $ echo "Heya"
job > Heya
job finished in 28 ms

 PASS  job
pipeline finished in 164 ms

You can see that the warning about no valid matches has disappeared. So I think this is fixed on master, and you can work around it in your local installation by setting the gcl-origin remote to a https:// address.

stiv-pro commented 1 month ago

First, thank you for the answer. I should have been more precise in my description, I forgot to mention I had to comment the component part of my gitlab-ci file to be able to downgrade in 4.48.2

But in fact , in 4.49, it works well without component...

When I uncomment the line, I get the ssh not supported! error.

include:
  - component: gitlab.mycompany.com/ci-templates/workflow@~latest

I followed guidelines here to write the component location : https://docs.gitlab.com/ee/ci/components/#use-a-component

Sounds more related to the last commit :D

Tried to play with location syntax but all I got is : This GitLab CI configuration is invalid: component: <various URLs> should not contain protocol

PigeonF commented 1 month ago

I probably can't fully reproduce your use case (since I don't know how gitlab.yourcompany.com is set up with regards to authentication), but on 4.49 I was at least able to do the following

# .gitlab-ci.yml
---
include:
  - component: gitlab.com/PigeonF/tests/foo@main

Note that gitlab.com/PigeonF/tests is a private repository which I assume your company repositories are as well.

# gitlab.com/PigeonF/tests repository, templates/foo.yml file
spec:
  inputs:
    stage:
      default: test
---

example:
  stage: $[[ inputs.stage ]]
  script: echo Hello, World
$ git remote get-url origin
ssh://git@github.com:firecow/gitlab-ci-local.git
$ git remote get-url gcl-origin
git@gitlab.com:PigeonF/tests.git

As far as I can tell the gcl-origin can be whatever, so long as it has the gitlab.com (which in your case would have to be gitlab.yourcompany.com and user/project.git format.

$ gitlab-ci-local
parsing and downloads finished in 1.57 s
example starting shell (test)
example $ echo Hello, World
example > Hello, World
example finished in 51 ms

PASS  example
pipeline finished in 1.74 s

I am not sure why you need to prefix your origin with ssh://, for me it works even without. But regardless, you can keep your origin as is and just change gcl-origin. I dont think it needs to point to a valid repository, just make sure to have the domain and make sure to end it in .git so it is recognized properly (I was able to repeat the above with gcl-origin set to git@gitlab.com:foo/bar.git.

If that does not work (i.e. the implicit ssh:// does not work), you can set your credentials in the https URL see stackoverflow). So you would git remote add gcl-origin https://user:pass@gitlab.yourcompany.com/som/repo.git.

Let me know how it goes

ANGkeith commented 1 month ago

@PigeonF thanks for looking into it,

i missed out a case in my switch statement 😅

@stiv-pro thanks for the bug report