Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the "version" in Composer git repository refer to the release (tag) on GitHub?

I need to use Composer to manage a dependency (normalize.css and others) without composer.js in the project root. I ended up defining a package but I have a few questions:

{
    "require": {
        "twbs/bootstrap": "~3.0",
        "fortawesome/font-awesome": "~3.2",
        "necolas/normalize.css": "*"
    },
    "repositories": [
        {
            "type":"package",
            "package": {
                "name": "necolas/normalize.css",
                "version":"2",
                "source": {
                    "url": "https://github.com/necolas/normalize.css.git",
                    "type": "git",
                    "reference":"master"
                }
            }
        }
    ]
}

Does the version in my package refer to a release (tag) in the GitHub repository? If yes, how can I specify i.e. ~2.1 (I get invalid package definition) or the latest tag available?

For necolas/normalize.css I'd like to always get the latest version of the master branch.

like image 699
gremo Avatar asked Oct 08 '13 18:10

gremo


People also ask

What is release tag in GitHub?

A Git release is a GitHub object that helps show official program versions on your project page. The object allows showing a specific commit point, a Git tag, with a release status. Managing releases is an easy and straightforward process performed on the GitHub website.

How do I find my GitHub repository version?

On GitHub.com, navigate to the main page of the repository. To the right of the list of files, click Releases. At the top of the Releases page, click Releases.

What is a Composer Git?

Composer is tool used to manage dependencies and file autoloading in your PHP project, it simply allows you to download packages from multiple repositories using composer.


2 Answers

Here is my solution:

For test purpose I have this composer.json file:

{
    "name": "mycompagny/composer-project",
    "repositories": [
        {
            "type": "vcs",
            "url": "http://localhost/git/test.composer.dep.git"
        }
    ],
    "require" : {
        "mycompagny/test.composer.dep": "dev-master#v2.0.0"
    },
    "minimum-stability": "dev"
}

In the require key, put #youversion after dev-master to point to your git tag "yourversion".

The tag after # here act as a commit. (according to : https://getcomposer.org/doc/04-schema.md#package-links)

like image 73
wonzbak Avatar answered Nov 14 '22 21:11

wonzbak


"Does the version in my package refer to a release"

No, a version inside a package entry defines the version number that Composer should refer to this package as.

Setting the version explicitly is required for packages unfortunately, even if they are coming from Git.

"how can I specify i.e. ~2.1 (I get invalid package definition) or the latest tag available?"

It looks like you can't. The version listed in a package has to be an actual version number, rather than a version number range, and there's no way to fetch the tags from Git, which sucks.

If you were to replace using a Package repository to using a zipball Artifact package, it would be really easy to add a composer.json with the relevant info after you've downloaded the zipball from Github.

I've added that as a proof of concept to https://github.com/Danack/IntahwebzRepo , which is a simple script to download zipballs from Github, and then either add a version entry to their composer.json, or completely generate a composer.json if they don't already have one.

Once the zipballs are downloaded and modified it then uses them in a Satis (aka Packagist) repository.

like image 33
Danack Avatar answered Nov 14 '22 21:11

Danack