From 0e8eefd1866e41b2dd7b24a34f811c88081120b8 Mon Sep 17 00:00:00 2001 From: efugier Date: Sat, 11 Nov 2023 17:39:49 +0100 Subject: [PATCH] feat(release_ci): get inspiration from bat --- .github/workflows/release.yml | 264 +++++++++++++++++----------------- README.md | 8 +- 2 files changed, 134 insertions(+), 138 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d623653..221c3d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,19 +1,17 @@ # The way this works is the following: # -# The create-release job runs purely to initialize the GitHub release itself -# and to output upload_url for the following job. +# The get-release job fetches the upload_url for the following job. # # The build-release job runs only once create-release is finished. It gets the # release upload URL from create-release job outputs, then builds the release # executables for each supported platform and attaches them as release assets # to the previously created release. -# -# The key here is that we create the release only once. -# -# Reference: -# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/ name: Release +env: + CICD_INTERMEDIATES_DIR: "_cicd-intermediates" + MSRV_FEATURES: --no-default-features --features minimal-application,bugreport,build-assets + on: push: # Enable when testing release infrastructure on a branch. @@ -22,8 +20,8 @@ on: tags: - "[0-9]+.[0-9]+.[0-9]+" jobs: - create-release: - name: create-release + get-release: + name: get-release runs-on: ubuntu-latest # env: # # Set to force version number, e.g., when no tag exists. @@ -31,136 +29,136 @@ jobs: outputs: smartcat_version: ${{ env.SMARTCAT_VERSION }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get the release version from the tag shell: bash if: env.SMARTCAT_VERSION == '' run: | echo "SMARTCAT_VERSION=$GITHUB_REF_NAME" >> $GITHUB_ENV echo "version is: ${{ env.SMARTCAT_VERSION }}" - - name: Create GitHub release - env: - GH_TOKEN: ${{ github.token }} - run: gh release create ${{ env.SMARTCAT_VERSION }} build-release: - name: build-release - needs: ['create-release'] - runs-on: ${{ matrix.os }} - env: - # For some builds, we use cross to test on 32-bit and big-endian - # systems. - CARGO: cargo - # When CARGO is set to CROSS, this is set to `--target matrix.target`. - TARGET_FLAGS: "" - # When CARGO is set to CROSS, TARGET_DIR includes matrix.target. - TARGET_DIR: ./target - # Emit backtraces on panics. - RUST_BACKTRACE: 1 - strategy: - matrix: - build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc] - include: - - build: linux - os: ubuntu-latest - rust: stable - target: x86_64-unknown-linux-musl - - build: linux-arm - os: ubuntu-latest - rust: stable - target: arm-unknown-linux-gnueabihf - - build: macos - os: macos-latest - rust: stable - target: x86_64-apple-darwin - - build: win-msvc - os: windows-latest - rust: stable - target: x86_64-pc-windows-msvc - - build: win-gnu - os: windows-latest - rust: stable-x86_64-gnu - target: x86_64-pc-windows-gnu - - build: win32-msvc - os: windows-latest - rust: stable - target: i686-pc-windows-msvc - - steps: - - name: Checkout repository - uses: actions/checkout@v3 - - # - name: Install packages (Ubuntu) - # if: matrix.os == 'ubuntu-latest' - # run: | - # ci/ubuntu-install-packages - - # - name: Install packages (macOS) - # if: matrix.os == 'macos-latest' - # run: | - # ci/macos-install-packages - - - name: Install Rust - uses: dtolnay/rust-toolchain@master - with: - toolchain: ${{ matrix.rust }} - target: ${{ matrix.target }} - - - name: Use Cross - shell: bash - run: | - cargo install cross - echo "CARGO=cross" >> $GITHUB_ENV - echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV - echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV - - - name: Show command used for Cargo - run: | - echo "cargo command is: ${{ env.CARGO }}" - echo "target flag is: ${{ env.TARGET_FLAGS }}" - echo "target dir is: ${{ env.TARGET_DIR }}" - - - name: Build release binary - run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} - - - name: Strip release binary (linux, macos and macos-arm) - if: matrix.build == 'linux' || matrix.os == 'macos' - run: strip "target/${{ matrix.target }}/release/sc" - - - name: Strip release binary (arm) - if: matrix.build == 'linux-arm' - run: | - docker run --rm -v \ - "$PWD/target:/target:Z" \ - rustembedded/cross:arm-unknown-linux-gnueabihf \ - arm-linux-gnueabihf-strip \ - /target/arm-unknown-linux-gnueabihf/release/sc - - - name: Build archive - shell: bash - run: | - staging="smartcat-${{ needs.create-release.outputs.smartcat_version }}-${{ matrix.target }}" - mkdir -p "$staging"/ - - cp {README.md,LICENSE} "$staging/" - # cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/" - - if [ "${{ matrix.os }}" = "windows-latest" ]; then - cp "target/${{ matrix.target }}/release/sc.exe" "$staging/" - 7z a "$staging.zip" "$staging" - certutil -hashfile "$staging.zip" SHA256 > "$staging.zip.sha256" - echo "ASSET=$staging.zip" >> $GITHUB_ENV - echo "ASSET_SUM=$staging.zip.sha256" >> $GITHUB_ENV - else - # The man page is only generated on Unix systems. ¯\_(ツ)_/¯ - cp "target/${{ matrix.target }}/release/sc" "$staging/" - tar czf "$staging.tar.gz" "$staging" - shasum -a 256 "$staging.tar.gz" > "$staging.tar.gz.sha256" - echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV - echo "ASSET_SUM=$staging.tar.gz.sha256" >> $GITHUB_ENV - fi - - - name: Upload release archive + name: ${{ matrix.job.target }} (${{ matrix.job.os }}) + runs-on: ${{ matrix.job.os }} + needs: + - get-release + strategy: + fail-fast: false + matrix: + job: + - { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } + - { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04, use-cross: true } + - { target: arm-unknown-linux-musleabihf, os: ubuntu-20.04, use-cross: true } + - { target: i686-pc-windows-msvc , os: windows-2019 } + - { target: i686-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } + - { target: i686-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } + - { target: x86_64-apple-darwin , os: macos-12 } + - { target: x86_64-pc-windows-gnu , os: windows-2019 } + - { target: x86_64-pc-windows-msvc , os: windows-2019 } + - { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04, use-cross: true } + - { target: x86_64-unknown-linux-musl , os: ubuntu-20.04, use-cross: true } env: - GH_TOKEN: ${{ github.token }} - run: gh release upload ${{ needs.create-release.outputs.smartcat_version }} ${{ env.ASSET }} ${{ env.ASSET_SUM }} + BUILD_CMD: cargo + steps: + - name: Checkout source code + uses: actions/checkout@v4 + + - name: Install prerequisites + shell: bash + run: | + case ${{ matrix.job.target }} in + arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; + aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; + esac + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.job.target }} + + - name: Install cross + if: matrix.job.use-cross + uses: taiki-e/install-action@v2 + with: + tool: cross + + - name: Overwrite build command env variable + if: matrix.job.use-cross + shell: bash + run: echo "BUILD_CMD=cross" >> $GITHUB_ENV + + - name: Show version information (Rust, cargo, GCC) + shell: bash + run: | + gcc --version || true + rustup -V + rustup toolchain list + rustup default + cargo -V + rustc -V + + - name: Build + shell: bash + run: $BUILD_CMD build --release --target=${{ matrix.job.target }} + + - name: Set binary name & path + id: bin + shell: bash + run: | + # Figure out suffix of binary + EXE_SUFFIX="" + case ${{ matrix.job.target }} in + *-pc-windows-*) EXE_SUFFIX=".exe" ;; + esac; + + # Setup paths + BIN_NAME="sc${EXE_SUFFIX}" + BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}" + + # Let subsequent steps know where to find the binary + echo "BIN_PATH=${BIN_PATH}" | tee -a $GITHUB_OUTPUT + echo "BIN_NAME=${BIN_NAME}" | tee -a $GITHUB_OUTPUT + + - name: Build archive + id: package + shell: bash + run: | + PKG_SUFFIX=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_SUFFIX=".zip" ;; esac; + PKG_BASENAME="sc-${{ needs.crate-metadata.outputs.version }}-${{ matrix.job.target }}" + PKG_NAME=${PKG_BASENAME}${PKG_SUFFIX} + echo "PKG_NAME=${PKG_NAME}" | tee -a $GITHUB_OUTPUT + + PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" + ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" + mkdir -p "${ARCHIVE_DIR}" + + # Binary + cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR" + + # README, LICENSE and CHANGELOG files + cp "README.md" "LICENSE" "$ARCHIVE_DIR" + + # base compressed package + pushd "${PKG_STAGING}/" >/dev/null + case ${{ matrix.job.target }} in + *-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;; + *) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;; + esac; + popd >/dev/null + + # sha + pushd "${PKG_STAGING}/" >/dev/null + case ${{ matrix.job.target }} in + *-pc-windows-*) certutil -hashfile "${PKG_NAME}" SHA256 > "${PKG_NAME}.sha256" ;; + *) shasum -a 256 "${PKG_NAME}" > "${PKG_NAME}.sha256" ;; + esac; + popd >/dev/null + + # Let subsequent steps know where to find the compressed package + echo "ASSET_PATH=${PKG_STAGING}/${PKG_NAME}" | tee -a $GITHUB_ENV + echo "ASSET_SUM=${PKG_STAGING}/${PKG_NAME}.sha256" | tee -a $GITHUB_ENV + + - name: Upload release archive + env: + GH_TOKEN: ${{ github.token }} + run: gh release upload ${{ needs.get-release.outputs.smartcat_version }} ${{ env.ASSET_PATH }} ${{ env.ASSET_SUM }} diff --git a/README.md b/README.md index 96ecb0f..ee94b75 100644 --- a/README.md +++ b/README.md @@ -42,12 +42,10 @@ Options: cargo install smartcat ``` -Optional: -``` -mv ~/.cargo/bin/smartcat ~/.cargo/bin/sc -``` +(the binary is named `sc`) + +Or download directly the binary compiled for your platform from the [release page](https://github.com/efugier/smartcat/releases). -where `~/.cargo/` is the cargo home, you can find it with `which smarcat` after installing it. On the first run, the program will ask you to generate some default configuration if it cannot find them. More about that in the [configuration section](#Configuration).