diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d623653..99cd895 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,6 +14,10 @@ # 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 +26,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 +35,282 @@ 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 }} + # - 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 + # build-release-nope: + # 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: + # fail-fast: false + # 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 + # steps: + # - name: Checkout repository + # uses: actions/checkout@v4 - - 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: Install packages (Ubuntu) + # # if: matrix.os == 'ubuntu-latest' + # # run: | + # # ci/ubuntu-install-packages - - name: Build release binary - run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} + # # - name: Install packages (macOS) + # # if: matrix.os == 'macos-latest' + # # run: | + # # ci/macos-install-packages - - name: Strip release binary (linux, macos and macos-arm) - if: matrix.build == 'linux' || matrix.os == 'macos' - run: strip "target/${{ matrix.target }}/release/sc" + # - name: Install Rust + # uses: dtolnay/rust-toolchain@master + # with: + # toolchain: ${{ matrix.rust }} + # target: ${{ matrix.target }} - - 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 + # - 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 + # env: + # GH_TOKEN: ${{ github.token }} + # run: gh release upload ${{ needs.create-release.outputs.smartcat_version }} ${{ env.ASSET }} ${{ env.ASSET_SUM }} + + crate-metadata: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Extract crate information 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 + cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT + cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT + outputs: + name: ${{ steps.crate-metadata.outputs.name }} + version: ${{ steps.crate-metadata.outputs.version }} + maintainer: ${{ steps.crate-metadata.outputs.maintainer }} + homepage: ${{ steps.crate-metadata.outputs.homepage }} + msrv: ${{ steps.crate-metadata.outputs.msrv }} + + build-release: + name: ${{ matrix.job.target }} (${{ matrix.job.os }}) + runs-on: ${{ matrix.job.os }} + needs: + - get-release + - crate-metadata + 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_OUTPUT + 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 }}