Skip to content

Instantly share code, notes, and snippets.

@markknol
Last active July 17, 2018 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save markknol/bb720aa8f7acab8960acf77bb1497a18 to your computer and use it in GitHub Desktop.
Save markknol/bb720aa8f7acab8960acf77bb1497a18 to your computer and use it in GitHub Desktop.
Publish to Haxelib (using Travis) using Github Releases

Publish to Haxelib using Travis using Github Releases

This tutorial will help you publish your library automatically to lib.haxe.org when you create a release on GitHub.

Motivation

  • Collaborators on GitHub can help publish on haxelib without the need of sharing/knowing your password.
  • It automatically tests your project, this ensures you don't publish broken builds.
  • It makes sure you have tagged your projects because that's what GitHub does for you when doing a release.
  • It is more transparent for collaborators/users what goes into the haxelib package zip file.
  • It will make you look 36% more professional.

What do you need

  • GitHub account and basic knowledge how to use Git.
  • A Travis account. You can create one by linking your GitHub profile.
  • A Haxelib account. If you have Haxe installed, you can run command-line: haxelib register. Remember your password.

Getting started

  1. Create a (useful) project and push to GitHub.
  2. Create and push haxelib.json. This is the configuration for Haxelib projects.
    {
     "name": "LIBNAME",
     "url": "https://github.com/GITHUB_USERNAME/LIBNAME",
     "license": "MIT",
     "tags": [],
     "description": "Cool Project",
     "version": "0.0.1",
     "classPath": "src/",
     "releasenote": "Initial release",
     "contributors": [
     	"markknol"
     ],
     "dependencies": {
    
     }
    }
  3. Create and push .travis.yml. This is the configuration for Travis.
    sudo: required
    dist: trusty
    
    language: haxe
    
    haxe:
      - "3.4.7"
      - "development"
    
    matrix:
      allow_failures:
        - haxe: development
    
    install:
      - haxelib dev LIBNAME .
    
    script:
      - haxe test.hxml
    
    deploy:
      - provider: script
        haxe: 3.4.7
        script: bash ./release_haxelib.sh $HAXELIB_PWD
        on:
          tags: true
  4. Create and push release_haxelib.sh. This is a bash file that Travis will run to deploy to Haxelib. Leave $HAXELIB_PWD like this, we will give Travis the password in a secure way. As you can see, it creates a zip which will be send to Haxelib. This zip includes the src-folder, all markdown files, json files and hxml files and run file (if present). You can customize this to your needs.
    #!/bin/sh
    rm -f library.zip
    zip -r library.zip src *.md *.json *.hxml run.n
    haxelib submit library.zip $HAXELIB_PWD --always
  5. GitHub: Enable travis
  6. Travis: Enable travis for project
    • You need to have your GitHub account synced to Travis.
    • Go to https://travis-ci.org/profile/GITHUB_USERNAME
    • Press "Sync account" this will update the repositories list.
    • Find the GitHub repository in the list, enable the project (make option ✓)
  7. Travis: Configure the settings

Publish to Haxelib via Github Release

Assuming your project is good to go, you can now automatically publish to Haxelib.

New Haxelib users

If you never ever published to Haxelib before, then the first release should be done manually.

If the zip command doesn't work, you can just create the zip yourself. As you can see, it includes the src-folder, all markdown files, json files and hxml files. You can customize this to your needs.

Run from commandline (bash):

zip -r library.zip src *.md *.json *.hxml run.n
haxelib submit library.zip

Release using GitHub releases \o/

  1. Update version and description in haxelib.json
  2. Github > Releases > Make new release https://github.com/GITHUB_USERNAME/LIBNAME/releases/new
  3. Enter release details
    • Tag name should be same as version in haxelib.json
    • Add release notes
    • Press "Publish release"
  4. Wait for Travis
  5. Check if it actually released the project https://lib.haxe.org/recent/. Congrats, your library is published.

Optional fun:

  • Add a Travis badge to your README.md
  • Since you now have automatic deployment, you also have automated testing. You can add more tests.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment