From f0637fc5fa582cce949a8a081b70a03cac705529 Mon Sep 17 00:00:00 2001 From: "Michael F. Herbst" Date: Tue, 8 Dec 2020 16:05:36 +0100 Subject: [PATCH] Release creation (#8) --- .github/workflows/ci.yaml | 76 +++++++++++++++++++++++------- .github/workflows/deploy_conda.yml | 2 +- scripts/pack_release.py | 35 ++++++++++++++ 3 files changed, 96 insertions(+), 17 deletions(-) create mode 100755 scripts/pack_release.py diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index abee07174..75b570907 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -2,9 +2,6 @@ name: CI on: [push] -env: - BUILD_TYPE: Release - jobs: build: runs-on: ${{ matrix.os }} @@ -33,24 +30,71 @@ jobs: ${{ runner.os }}-deploy- ${{ runner.os }}- - - name: Create Build Environment - run: cmake -E make_directory ${{runner.workspace}}/build - - - name: Configure CMake + - name: Build shell: bash - working-directory: ${{runner.workspace}}/build run: | - export PATH="/usr/local/opt/ccache/libexec:$PATH" - export PATH="/usr/lib/ccache:$PATH" - cmake $GITHUB_WORKSPACE -GNinja -DCMAKE_BUILD_TYPE=$BUILD_TYPE + ccache --max-size 2G + ./build_libtensor.py -v -d ${{runner.workspace}}/build --install ${{runner.workspace}}/install --type Release - - name: Build + - name: Test working-directory: ${{runner.workspace}}/build shell: bash - run: cmake --build . --config $BUILD_TYPE + run: ctest --output-on-failure - - name: Test - working-directory: ${{runner.workspace}}/build + - name: Bundle tarball shell: bash - run: ctest -C $BUILD_TYPE + run: | + ./scripts/pack_release.py ${{runner.workspace}}/install + - name: Upload tarball as artefact + uses: actions/upload-artifact@v2 + with: + name: libtensorlight-${{ matrix.os }} + path: libtensorlight-*.tar.gz + + release: + if: startsWith(github.ref, 'refs/tags') + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v2 + with: + path: artifacts + - name: Glob asset paths + id: asset_paths + run: | + LINUX_PATH=$(ls artifacts/*/*.tar.gz | grep -i linux | head -n 1) + LINUX_NAME=$(basename "$LINUX_PATH") + MACOS_PATH=$(ls artifacts/*/*.tar.gz | grep -i macos | head -n 1) + MACOS_NAME=$(basename "$MACOS_PATH") + RELEASE_NAME=v$(echo "$LINUX_NAME" | cut -d- -f2) + echo "::set-output name=linux_path::$LINUX_PATH" + echo "::set-output name=macos_path::$MACOS_PATH" + echo "::set-output name=linux_name::$LINUX_NAME" + echo "::set-output name=macos_name::$MACOS_NAME" + echo "::set-output name=release_name::$RELEASE_NAME" + - uses: actions/create-release@v1 + id: create_release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ steps.asset_paths.outputs.release_name }} + draft: true + prerelease: false + - uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ steps.asset_paths.outputs.linux_path }} + asset_name: ${{ steps.asset_paths.outputs.linux_name }} + asset_content_type: application/x-gtar + - uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ${{ steps.asset_paths.outputs.macos_path }} + asset_name: ${{ steps.asset_paths.outputs.macos_name }} + asset_content_type: application/x-gtar diff --git a/.github/workflows/deploy_conda.yml b/.github/workflows/deploy_conda.yml index 3d89edb9b..bbff48b6a 100644 --- a/.github/workflows/deploy_conda.yml +++ b/.github/workflows/deploy_conda.yml @@ -18,7 +18,7 @@ jobs: - name: Install deps on macos if: contains( matrix.os, 'macos') run: brew install coreutils || true - + - name: Install macOS SDK if: contains( matrix.os, 'macos') working-directory: /Users/runner diff --git a/scripts/pack_release.py b/scripts/pack_release.py new file mode 100755 index 000000000..a7f6416f8 --- /dev/null +++ b/scripts/pack_release.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +import os +import re +import sys +import subprocess +import configparser +import distutils.util + +if not os.path.isfile("scripts/pack_release.py"): + raise RuntimeError("Please run from top dir of repository") + +if len(sys.argv) != 2: + raise RuntimeError("Usage: scripts/pack_release.py install_dir") + +install_dir = sys.argv[1] +if not os.path.isdir(install_dir): + raise RuntimeError(f"Install directory {install_dir} does not exist") + +platform = distutils.util.get_platform().replace('.', '_').replace('-', '_') + +# Get current libtensorlight version +config = configparser.RawConfigParser() +config.read("setup.cfg") +ltl_version = config.get("bumpversion", "current_version") + +# Check if this points to a tag +git_revision = subprocess.check_output(["git", "rev-parse", "HEAD"], + universal_newlines=True).strip() +git_tag = subprocess.check_output(["git", "tag", "--points-at", git_revision], + universal_newlines=True).strip() +if not re.match("^v([0-9.]+)$", git_tag): + ltl_version = ltl_version + ".dev" + +filename = f"libtensorlight-{ltl_version}-{platform}.tar.gz" +subprocess.check_call(["tar", "-C", install_dir, "-czf", filename, "include", "lib"])