From 96413344ce56cab7f25564e988ae5dd0ad6de8bd Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 11 Jun 2020 23:12:41 +0200 Subject: [PATCH] github-actions --- .github/workflows/ci.yml | 37 +++++++++ .github/workflows/release.yml | 148 ++++++++++++++++++++++++++++++++++ bundle/build.sh | 24 ++---- 3 files changed, 192 insertions(+), 17 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..5372f90 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,37 @@ +name: Haskell CI + +on: [push] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-haskell@v1 + with: + ghc-version: '8.6.5' + cabal-version: '3.2' + - name: Cache + uses: actions/cache@v1 + env: + cache-name: cache-cabal + with: + path: ~/.cabal + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/*.cabal') }}-${{ hashFiles('**/cabal.project') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + - name: Setup paths + run: echo "::add-path::${HOME}/.cabal/bin" + - name: Install dependencies + run: | + cabal update + cabal install purescript-0.13.8 + cabal build --only-dependencies --enable-tests --enable-benchmarks + - name: Build + run: cabal build exe:zephyr + - name: Run tests + run: cabal run zephyr-test -- -m generators -m dceEval -m dceExpr -m TestLib diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..37ceddc --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,148 @@ +# Release workflow. +# It runs two jobs +# - build job which builds zephyr on: linux, macos and windows and uploads +# artifacts using `action/upload-artifact`. +# - release job which depends on completion of the previous job: +# * creata a new release using `actions/create-release` +# * downloads artifacts using `action/download-artifact`. +# * uploads artifacts to the release with `action/upload-release-asset` +# The last two actions are done for all three systems. +# +on: + push: + tags: + - 'v*' + +name: Upload Release Assets + +jobs: + build: + name: Release build + strategy: + matrix: + os: [ubuntu-latest, macos-latest, windows-latest] + runs-on: ${{ matrix.os }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - uses: actions/setup-haskell@v1 + with: + ghc-version: '8.6.5' + cabal-version: '3.2' + - name: Setup paths + run: echo "::add-path::${HOME}/.cabal/bin" + - name: Build zephyr + run: bash bundle/build.sh ${{ runner.os }} + - name: Upload tar file + uses: actions/upload-artifact@v2 + with: + name: ${{ runner.os }}.tar.gz + path: bundle/${{ runner.os }}.tar.gz + - name: Upload sha file + uses: actions/upload-artifact@v2 + with: + name: ${{ runner.os }}.sha + path: bundle/${{ runner.os }}.sha + + release: + needs: [build] + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Release ${{ github.ref }} + draft: true + prerelease: false + + - name: Download Linux.tar.gz + uses: actions/download-artifact@v2 + with: + name: Linux.tar.gz + - name: Download Linux.sha + uses: actions/download-artifact@v2 + with: + name: Linux.sha + - name: Upload Linux.tar.gz + id: upload-Linux + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: Linux.tar.gz + asset_name: Linux.tar.gz + asset_content_type: application/zip + - name: Upload Linux.sha + id: upload-Linux-sha + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: Linux.sha + asset_name: Linux.sha + asset_content_type: application/zip + + - name: Download macOS.tar.gz + uses: actions/download-artifact@v2 + with: + name: macOS.tar.gz + - name: Download macOS.sha + uses: actions/download-artifact@v2 + with: + name: macOS.sha + - name: Upload macOS.tar.gz + id: upload-macOS + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: macOS.tar.gz + asset_name: macOS.tar.gz + asset_content_type: application/zip + - name: Upload macOS.sha + id: upload-macOS-sha + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: macOS.sha + asset_name: macOS.sha + asset_content_type: application/zip + + - name: Download Windows.tar.gz + uses: actions/download-artifact@v2 + with: + name: Windows.tar.gz + - name: Download Windows.sha + uses: actions/download-artifact@v2 + with: + name: Windows.sha + - name: Upload Windows.tar.gz + id: upload-Windows + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: Windows.tar.gz + asset_name: Windows.tar.gz + asset_content_type: application/zip + - name: Upload Windows.sha + id: upload-Windows-sha + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: Windows.sha + asset_name: Windows.sha + asset_content_type: application/zip diff --git a/bundle/build.sh b/bundle/build.sh index 7094b53..ccee4a7 100755 --- a/bundle/build.sh +++ b/bundle/build.sh @@ -4,25 +4,15 @@ ## Usage bundle.sh os set -e + if [[ -z ${1} ]]; then - echo "Usage build.sh os_name"; + echo "Usage build.sh [Linux|macOS|Windows]"; exit 1; fi +OS_NAME="$1" -# Build OS_NAME -case $1 in - "linux") - OS_NAME="x86_64-linux";; - "osx") - OS_NAME="x86_64-osx";; - "win64") - OS_NAME="x86_64-windows";; - *) - OS_NAME=${1};; -esac - -if [[ "$OS" = "win64" ]] +if [[ "$OS" = "Windows" ]] then BIN_EXT=".exe" else @@ -31,11 +21,11 @@ fi BUNDLE_DIR="bundle/zephyr" mkdir -p ${BUNDLE_DIR} -cabal install --install-method=copy --installdir ${BUNDLE_DIR} exe:zephyr ZEPHYR="${BUNDLE_DIR}/zephyr${BIN_EXT}" +cabal install --install-method=copy --installdir ${BUNDLE_DIR} exe:zephyr # strip the executable -if [[ ${OS_NAME} != "x86_64-windows" ]]; then +if [[ ${OS_NAME} != "Windows" && -a ${ZEPHYR} ]]; then strip ${ZEPHYR}; fi cp README.md LICENSE ${BUNDLE_DIR}; @@ -44,7 +34,7 @@ cp README.md LICENSE ${BUNDLE_DIR}; cabal info . > "${BUNDLE_DIR}/info" # Calculate the SHA hash -if [[ ${OS_NAME} = "x86_64-windows" ]]; then +if [[ ${OS_NAME} = "Windows" ]]; then SHASUM="openssl dgst -sha1"; else SHASUM="shasum";