From 3495597e955eeca54f50aec6d98556cdc87c16a3 Mon Sep 17 00:00:00 2001 From: "nieznany.sprawiciel" Date: Fri, 22 Mar 2024 15:04:35 +0100 Subject: [PATCH] github actions for building releases --- .ci/pack-build.sh | 61 ++++++++++++++++++++++++++++++++ .github/workflows/release.yml | 66 +++++++++++++++++++++++++++++++++++ .github/workflows/rust.yml | 2 +- 3 files changed, 128 insertions(+), 1 deletion(-) create mode 100644 .ci/pack-build.sh create mode 100644 .github/workflows/release.yml diff --git a/.ci/pack-build.sh b/.ci/pack-build.sh new file mode 100644 index 0000000..8c555cd --- /dev/null +++ b/.ci/pack-build.sh @@ -0,0 +1,61 @@ + +fail() { + printf "%s\n" "$1" >&2 + exit 1 +} + +not_empty() { + test -z "$1" && fail "expected $2" +} + + +not_empty "$GITHUB_REF" GITHUB_REF +not_empty "$OS_NAME" OS_NAME + + +if [ "$OS_NAME" = "ubuntu" ]; then + OS_NAME=linux + exe="" +elif [ "$OS_NAME" == "linux-aarch64" ]; then + OS_NAME=linux_aarch64 + exe="" +elif [ "$OS_NAME" == "macos" ]; then + OS_NAME=osx +elif [ "$OS_NAME" == "windows" ]; then + exe=".exe" +else + fail "unknown os name: $OS_NAME" +fi + +TAG_NAME="${GITHUB_REF##*/}" + +generate_asset() { + local asset_type=$1 + local bins="$2" + local non_exe="$3" + local TARGET_DIR=releases/${asset_type}-${OS_NAME}-${TAG_NAME} + mkdir -p "$TARGET_DIR" + for component in $bins; do + strip -x target/release/${component}${exe} + done + for bin in $bins; do + cp "target/release/${bin}${exe}" "$TARGET_DIR/" + done + if test -n "$non_exe"; then + for bin in $non_exe; do + cp "target/release/${bin}" "$TARGET_DIR/" + done + fi + if [ "$OS_NAME" = "windows" ]; then + echo "::set-output name=${asset_type}Artifact::${asset_type}-${OS_NAME}-${TAG_NAME}.zip" + echo "::set-output name=${asset_type}Media::application/zip" + (cd "$TARGET_DIR" && 7z a "../${asset_type}-${OS_NAME}-${TAG_NAME}.zip" * ) + else + echo "::set-output name=${asset_type}Artifact::${asset_type}-${OS_NAME}-${TAG_NAME}.tar.gz" + echo "::set-output name=${asset_type}Media::application/tar+gzip" + (cd releases && tar czf "${asset_type}-${OS_NAME}-${TAG_NAME}.tar.gz" "${asset_type}-${OS_NAME}-${TAG_NAME}") + du -h "releases/${asset_type}-${OS_NAME}-${TAG_NAME}.tar.gz" + fi +} + +generate_asset "golem-certificate-cli" "golem-certificate-cli" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..999c152 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,66 @@ +name: Build Release + +on: + push: + tags: + - v* + - pre-rel-* +env: + CARGO_TERM_COLOR: always + rust_stable: 1.76.0 + +jobs: + release: + name: CI + runs-on: ${{ matrix.os }}-latest + if: startsWith(github.ref, 'refs/tags/') + strategy: + fail-fast: true + matrix: + os: + - ubuntu + - windows + - macos + + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + with: + toolchain: ${{ env.rust_stable }} + components: clippy, rustfmt + + - uses: Swatinem/rust-cache@v2 + - run: cargo tree --locked + + - name: Install smartcard libraries ( Linux only ) + if: runner.os == 'Linux' + run: | + sudo apt install -y libpcsclite-dev + + - name: Build + if: runner.os != 'Linux' + run: cargo build --workspace --release + + - name: Build cli with smartcard ( Linux only ) + if: runner.os == 'Linux' + uses: actions-rs/cargo@v1 + with: + command: build + args: -p golem-certificate-cli --features smartcard + + - name: Pack + id: pack + shell: bash + env: + OS_NAME: ${{ matrix.os }} + GITHUB_REF: ${{ github.ref }} + run: | + bash .ci/pack-build.sh + + - name: Release + uses: softprops/action-gh-release@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + files: | + releases/golem-certificate-cli-* + prerelease: ${{ startsWith(github.ref, 'refs/tags/pre-rel-v') }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 1415647..6b5fbfd 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -9,7 +9,7 @@ on: - main env: - rust_stable: 1.68.2 + rust_stable: 1.76.0 jobs: build: