Git-updater: Release assets do not work for GitLab

Created on 30 Sep 2016  路  26Comments  路  Source: afragen/git-updater

I tried to use this for my GitLab and I thought / hope that the release assets would work with GitLab artifacts. Turned out they don't.

This would be a nice feature as GitLab CI compiles the theme assets and builds it, with the artifact generated being the correct ZIP.

I think this could be achieved through the Tag, Commit and Build APIs (the last one being the download link), but any of them still require the correct name. This could be done by either:

  • Defining a standard job name (eg, build_theme) for the job which artifact would be used;
  • Add a new header GitLab Job (or similar) to configure this name.

I could try to implement this (and submit a pull request) but only 3 or 4 weeks from now,

All 26 comments

Can you share a URI for the repo and the release asset? It would help me try to figure out how to fix.

I'll try to leave here as much info as possible.

The URL that allows me to download the artifact through the UI is https://gitlab.com/saofilipe/saofilipe-wp/builds/artifacts/3.0.0-alpha.2/download?job=build_theme , but I think this doesn't work with a private_token.

The artifact for a build can be accessed through GET /projects/:id/builds/:build_id/artifacts .

The ID for a build can be accessed for a commit through GET /projects/:id/repository/commits/:sha/statuses , and the query param name can be used to filter by job name.

Finally, the commit SHA can be obtained through the Tags API this plugin is already using.

If you want (and give me you GitLab user) I can give you access to the repo. The most recent tag is 3.0.0-alpha.2.

My GitLab user is afragen, but this is very helpful. I only had previously tested with GitHub. GitLab and GitHub have very similar APIs but I guess not in this case.

Now I know why this doesn't work. I've never heard of it before. 馃槤

I added you with the Reporter role (I think it is enough).

Regarding releases, the main difference between GitHub and GitLab is that Lab can itself build the project, through GitLab Ci.

If I can help in any way just ask! I'm familiar with the CI/build process and somewhat with the API (I just have zero time now to do it myself).

For a better Updater!

It shouldn't be that difficult. I'm at WordCamp Phoenix so when I have time I'll get it done and report back here.

Does the URI always point to the tag by default or is this something you set up specifically? In other words. Can the URI be named arbitrarily by you or is it pretty set in the API?

Also, what is in your build artifact that isn't in your repo from a regular download? Nevermind, I just downloaded both to see for myself.

Where does the query arg ?job=build_theme come from? I take it this could be just about anything?

The built css and js files! The repo has only the Less and js files, the builder prepares everything and builds a zip with only the needed files for the theme (no Less, no .files, etc).

If I understood the question correctly, that URL provided by the UI (when I right click and copy link) uses the tag I created and the build job I defined in the .gitlab-ci.yml file.

In .gitlab-ci.yml, did you create the build_theme name or is it standard?

I ask as I may have to create a new header for GitLab Build Job or something.

I created it, it is anything I want. That's why I proposed just that in the issue - or a header or the plugin defines a standard for users to call the job.

Yes, now that I re-read I see.

Simpler to define, but more versatile to have header. I think a new header might be better, but it'll take a bit more work. Definitely doable. 馃槈

I've added the appropriate code but I'm running into a problem. I seems that even when passing the private token there's an auth issue.

You can try the branch gitlab-ci-release-asset

As I said before, I think that "direct" URL can't be used like an API and is meant to be used through the UI - that is, with a website session. I think the way to get the download link is though the APIs as I said in my second comment. The /projects/:id/builds/:build_id/artifacts URL will be the direct link to the ZIP.

And thank you for all the effort!

Unfortunately, trying to access this download link from the CLI doesn't work unless I'm logged in. At least I have to be logged in from the browser for it to work in the browser. Passing the private_token doesn't seem to work either.

Fawkes:~ afragen$ curl "https://gitlab.com/saofilipe/saofilipe-wp/builds/artifacts/3.0.0-alpha.3/download?job=build_theme"
<html><body>You are being <a href="https://gitlab.com/users/sign_in">redirected</a>.</body></html>Fawkes:~ afragen$ 
Fawkes:~ afragen$ curl "https://gitlab.com/saofilipe/saofilipe-wp/builds/artifacts/3.0.0-alpha.3/download?job=build_theme?private_token=xxxxxxxxxxxxxxxxxxxxx"
<html><body>You are being <a href="https://gitlab.com/users/sign_in">redirected</a>.</body></html>Fawkes:~ afragen$ 

Because of this limitation it doesn't appear that setting a CI Job and redirect the download to this URL is going to work. I really don't know a method around this. I'm open to ideas.

I have tried other permutations from https://docs.gitlab.com/ce/api/builds.html#download-the-artifacts-file but it still gives an authorization error.

The URL https://gitlab.com/api/v3/projects/1752210/builds/artifacts/3.0.0-alpha.3/download?job=build_theme&private_token=xxxxxxxxxx seems to work for me.

The URL you used has an authentication problem because the query string is built in the wrong way - the private_token should be added with "&" - https://gitlab.com/saofilipe/saofilipe-wp/builds/artifacts/3.0.0-alpha.3/download?job=build_theme&private_token=xxxxxxxxxx .

Still, when I call this last one through curl, it tells me its being redirected to an URL with the build ID:

iMac-de-Joao:~ joaoluis$ curl "https://gitlab.com/saofilipe/saofilipe-wp/builds/artifacts/3.0.0-alpha.3/download?job=build_theme&private_token=DqtGYWdEz7deJV6WxP9w"
<html><body>You are being <a href="https://gitlab.com/saofilipe/saofilipe-wp/builds/4627455/artifacts/download">redirected</a>.</body></html>

I fixed the download link and I get no errors but the theme gets overwritten with nothing. It clears out the contents of the theme's folder. I have to dig further but I'm getting somewhere.

That may be because of the redirection... I suggest either using the first URL I posted, with the project ID (which the GitLab API class already knows) or, using the second, read the headers and use the Location header URL.

I just updated again so the download link works. I can follow the code and the download happens but the renaming code hits a snag when the core filesystem move fails. I don't know why -- yet.

I think I've gotten it to work. I was having some issues as the release asset downloaded to a slightly different directory structure and I had to add a call clean up after myself.

The only issue would be if someone tries to use the branch switcher with a release asset. They would get an installation that possibly wouldn't work.

Update to latest commit. You'll need to add the header GitLab CI Job: build_theme to your local theme's style.css as well as the next release asset.

Let me know how it works for you.

It is working! Thank you!

Regarding that, possibly one option would be to use the API to check if the build exists or if it was successful. When I have some more free time I will dig though the API and through this plugin to try to improve it for other GitLab users.

Thank you for the quick response!

I added some logic to remove the branch switcher if using a release asset.

I can confirm that 3.0.0-alpha.5 just updated correctly. 馃檶

screenshot_01

Yap, I updated it on my website using the plugin too! Once again, thank you very much!

I plan on merging this into develop so when you see an update don't worry. You can keep using this branch until then. The update will automatically pull you back into the develop branch.

It will be in the next release.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jasonjersey picture jasonjersey  路  3Comments

alexclassroom picture alexclassroom  路  5Comments

alexjose picture alexjose  路  14Comments

PthPndr picture PthPndr  路  11Comments

andruwa13 picture andruwa13  路  3Comments