From 99ca508d8ffd34ec77ccad7937ec46435ee5a90b Mon Sep 17 00:00:00 2001 From: "Tobias Wellnitz, DH1TW" Date: Sun, 8 Dec 2019 08:54:17 +0100 Subject: [PATCH] migrated CI to Github Actions --- .github/workflows/build.yml | 217 ++++++++++++++++++++++++++++++++++++ Makefile | 18 +-- README.md | 3 +- 3 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..11f177b --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,217 @@ +name: Cross Platform build + +on: [push, pull_request] + +jobs: + build_linux: + runs-on: ubuntu-18.04 + strategy: + matrix: + version: ['linux-armhf', 'linux-arm64', 'linux-i386', 'linux-amd64'] + include: + # add the GO naming convention for OS ($GOOS) and architecture ($GOARCH) + # instead of using Linux' naming convention (version items). + - version: linux-armhf + OS: linux + ARCH: arm + - version: linux-arm64 + OS: linux + ARCH: arm64 + - version: linux-i386 + OS: linux + ARCH: '386' + - version: linux-amd64 + OS: linux + ARCH: amd64 + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - name: Build binary for ${{ matrix.version }} + run: | + docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp dh1tw/remoteaudio-xcompile:${{ matrix.version }} /bin/sh -c 'make dist' + - name: Prepare build artifact for stashing + run: | + mkdir release + mv ./remoteAudio ./release + # The build artifact can be identified by the trailing sha of the git commit + - name: Stash the build artifact + uses: actions/upload-artifact@v1 + with: + name: remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }} + path: ./release + + build_macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - name: Install dependencies + run: | + brew install pkg-config + brew install opus + brew install opusfile + brew install portaudio + brew install protobuf + brew install libsamplerate + brew install upx + - name: Install code generators + run: make install-deps + - name: Build binary for macOS + run: | + export PATH=/System/Volumes/Data/Users/runner/go/bin:$PATH + make dist + - name: Prepare build artifact for stashing + run: | + mkdir release + mv ./remoteAudio ./release + # The build artifact can be identified by the trailing sha of the git commit + - name: Stash the build artifact + uses: actions/upload-artifact@v1 + with: + name: remoteAudio-darwin-amd64-${{ github.sha }} + path: ./release + + build_windows: + runs-on: ubuntu-18.04 + strategy: + matrix: + version: ['windows-amd64', 'windows-i386'] + include: + # add the GO naming convention for OS ($GOOS) and architecture ($GOARCH) + # instead of using Linux' naming convention (version items). + - version: windows-amd64 + OS: windows + ARCH: amd64 + - version: windows-i386 + OS: windows + ARCH: '386' + steps: + - uses: actions/checkout@v1 + with: + submodules: true + - name: Build binary for ${{ matrix.version }} + run: | + docker run --rm -v "$PWD":/usr/src/myapp -w /usr/src/myapp dh1tw/remoteaudio-xcompile:${{ matrix.version }} /bin/sh -c 'make dist && /scripts/getlibs.sh .' + - name: Prepare build artifacts for stashing + run: | + mkdir release + mv ./remoteAudio.exe ./release + mv ./*.dll ./release + # The build artifact can be identified by the trailing sha of the git commit + - name: Stash the build artifact + uses: actions/upload-artifact@v1 + with: + name: remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }} + path: ./release + + # A Github release is created whenever the git reference contains a tag, starting with 'v*' (e.g. v0.4.2) + # And the previous build jobs have been successful + create_release: + runs-on: ubuntu-18.04 + needs: [build_linux, build_macos, build_windows] + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Create Release + id: create_release + uses: actions/create-release@v1.0.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: true + prerelease: false + # since jobs can not share any variables we have to copy the URL of the created Github release + # into a file and stash it as an artifact + - name: Copy release URL into file + run: | + mkdir release + printf "%s" "${{ steps.create_release.outputs.upload_url }}" > release/url.txt + - name: Stash file containing the release URL as an artifact + uses: actions/upload-artifact@v1 + with: + name: release-url + path: ./release + + # In this job we upload the release artifacts to the corresponding release + upload: + runs-on: ubuntu-18.04 + needs: create_release # release must be created before this job can start + strategy: + matrix: + version: ['linux-armhf', 'linux-arm64', 'linux-i386', 'linux-amd64', 'darwin-amd64', 'windows-amd64', 'windows-i386'] + # add the GO naming convention for OS ($GOOS) and architecture ($GOARCH) + # instead of using Linux' naming convention (version items). + include: + - version: linux-armhf + OS: linux + ARCH: arm + - version: linux-arm64 + OS: linux + ARCH: arm64 + - version: linux-i386 + OS: linux + ARCH: '386' + - version: linux-amd64 + OS: linux + ARCH: amd64 + - version: darwin-amd64 + OS: darwin + ARCH: amd64 + - version: windows-amd64 + OS: windows + ARCH: amd64 + - version: windows-i386 + OS: windows + ARCH: '386' + steps: + # Since Github actions (currently) doesn't provide a slugged version of the git tag we have to + # create it by ourselves. It is then made available to other steps in this job as a step.outputs + # variable + - name: Get the version (git tag) + id: get_version + run: | + echo ${GITHUB_REF/refs\/tags\//} + echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\//} + - name: Retrieve stashed intermediary build artifact + uses: actions/download-artifact@v1 + with: + name: remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }} + # rename the retrieved intermediary artifact and prepare zip file + - name: Prepare release artifact + env: + VERSION: ${{ steps.get_version.outputs.VERSION }} + run: | + mv ./remoteAudio-${{ matrix.OS }}-${{ matrix.ARCH }}-${{ github.sha }}/* . + test -f ./remoteAudio && chmod +x ./remoteAudio #only on linux & darwin needed + zip -j remoteAudio-$VERSION-${{ matrix.OS }}-${{ matrix.ARCH }}.zip ./* + # Download the previously uploaded artifact which contains the release URL + - name: Retrieve stashed release URL + uses: actions/download-artifact@v1 + with: + name: release-url + # Write content of downloaded file (a string which contains the release URL) into a step.outputs variable + - name: Read release URL + id: get_release_url + run: echo ::set-output name=URL::$(cat release-url/url.txt) + # This step is only needed because the upload-release-asset currently doesn't support + # environment variables. Therefore they must be written and referenced through step.outputs + - name: Prepare artifact metadata + id: prepare_artifact_metadata + env: + VERSION: ${{ steps.get_version.outputs.VERSION }} + run: | + echo ::set-output name=ARTIFACT_PATH::./remoteAudio-$VERSION-${{ matrix.OS }}-${{ matrix.ARCH }}.zip + echo ::set-output name=ARTIFACT_NAME::remoteAudio-$VERSION-${{ matrix.OS }}-${{ matrix.ARCH }}.zip + # Finally upload the artifact to the corresponding release + - name: Upload Release Artifact ${{ matrix.version }} + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.get_release_url.outputs.URL }} + asset_path: ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_PATH }} + asset_name: ${{ steps.prepare_artifact_metadata.outputs.ARTIFACT_NAME }} + asset_content_type: application/gzip \ No newline at end of file diff --git a/Makefile b/Makefile index ba1d390..63b6186 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +#!/bin/bash + PKG := github.com/dh1tw/remoteAudio COMMITID := $(shell git describe --always --long --dirty) COMMIT := $(shell git rev-parse --short HEAD) @@ -21,8 +23,13 @@ dist: protoc --proto_path=./icd --micro_out=./sb_audio ./icd/audio.proto cd webserver; \ rice embed-go - go build -v -ldflags="-w -X github.com/dh1tw/remoteAudio/cmd.commitHash=${COMMIT} \ + go build -v -ldflags="-w -s -X github.com/dh1tw/remoteAudio/cmd.commitHash=${COMMIT} \ -X github.com/dh1tw/remoteAudio/cmd.version=${VERSION}" + @if [ ${GOOS} = "windows" ]; \ + then upx ./remoteAudio.exe; \ + else \ + upx ./remoteAudio; \ + fi # test: # @go test -short ${PKG_LIST} @@ -47,18 +54,11 @@ install-deps: go get github.com/gogo/protobuf/protoc-gen-gofast go get github.com/GeertJohan/go.rice/rice go get github.com/micro/protoc-gen-micro - go get ./... # static: vet lint # go build -i -v -o ${OUT}-v${VERSION} -tags netgo -ldflags="-extldflags \"-static\" -w -s -X main.version=${VERSION}" ${PKG} -client: build - ./remoteAudio client mqtt - -server: build - ./remoteAudio server mqtt - clean: -@rm remoteAudio remoteAudio-v* -.PHONY: build client server install vet lint clean install-deps \ No newline at end of file +.PHONY: build install vet lint clean install-deps \ No newline at end of file diff --git a/README.md b/README.md index 3e84564..627a552 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,5 @@ # remoteAudio -Linux & MacOS [![Build Status](https://travis-ci.org/dh1tw/remoteAudio.svg?branch=master)](https://travis-ci.org/dh1tw/remoteAudio) -Windows [![Build status](https://ci.appveyor.com/api/projects/status/it6077sklplhgkyf?svg=true)](https://ci.appveyor.com/project/dh1tw/remoteaudio) +![Build Status](https://github.com/dh1tw/remoteAudio/workflows/Cross%20Platform%20build/badge.svg?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/dh1tw/remoteAudio)](https://goreportcard.com/report/github.com/dh1tw/remoteAudio) [![MIT license](http://img.shields.io/badge/license-MIT-brightgreen.svg)](http://opensource.org/licenses/MIT) [![GoDoc](https://godoc.org/github.com/dh1tw/remoteAudio?status.svg)](https://godoc.org/github.com/dh1tw/remoteAudio)