Haxe + GitHub Workflows / Actions

Howdy all!

So I’ve been playing with github workflows for haxeui the last couple of days, and came up with a pretty decent workflow so thought i would share in case its useful for anyone else or in case anyone might like to either write, or help write a proper haxe workflow custom action… HF? :wink:

An important thing i wanted / needed in my build is the ability for commits to haxeui-core to trigger builds (github workflows) in other repositories, namely, the haxeui-backends. As it turns out this was relatively simple by having the backend repos trigger on “push” as well as “repository_dispatch”… all haxeui-core has to do now in its workflow is send a load of curl commands to these repos to trigger this dispatch:

    steps:
    - uses: actions/checkout@v1
    - name: Dispatch
      run: |
        curl --fail -X POST https://api.github.com/repos/ianharrigan/GitHubActionsTest/dispatches -H 'Accept: application/vnd.github.everest-preview+json' -H 'Authorization: Bearer ${{ secrets.GH_TOKEN }}' --data "{\"event_type\": \"test\"}"

The other fairly important thing was the custom workflow action. I needed a way to be able to install and setup haxe as simply as possible across multiple repos, i could of just copied and pasted to yaml config, but this gets out of hand pretty fast with a load of repos, so ive thrown together a custom workflow action that does this for me, then using it in my backend workflow is as simple as:

    steps:
    - uses: actions/checkout@v1
    - uses: haxeui/haxeui-core/.github/actions/haxe@master
      with:
        haxe-version: 4.0.3

The action is really pretty crappy and just a “make it work” type of thing, but work it does, im using it across all my haxeui repos (well, the ones i have moved over to github workflows anyway). Another example of it is on my test repos (it uses a different source repo for the action, but its the same essentially):

name: Haxe (all versions, all platforms, all targets)

on: [push, repository_dispatch]

jobs:
  build:

    runs-on: ${{ matrix.os }}

    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        haxe-version: [3.4.4, 4.0.3]
        hxml: [js.hxml, cpp.hxml]

    steps:
    - uses: actions/checkout@v1
    - uses: ianharrigan/GitHubActionsTest/.github/actions/haxe@master
      with:
        haxe-version: ${{ matrix.haxe-version }}

    - name: Build app (${{ matrix.hxml }}, haxe ${{ matrix.haxe-version }}, ${{ matrix.os }})
      run: |
        haxelib install ${{ matrix.hxml }} --always
        haxe ${{ matrix.hxml }}

So that will build a js and hxcpp app on linux, osx and windows using haxe 3 and 4.

Anyways, i figured possibly this might be useful for someone, and might motivate / help someone to write a proper (maybe official?) custom haxe workflow action.

Here are some links to the workflows / actions for ref (may also be useful to someone maybe):

Cheers,
Ian

18 Likes

Note that there is now a dedicated action to setup Haxe:

4 Likes

Nice, good to know, ill have to take it for a spin, would be nice to retire the extremely messy versions i came up with - had a quick look of the code and looks ALOT cleaner, so that bodes well :slight_smile:

Thanks for the info!

Ian

Thanks for sharing! I’ve been using Ian’s action to build Lime, OpenFL, and Feathers UI. I’ll be sure to give yours a try too.

Thanks a lot for this @cedx. Your action allowed me to create mine :slight_smile:

I’ve just created a workflow to automatically submit a package to haxelib whenever the version changes: GitHub - endel/haxelib-publish-github-actions-test: Testing GitHub Actions to publish a Haxe package to the haxelib registry.

4 Likes

Thanks for reminding me, keep meaning to move all my repos over the @cedx’s versions as they look like a 100% improvement over the thrown together versions i came up with!

Cheers,
Ian

1 Like

Thanks a lot for this @cedx. Your action allowed me to create mine.

I’m not the author of this action. We should all thank KrdLab (krdlab (Sho Kuroda) · GitHub).

3 Likes

Running tests with different targets is quite easy because it exists a dedicated action to setup most of them:

But I couldn’t find anything for HashLink. It turns out that it’s finally very easy to setup HashLink with a workflow running on the Windows platform (only! As there is currently no Linux/macOS build on the HashLink repository):

jobs:
  hashlink:
    runs-on: windows-latest
    steps:
      - name: Fetch sources
        uses: actions/checkout@v2
      - name: Set up Haxe
        uses: krdlab/setup-haxe@v1
        with:
          haxe-version: 4.1.4
      - name: Set up HashLink
        run: |
          Invoke-WebRequest https://github.com/HaxeFoundation/hashlink/releases/download/1.11/hl-1.11.0-win.zip -OutFile hashlink.zip
          Expand-Archive hashlink.zip
          Add-Content $Env:GITHUB_PATH (Resolve-Path hashlink/hl-1.11.0-win) -NoNewline
      - name: Check environment
        run: |
          haxe --version
          hl --version
      - name: Install dependencies
        run: haxelib install all --always
      - name: Run tests
        run: haxe hashlink.hxml

Where the hashlink.hxml file is similar to:

--class-path src
--class-path test
--hl tests.hl
--library tink_unittest
--main TestAll
--cmd hl tests.hl
4 Likes

There’s now a dedicated action for HashLink:
Setup Hashlink VM

Thanks @PXshadow for the inspiration!

3 Likes

@endel would it be possible to create github action for haxelib publish ?