From b3112bb96d581f18dfe1044f9cae252865af3fca Mon Sep 17 00:00:00 2001 From: Thierry Marianne Date: Thu, 1 Jul 2021 19:09:15 +0200 Subject: [PATCH] Add scripts to build and publish windows archive containing newly compiled binary on tag push Replace rpm and deb packaging with statically compiled build Revise step name Install make package Revise windows and linux builds Restore action responsible for building linux binary Install gcc-mingw-w64-x86-64 package required to build windows binary Remove jemalloc feature when building windows binary Add _amd64 suffix to linux binary --- .github/workflows/release.yml | 70 ++++++++++++++----- contrib/deb/build.sh | 8 --- contrib/github-actions/build-linux-binary.sh | 12 ++++ .../github-actions/build-linux-packages.sh | 25 ------- .../github-actions/build-windows-package.sh | 13 ++++ ...ux-packages.sh => release-linux-binary.sh} | 10 +-- .../github-actions/release-windows-package.sh | 54 ++++++++++++++ contrib/rpm/build.sh | 18 ----- 8 files changed, 135 insertions(+), 75 deletions(-) delete mode 100644 contrib/deb/build.sh create mode 100644 contrib/github-actions/build-linux-binary.sh delete mode 100644 contrib/github-actions/build-linux-packages.sh create mode 100644 contrib/github-actions/build-windows-package.sh rename contrib/github-actions/{release-linux-packages.sh => release-linux-binary.sh} (78%) create mode 100644 contrib/github-actions/release-windows-package.sh delete mode 100644 contrib/rpm/build.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bde8194..430e9cc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,41 +30,37 @@ jobs: run: echo "RELEASE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV - name: Install packages - run: sudo apt-get install bash build-essential curl jq gcc git rpm rubygems + run: sudo apt-get install bash build-essential curl jq gcc git make musl-tools + + - name: Set up Ruby 2.6 + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + + - uses: actions/checkout@v2 - name: Install Rust toolchain uses: actions-rs/toolchain@v1 with: profile: complete toolchain: stable + target: x86_64-unknown-linux-musl - name: Set up rust cache uses: Swatinem/rust-cache@v1 - - name: Set up Ruby 2.6 - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.6 - - - name: Install fpm - run: gem install --no-document fpm - - - uses: actions/checkout@v2 - - name: Build binaries - run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/build-linux-packages.sh" + run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/build-linux-binary.sh" env: - PKT_FAIL_DIRTY: 1 RELEASE_NAME: ${{ env.RELEASE_NAME }} - uses: actions/upload-artifact@main with: path: | - ${{ github.workspace }}/${{ env.RELEASE_NAME }}-linux-x86_64.rpm - ${{ github.workspace }}/${{ env.RELEASE_NAME }}-linux-amd64.deb + ${{ github.workspace }}/${{ env.RELEASE_NAME }} - name: Publish release - run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/release-linux-packages.sh" + run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/release-linux-binary.sh" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_NAME: ${{ env.RELEASE_NAME }} @@ -104,7 +100,6 @@ jobs: - name: Build binaries run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/build-macos-package.sh" env: - PKT_FAIL_DIRTY: 1 RELEASE_NAME: ${{ env.RELEASE_NAME }} - uses: actions/upload-artifact@main @@ -117,3 +112,44 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} RELEASE_NAME: ${{ env.RELEASE_NAME }} + + windows: + needs: release + + runs-on: ubuntu-latest + + steps: + + - name: Set env + run: echo "RELEASE_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV + + - name: Install packages + run: sudo apt-get install bash build-essential curl jq gcc gcc-mingw-w64-x86-64 git make zip + + - name: Install Rust toolchain + uses: actions-rs/toolchain@v1 + with: + profile: complete + toolchain: stable + target: x86_64-pc-windows-gnu + + - name: Set up rust cache + uses: Swatinem/rust-cache@v1 + + - uses: actions/checkout@v2 + + - name: Build binaries + run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/build-windows-package.sh" + env: + RELEASE_NAME: ${{ env.RELEASE_NAME }} + + - uses: actions/upload-artifact@main + with: + path: | + ${{ github.workspace }}/${{ env.RELEASE_NAME }}-win.zip + + - name: Publish release + run: /bin/bash -c "source $GITHUB_WORKSPACE/contrib/github-actions/release-windows-package.sh" + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RELEASE_NAME: ${{ env.RELEASE_NAME }} \ No newline at end of file diff --git a/contrib/deb/build.sh b/contrib/deb/build.sh deleted file mode 100644 index c325549..0000000 --- a/contrib/deb/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash - -# -# This script should be run from the project root -# e.g. ./contrib/deb/build.sh -# -set -e -fpm -n packetcrypt-linux -s dir -t deb -v "$(./target/release/packetcrypt --version | sed -E 's/packetcrypt //' | tr -d '\n')" ./bin \ No newline at end of file diff --git a/contrib/github-actions/build-linux-binary.sh b/contrib/github-actions/build-linux-binary.sh new file mode 100644 index 0000000..e38d0b7 --- /dev/null +++ b/contrib/github-actions/build-linux-binary.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +function build() { + cd "${GITHUB_WORKSPACE}" || exit + cargo build --release --features jemalloc --target=x86_64-unknown-linux-musl + + mkdir "${GITHUB_WORKSPACE}/bin" + + cp "${GITHUB_WORKSPACE}/target/x86_64-unknown-linux-musl/release/packetcrypt" \ + "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}" +} +build diff --git a/contrib/github-actions/build-linux-packages.sh b/contrib/github-actions/build-linux-packages.sh deleted file mode 100644 index d77553c..0000000 --- a/contrib/github-actions/build-linux-packages.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/bin/bash - -function build() { - cd "${GITHUB_WORKSPACE}" || exit - cargo build --release --features jemalloc - - mkdir "${GITHUB_WORKSPACE}/bin" - cp "${GITHUB_WORKSPACE}/target/release/packetcrypt" "${GITHUB_WORKSPACE}/bin" - - local VERSION - VERSION=$(echo "${RELEASE_NAME}" | sed -E 's/.+v//') - - cd "${GITHUB_WORKSPACE}" || exit - bash -x ./contrib/deb/build.sh - - mv -v "${GITHUB_WORKSPACE}"'/packetcrypt-linux_'"${VERSION}"'_amd64.deb' \ - "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-linux-amd64.deb' - - cd "${GITHUB_WORKSPACE}" || exit - bash -x ./contrib/rpm/build.sh - - mv -v "${GITHUB_WORKSPACE}"'/packetcrypt-linux-'"${VERSION}"'-1.x86_64.rpm' \ - "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-linux-x86_64.rpm' -} -build \ No newline at end of file diff --git a/contrib/github-actions/build-windows-package.sh b/contrib/github-actions/build-windows-package.sh new file mode 100644 index 0000000..f03ba43 --- /dev/null +++ b/contrib/github-actions/build-windows-package.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +function build() { + cd "${GITHUB_WORKSPACE}" || exit + cargo build --release --target x86_64-pc-windows-gnu + + mkdir ./bin + + mv ./target/x86_64-pc-windows-gnu/release/packetcrypt.exe ./bin + + zip -r "./${RELEASE_NAME}-win.zip" ./bin +} +build \ No newline at end of file diff --git a/contrib/github-actions/release-linux-packages.sh b/contrib/github-actions/release-linux-binary.sh similarity index 78% rename from contrib/github-actions/release-linux-packages.sh rename to contrib/github-actions/release-linux-binary.sh index 5eac4f7..5a186cc 100644 --- a/contrib/github-actions/release-linux-packages.sh +++ b/contrib/github-actions/release-linux-binary.sh @@ -4,9 +4,6 @@ function publish() { local binary binary="${1}" - local extension - extension="${2}" - if [ ! -e "${binary}" ]; then echo 'Invalid binary ('"${binary}"')' @@ -42,15 +39,14 @@ function publish() { --data-binary @${binary} \ -H 'Content-Type: application/octet-stream' \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - "${upload_url}?name=${release_name}-linux${extension}" + "${upload_url}?name=${release_name}-linux_amd64" curl \ -X POST \ --data "$checksum" \ -H 'Content-Type: text/plain' \ -H "Authorization: Bearer ${GITHUB_TOKEN}" \ - "${upload_url}?name=${release_name}-linux${extension}.sha256sum" + "${upload_url}?name=${release_name}-linux_amd64.sha256sum" } -publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-linux-x86_64.rpm' '.rpm' -publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-linux-amd64.deb' '.deb' \ No newline at end of file +publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}" diff --git a/contrib/github-actions/release-windows-package.sh b/contrib/github-actions/release-windows-package.sh new file mode 100644 index 0000000..28b3efc --- /dev/null +++ b/contrib/github-actions/release-windows-package.sh @@ -0,0 +1,54 @@ + +function publish() { + local archive + archive="${1}" + + local extension + extension="${2}" + + if [ ! -e "${archive}" ]; + then + echo 'Invalid archive ('"${archive}"')' + return 1 + fi + + local checksum + checksum="$(sha256sum "${archive}" | cut -d ' ' -f 1)" + + local base_url + base_url='https://api.github.com/repos/'"${GITHUB_REPOSITORY}" + + local upload_url + upload_url="$(curl \ + -H 'Content-Type: application/octet-stream' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${base_url}"/releases 2>> /dev/null | \ + jq -r '.[] | .upload_url' | \ + head -n1)" + + upload_url=${upload_url/\{?name,label\}/} + + local release_name + release_name="$(curl \ + -H 'Content-Type: application/octet-stream' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${base_url}"/releases 2>> /dev/null | \ + jq -r '.[] | .tag_name' | \ + head -n1)" + + curl \ + -X POST \ + --data-binary @${archive} \ + -H 'Content-Type: application/octet-stream' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${upload_url}?name=${release_name}-windows${extension}" + + curl \ + -X POST \ + --data "$checksum" \ + -H 'Content-Type: text/plain' \ + -H "Authorization: Bearer ${GITHUB_TOKEN}" \ + "${upload_url}?name=${release_name}-windows${extension}.sha256sum" +} + +publish "${GITHUB_WORKSPACE}"'/'"${RELEASE_NAME}"'-win.zip' '.zip' \ No newline at end of file diff --git a/contrib/rpm/build.sh b/contrib/rpm/build.sh deleted file mode 100644 index 9c10b04..0000000 --- a/contrib/rpm/build.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash - -# -# This script should be run from the project root -# e.g. ./contrib/rpm/build.sh -# -if which fpm; then - if which rpmbuild; then - fpm -n packetcrypt-linux -s dir -t rpm -v "$(./target/release/packetcrypt --version | sed -E 's/packetcrypt //' | tr -d '\n')" ./bin - echo "RPM file built." - else - echo "rpmbuild not installed or not reachable" - exit 1 - fi -else - echo "fpm not installed or not reachable" - exit 1 -fi