I wrote a workflow to cross compile commands and release to GitHub Release in 
GitHub Actions.

[https://github.com/jiro4989/repo-template-nim/blob/master/.github/workflows/main.yml](https://github.com/jiro4989/repo-template-nim/blob/master/.github/workflows/main.yml)
    
    
    name: build
    
    on:
      push:
      pull_request:
      release:
        types: [published]
    
    env:
      APP_NAME: 'APPNAME' # TODO: need change
    
    jobs:
      skip:
        runs-on: ubuntu-latest
        steps:
          - run: echo "Skip job"
      
      before:
        runs-on: ubuntu-latest
        if: "! contains(github.event.head_commit.message, '[skip ci]')"
        steps:
          - run: echo "not contains '[skip ci]'"
      
      build:
        runs-on: ${{ matrix.os }}
        strategy:
          matrix:
            os:
              - ubuntu-latest
              - windows-latest
              - macOS-latest
        needs: before
        env:
          NIM_VERSION: 1.2.0
        steps:
          - uses: actions/checkout@v1
          - name: Cache choosenim
            id: cache-choosenim
            uses: actions/cache@v1
            with:
              path: ~/.choosenim
              key: ${{ runner.os }}-choosenim-${{ env.NIM_VERSION }}
          - name: Cache nimble
            id: cache-nimble
            uses: actions/cache@v1
            with:
              path: ~/.nimble
              key: ${{ runner.os }}-nimble-${{ hashFiles('*.nimble') }}
          - uses: jiro4989/[email protected]
          - run: nimble build -Y
          - run: nimble test -Y
          - name: Archive files
            run: nimble archive
          - name: Release
            if: startsWith(github.ref, 'refs/tags/')
            uses: softprops/action-gh-release@v1
            with:
              files: 'dist/${{ env.APP_NAME }}_*.*'
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      
      create-tag-draft:
        runs-on: ubuntu-latest
        if: github.ref == 'refs/heads/master'
        needs: build
        steps:
          - uses: release-drafter/[email protected]
            env:
              GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
    
    Run

This workflow creates a tag-draft when master was pushed.  
And when you published the tag-draft, this workflow do cross-compiling your 
commands and release to GitHub Release.  


[https://github.com/jiro4989/repo-template-nim/releases](https://github.com/jiro4989/repo-template-nim/releases)

`run: nimble archive` is a original nimble task.  
This task creates a release file.  
It creates .zip file when OS is windows.  
It creates .tar.gz file when OS is MacOS or Linux.  


[https://github.com/jiro4989/repo-template-nim/blob/master/APPNAME.nimble](https://github.com/jiro4989/repo-template-nim/blob/master/APPNAME.nimble)
    
    
    import os, strformat
    
    task archive, "Create archived assets":
      let app = "APPNAME" # TODO: need change
      let assets = &"{app}_{buildOS}"
      let dir = "dist"/assets
      mkDir dir
      cpDir "bin", dir/"bin"
      cpFile "LICENSE", dir/"LICENSE"
      cpFile "README.rst", dir/"README.rst"
      withDir "dist":
        when buildOS == "windows":
          exec &"7z a {assets}.zip {assets}"
        else:
          exec &"tar czf {assets}.tar.gz {assets}"
    
    Run

Reply via email to