balazsgrill/wscgo

View on GitHub
.github/workflows/main.yml

Summary

Maintainability
Test Coverage
name: Main
on: [push]
jobs:

  build:
    name: Build
    runs-on: ubuntu-latest
    steps:

    - name: Get current time
      uses: srfrnk/current-time@v1.1.0
      id: current-time
      with:
        format: YYYYMMDDHHss

    - name: Set up Go 1.18
      uses: actions/setup-go@v1
      with:
        go-version: 1.18
      id: go

    - name: Install tools
      run: |
        sudo apt update
        sudo apt-get install -y build-essential devscripts debhelper gettext-base

    - name: Check out code into the Go module directory
      uses: actions/checkout@v2
    
    - id: dotenv
      uses: falti/dotenv-action@v0.2.3

    - name: Test
      run: |
        go test -v ./devices
        go test -v ./protocol
        go test -v ./config

    - name: Package
      env:
        VERSION: "${{ steps.dotenv.outputs.version }}-${{ steps.current-time.outputs.formattedTime }}"
        GOOS: "linux"
        GOARCH: "arm"
        GOARM: "5"
      run: |
        echo "Version: $VERSION"
        envsubst < debian/changelog.tpl > debian/changelog
        dpkg-buildpackage --target-arch armhf --host-arch armhf -b
        cp ../wscgo_${{ steps.dotenv.outputs.version }}-${{ steps.current-time.outputs.formattedTime }}_armhf.deb ./
    
    - uses: actions/upload-artifact@v1
      with:
        name: binary
        path: "wscgo"

    - uses: actions/upload-artifact@v1
      with:
        name: debian-package
        path: "wscgo_${{ steps.dotenv.outputs.version }}-${{ steps.current-time.outputs.formattedTime }}_armhf.deb"
    
    - name: Publish CI package
      id: push
      if: startsWith(github.ref, 'refs/tags/v')
      uses: cloudsmith-io/action@master
      with:
        api-key: ${{ secrets.CLOUDSMITH_API_KEY }}
        command: 'push'
        format: 'deb'
        owner: 'home2mqtt'             
        repo: 'home2mqtt'         
        distro: 'any-distro'   
        release: 'any-version'        
        republish: 'true' 
        file: "wscgo_${{ steps.dotenv.outputs.version }}-${{ steps.current-time.outputs.formattedTime }}_armhf.deb"