1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Setup git repos

Discussion in 'XenForo Development Discussions' started by Earl, Sep 25, 2016.

  1. Earl

    Earl Member

    Does anyone use version control system with XenForo addons?
    In case you guys are using git how do you setup repositories with xf addons?

    In my case I think I should use git submodules on each plugin, but currently I'm facing a problem

    |    |       +-Controller/..
    |    |       |
    |    |       +-Model/..
    |    |       |
    |    |       +-.git
    |    |
    |    +--Model/..
    |    +--View/..
    |    +--ControllerPublic/..
    "XenForo" Folder is the super project and I can initialize a git submodule in "XenForo/library/MyPlugin" directory. (of cause I can export the plugin.xml file and put it inside the same directory so I can track templates phrases etc.)
    But the problem is in "/js/MyPlugin" directory. I can't track that folder because it's in outside of the submodule.

    Did anyone face this problem?
    How do you guys setup git repos?

    I'm using Vagrant on a windows desktop pc, so the symlinks doesn't work I guess.
    Robust likes this.
  2. Sim

    Sim Well-Known Member

    I have a /library/MyAddon/js and a /library/MyAddon/style directory which during first deployment gets soft linked from /js/myaddon/ and /styles/myaddon/ respectively.

    It's not ideal, but it works and means that I can auto-deploy file updates. I run 8 forums with mostly the same custom-built addons deployed to each, so automation is important.

    I still need to manually install the addon.xml file (haven't got around to automating that part yet), but deploying the xml file automatically and then just copy-pasting the URL to the xml file into the addon upgrade form on each site takes very little time.

    I don't have a super project - no point checking in the core files, I just have one git repo per addon and my customised components, site style and language file is deployed as part of a site-specific addon for each site.

    Edit: I missed your comment about developing on Windows and so no symlinks ... which is why I use VMware running Ubuntu as my local dev servers (pretty much identical setup to my production server) so I can develop the same way I deploy.
    Jeremy P likes this.
  3. Robust

    Robust Well-Known Member

    I'm kinda interested in the answer to this. This doesn't seem like an elegant/good solution here. Anyone here using git, how do you do it?
  4. Sim

    Sim Well-Known Member

    Did you read my post?

    One repo per addon, include your style and/or js folders within the repo and then symlink those folders from the main styles / js folders. This step could even be done as part of your auto-deploy process (I use DeployHQ).

    Still requires you to manually upload your addon xml file.

    There's not really any other way to do it - you can't check in files at a higher level because they need to be contained within a single folder for your git repo.

    The only other approach would be to have a deployment script which copies styles/js files from the source repo (under your main addon folder) to the destination - but I prefer to use symlinks so that there is only one copy of the files on the server and a git pull will be able to delete unneeded files which could prevent security issues - you don't want old files hanging around on your server.

    For people on Windows - you should be able to do symlinks if you are using NTFS.

    I just counted - I have 25 addons I deploy in this way across 8 XenForo installations.
    ozzy47 likes this.
  5. Robust

    Robust Well-Known Member

    First post was less clear to me, I think I misunderstood how you wrote it.

    I use Mac OS X, Debian for my development VM to execute the scripts (synced realtime using Vagrant).

    So you do something like this?

    Local git repo directory:
    | addon.xml
    | library
    | - | MyAddon
    | - | - | Listener.php
    | js
    | - | myaddon
    | styles
    | - | myaddon
    | - | - | spritesheet.png
    Then you use symlinks to do this:
    | XF files
    | More XF files
    | library
    | - | XenForo
    | - | - | ...
    | - | MyAddon - symlinked to the directory mentioned in previous response
    | - | - | Listener.php
    Does XenForo follow this symlink? Sounds to me like it would ignore it, no?
  6. Sim

    Sim Well-Known Member

    Nope - you've got it around the wrong way.

    My local dev environment looks like this:
    /xenforo (xenforo root ... whatever folder your xenforo files are in)
    /xenforo/library/MyAddon (my addon root - this is the folder that gets checked into git and where all my addon php files are)
    /xenforo/library/MyAddon/style (my addon style files go in here)
    /xenforo/library/MyAddon/js (my addon js files go in here)
    /xenforo/styles/myaddon -> ../library/MyAddon/style/ (this is a symlink to the style folder in my addon folder)
    /xenforo/js/myaddon -> ../library/MyAddon/js/ (this is a symlink to the js folder in my addon folder)
    So I point my Git client at /xenforo/library/MyAddon and tell it to check that into source control

    Then when deploying, I pull from git into the /xenforo/library/MyAddon folder on my server and all my addon files end up in that folder, including style and js files

    So it's pretty much literally this:

    # my xenforo root path is /srv/www/xenforo, substitute your own here
    cd /srv/www/xenforo/library
    # create the MyAddon folder in library and pulls the code from git
    git clone https://bitbucket.org/hampel/myaddon.git MyAddon
    # go back to the XenForo styles folder
    cd ../styles
    # link to my addon styles folder
    ln -s ../library/MyAddon/style/ myaddon
    # go back to the XenForo js folder
    cd ../js
    # link to my addon js folder
    ln -s ../library/MyAddon/js/ myaddon
    # manually install addon code, which I put in 'library/MyAddon/addon-MyAddon.xml'
    ... and when updating from git, you just go:

    cd /srv/www/xenforo/library/MyAddon
    git pull
    # ... and manually install updated addon code if necessary
    Of course, when actually referring to style or js files in your code, you'll use something like:

    ... becomes:
    <img src="styles/myaddon/myimage.png" />
    ... and ...
    ... becomes:
    <xen:require js="js/myaddon/myscript.js" />
    Robust likes this.
  7. Sim

    Sim Well-Known Member

    ... I should also add that the vast majority of my addons do not contain style or js folders at all (and thus there is no symlink required) - but then, most of my addons are back-end integration and don't have much in the way of a UI (or only utilise the core UI features).
  8. Robust

    Robust Well-Known Member

    Your method is very elegant. Thanks so much for sharing. I'm going to be utilising that method as well. It's been the way I've done it so far, but having styles and js in some add-ons has been awkward.
  9. Sim

    Sim Well-Known Member

    You just have to remember to create the symlinks ... so many times I've deployed something to a new server and then wondered why I'm getting broken image links :rolleyes:

    I never did get around to setting up an auto-deploy script to do it for me. I should do that one day so that DeployHQ can take care of symlinks for me automagically whenever I deploy to a new server.
  10. Robust

    Robust Well-Known Member

    I'm lazy so I'll probably make a script to make symlinks automatically. When I do I'll be happy to share.

Share This Page