This tutorial will help you publish your library automatically to lib.haxe.org when you create a release on GitHub.
- 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.
- 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.
- Create a (useful) project and push to GitHub.
- 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": { } }
- 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
- 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
- GitHub: Enable travis
- Go to https://github.com/GITHUB_USERNAME/LIBNAME/settings/installations
- Add service: "Travis CI"
- You can skip the details (user, token, domain), just press the green button "Add service".
- 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 ✓)
- Travis: Configure the settings
- Go to the project settings https://travis-ci.org/GITHUB_USERNAME/LIBNAME/settings
- Add "Environment Variables":
- name: HAXELIB_PWD
- value: **************** (Strong password, don't tell anyone)
- Disable "Display value in build log" (needs to be off, guess why)
Assuming your project is good to go, you can now automatically publish to Haxelib.
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
- If you are using Git Bash on Windows, install Zip for Git Bash extension first.
- Update
version
anddescription
in haxelib.json - Github > Releases > Make new release https://github.com/GITHUB_USERNAME/LIBNAME/releases/new
- Enter release details
- Tag name should be same as
version
in haxelib.json - Add release notes
- Press "Publish release"
- Tag name should be same as
- Wait for Travis
- 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.