From b77f92b61ee46deecedf635cd49d260a4bc9f5c1 Mon Sep 17 00:00:00 2001 From: Felix Van der Jeugt Date: Tue, 13 Jul 2021 17:14:14 +0200 Subject: [PATCH] add github release workflow --- .github/workflows/release.yml | 163 ++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..97bedf9 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,163 @@ +# The MIT License (MIT) +# +# Copyright (c) 2016 Jinzhou Zhang +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in all +# copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +# SOFTWARE. + +# workflow copied from https://github.com/lotabout/skim and modified +name: Publish to Github + +on: + push: + tags: + - 'v[0-9]+.[0-9]+.[0-9]+' + +jobs: + create-release: + name: Create Github Release + runs-on: ubuntu-latest + steps: + - name: Create artifacts directory + run: mkdir artifacts + - name: Get the release version from the tag + run: | + # Apparently, this is the right way to get a tag name. Really? + # + # See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 + echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV + - name: Create Release + id: release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ env.RELEASE_VERSION }} + body: ${{ env.RELEASE_VERSION }} + draft: false + prerelease: false + - name: Save release upload URL to artifact + run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url + - name: Save version number to artifact + run: echo "${{ env.RELEASE_VERSION }}" > artifacts/release-version + - name: Upload artifacts + uses: actions/upload-artifact@v1 + with: + name: artifacts + path: artifacts + + publish-to-github: + name: Publish to Github + needs: ['create-release'] + runs-on: ${{matrix.os}} + strategy: + matrix: + build: [linux, arm, arm-v7, macos] + include: + - build: linux + os: ubuntu-latest + rust: stable + target: x86_64-unknown-linux-musl + cross: false + - build: arm + os: ubuntu-latest + rust: stable + target: arm-unknown-linux-gnueabihf + cross: true + - build: arm-v7 + os: ubuntu-latest + rust: stable + target: armv7-unknown-linux-gnueabihf + cross: true + - build: macos + os: macos-latest + rust: stable + target: x86_64-apple-darwin + cross: false + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + fetch-depth: 1 + - name: Install correct toolchain + uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ matrix.rust }} + target: ${{ matrix.target }} + use-cross: ${{ matrix.cross }} + override: true + + - name: Get release download URL + uses: actions/download-artifact@v1 + with: + name: artifacts + path: artifacts + - name: Set release upload URL and release version + shell: bash + run: | + release_upload_url="$(cat artifacts/release-upload-url)" + echo "RELEASE_UPLOAD_URL=$release_upload_url" >> $GITHUB_ENV + echo "release upload url: $RELEASE_UPLOAD_URL" + release_version="$(cat artifacts/release-version)" + echo "RELEASE_VERSION=$release_version" >> $GITHUB_ENV + echo "release version: $RELEASE_VERSION" + + - name: build + uses: actions-rs/cargo@v1 + with: + use-cross: ${{ matrix.cross }} + command: build + args: --release --target ${{ matrix.target }} + - name: Package Artifacts + run: | + src=$(pwd) + stage= + + case $RUNNER_OS in + Linux) + stage=$(mktemp -d) + ;; + macOS) + stage=$(mktemp -d -t tmp) + ;; + esac + + echo "src is: $src" + echo "stage is: $stage" + + cp target/${{ matrix.target }}/release/FragGeneScanRs $stage/ + cd $stage + + ASSET_NAME="FragGeneScanRs-${{ env.RELEASE_VERSION }}-${{ matrix.target }}.tar.gz" + ASSET_PATH="$src/$ASSET_NAME" + echo "ASSET_NAME=$ASSET_NAME" >> $GITHUB_ENV + echo "ASSET_PATH=$ASSET_PATH" >> $GITHUB_ENV + + tar czf $ASSET_PATH * + + cd $src + - name: Upload release archive + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ env.RELEASE_UPLOAD_URL }} + asset_path: ${{ env.ASSET_PATH }} + asset_name: ${{ env.ASSET_NAME }} + asset_content_type: application/octet-stream \ No newline at end of file