fork/numbat
git clone https://git.julia.blue/fork/numbat
794da79
master
1name : CICD 2 3env : 4CICD_INTERMEDIATES_DIR : "_cicd-intermediates" 5MSRV_FEATURES : "" 6 7on : 8workflow_dispatch : 9pull_request : 10push : 11branches : 12- master 13tags : 14- '*' 15 16jobs : 17crate_metadata : 18name : Extract crate metadata 19runs-on : ubuntu-latest 20steps : 21- uses : actions/checkout@v4 22- name : Extract crate information 23id : crate_metadata 24run : | 25cargo metadata --no-deps --format-version 1 | jq -r '"name=" + .packages[0].name' | tee -a $GITHUB_OUTPUT 26cargo metadata --no-deps --format-version 1 | jq -r '"version=" + .packages[0].version' | tee -a $GITHUB_OUTPUT 27cargo metadata --no-deps --format-version 1 | jq -r '"maintainer=" + .packages[0].authors[0]' | tee -a $GITHUB_OUTPUT 28cargo metadata --no-deps --format-version 1 | jq -r '"homepage=" + .packages[0].homepage' | tee -a $GITHUB_OUTPUT 29cargo metadata --no-deps --format-version 1 | jq -r '"msrv=" + .packages[0].rust_version' | tee -a $GITHUB_OUTPUT 30outputs : 31name : ${{ steps.crate_metadata.outputs.name }} 32version : ${{ steps.crate_metadata.outputs.version }} 33maintainer : ${{ steps.crate_metadata.outputs.maintainer }} 34homepage : ${{ steps.crate_metadata.outputs.homepage }} 35msrv : ${{ steps.crate_metadata.outputs.msrv }} 36 37ensure_cargo_fmt : 38name : Ensure 'cargo fmt' has been run 39runs-on : ubuntu-20.04 40steps : 41- uses : dtolnay/rust-toolchain@stable 42with : 43components : rustfmt 44- uses : actions/checkout@v4 45- run : cargo fmt -- --check 46 47documentation_checks : 48name : Documentation checks 49runs-on : ubuntu-20.04 50steps : 51- uses : dtolnay/rust-toolchain@stable 52- uses : actions/checkout@v3 53- name : Install mdbook 54run : | 55cargo install mdbook 56cargo install mdbook-linkcheck 57- name : Build documentation 58run : | 59cd book 60bash build.sh 61if [ -n "$(git status --porcelain)" ]; then 62echo "Documentation not up to date." 63echo "Make sure to run 'build.sh' in the book/ folder" 64exit 1 65fi 66 67wasm : 68name : WASM version 69runs-on : ubuntu-20.04 70steps : 71- uses : dtolnay/rust-toolchain@stable 72- uses : actions/checkout@v3 73- name : Install wasm-pack 74run : | 75curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh 76- name : Build WASM version 77run : | 78cd numbat-wasm 79bash build.sh 80- name : Test WASM version 81run : | 82cd numbat-wasm 83bash test.sh 84 85min_version : 86name : Minimum supported rust version 87runs-on : ubuntu-20.04 88needs : crate_metadata 89steps : 90- name : Checkout source code 91uses : actions/checkout@v4 92 93- name : Install rust toolchain (v${{ needs.crate_metadata.outputs.msrv }}) 94uses : dtolnay/rust-toolchain@master 95with : 96toolchain : ${{ needs.crate_metadata.outputs.msrv }} 97components : clippy 98- name : Run clippy (on minimum supported rust version to prevent warnings we can't fix) 99run : cargo clippy --locked --all-targets ${{ env.MSRV_FEATURES }} 100- name : Run tests 101run : cargo test --locked ${{ env.MSRV_FEATURES }} 102 103build : 104name : ${{ matrix.job.target }} (${{ matrix.job.os }}) 105runs-on : ${{ matrix.job.os }} 106needs : crate_metadata 107strategy : 108fail-fast : false 109matrix : 110job : 111- { target : aarch64-unknown-linux-gnu , os : ubuntu-20.04 , use-cross : true } 112- { target : arm-unknown-linux-gnueabihf , os : ubuntu-20.04 , use-cross : true } 113- { target : arm-unknown-linux-musleabihf , os : ubuntu-20.04 , use-cross : true } 114- { target : i686-pc-windows-msvc , os : windows-2019 } 115- { target : i686-unknown-linux-gnu , os : ubuntu-20.04 , use-cross : true } 116- { target : i686-unknown-linux-musl , os : ubuntu-20.04 , use-cross : true } 117- { target : x86_64-apple-darwin , os : macos-12 } 118#- { target: x86_64-pc-windows-gnu , os: windows-2019 } 119- { target : x86_64-pc-windows-msvc , os : windows-2019 } 120- { target : x86_64-unknown-linux-gnu , os : ubuntu-20.04 , use-cross : true } 121- { target : x86_64-unknown-linux-musl , os : ubuntu-20.04 , use-cross : true } 122env : 123BUILD_CMD : cargo 124steps : 125- name : Checkout source code 126uses : actions/checkout@v4 127 128- name : Install prerequisites 129shell : bash 130run : | 131case ${{ matrix.job.target }} in 132arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; 133aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; 134esac 135 136- name : Install Rust toolchain 137uses : dtolnay/rust-toolchain@stable 138with : 139targets : ${{ matrix.job.target }} 140 141- name : Install cross 142if : matrix.job.use-cross 143uses : taiki-e/install-action@v2 144with : 145tool : cross 146 147- name : Overwrite build command env variable 148if : matrix.job.use-cross 149shell : bash 150run : echo "BUILD_CMD=cross" >> $GITHUB_ENV 151 152- name : Show version information (Rust, cargo, GCC) 153shell : bash 154run : | 155gcc --version || true 156rustup -V 157rustup toolchain list 158rustup default 159cargo -V 160rustc -V 161 162- name : Build 163shell : bash 164run : $BUILD_CMD build --locked --release --target=${{ matrix.job.target }} 165 166- name : Set binary name & path 167id : bin 168shell : bash 169run : | 170# Figure out suffix of binary 171EXE_suffix="" 172case ${{ matrix.job.target }} in 173*-pc-windows-*) EXE_suffix=".exe" ;; 174esac; 175 176# Setup paths 177BIN_NAME="${{ needs.crate_metadata.outputs.name }}${EXE_suffix}" 178BIN_PATH="target/${{ matrix.job.target }}/release/${BIN_NAME}" 179 180# Let subsequent steps know where to find the binary 181echo "BIN_PATH=${BIN_PATH}" >> $GITHUB_OUTPUT 182echo "BIN_NAME=${BIN_NAME}" >> $GITHUB_OUTPUT 183 184- name : Set testing options 185id : test-options 186shell : bash 187run : | 188# test only library unit tests and binary for arm-type targets 189unset CARGO_TEST_OPTIONS 190unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${{ needs.crate_metadata.outputs.name }}" ;; esac; 191echo "CARGO_TEST_OPTIONS=${CARGO_TEST_OPTIONS}" >> $GITHUB_OUTPUT 192 193- name : Run tests 194shell : bash 195run : $BUILD_CMD test --locked --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} 196 197- name : Create tarball 198id : package 199shell : bash 200run : | 201PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac; 202PKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-v${{ needs.crate_metadata.outputs.version }}-${{ matrix.job.target }} 203PKG_NAME=${PKG_BASENAME}${PKG_suffix} 204echo "PKG_NAME=${PKG_NAME}" >> $GITHUB_OUTPUT 205 206PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" 207ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" 208mkdir -p "${ARCHIVE_DIR}" 209 210# Binary 211cp "${{ steps.bin.outputs.BIN_PATH }}" "$ARCHIVE_DIR" 212 213# README and LICENSE files 214cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "$ARCHIVE_DIR" 215 216# Desktop file and icons 217mkdir "$ARCHIVE_DIR/assets" 218cp "assets/numbat.desktop" assets/numbat-*x*.png "assets/numbat.svg" "$ARCHIVE_DIR/assets" 219 220# Numbat prelude 221cp -r numbat/modules "$ARCHIVE_DIR" 222 223# base compressed package 224pushd "${PKG_STAGING}/" >/dev/null 225case ${{ matrix.job.target }} in 226*-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;; 227*) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;; 228esac; 229popd >/dev/null 230 231# Let subsequent steps know where to find the compressed package 232echo "PKG_PATH=${PKG_STAGING}/${PKG_NAME}" >> $GITHUB_OUTPUT 233 234- name : Create Debian package 235id : debian-package 236shell : bash 237if : startsWith(matrix.job.os, 'ubuntu') 238run : | 239COPYRIGHT_YEARS="2022 - "$(date "+%Y") 240DPKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/debian-package" 241DPKG_DIR="${DPKG_STAGING}/dpkg" 242mkdir -p "${DPKG_DIR}" 243 244DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }} 245DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }}-musl 246case ${{ matrix.job.target }} in *-musl*) DPKG_BASENAME=${{ needs.crate_metadata.outputs.name }}-musl ; DPKG_CONFLICTS=${{ needs.crate_metadata.outputs.name }} ;; esac; 247DPKG_VERSION=${{ needs.crate_metadata.outputs.version }} 248 249unset DPKG_ARCH 250case ${{ matrix.job.target }} in 251aarch64-*-linux-*) DPKG_ARCH=arm64 ;; 252arm-*-linux-*hf) DPKG_ARCH=armhf ;; 253i686-*-linux-*) DPKG_ARCH=i686 ;; 254x86_64-*-linux-*) DPKG_ARCH=amd64 ;; 255*) DPKG_ARCH=notset ;; 256esac; 257 258DPKG_NAME="${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb" 259echo "DPKG_NAME=${DPKG_NAME}" >> $GITHUB_OUTPUT 260 261# Binary 262install -Dm755 "${{ steps.bin.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.bin.outputs.BIN_NAME }}" 263 264# README and LICENSE 265install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md" 266install -Dm644 "LICENSE-MIT" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/LICENSE-MIT" 267install -Dm644 "LICENSE-APACHE" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/LICENSE-APACHE" 268 269# Desktop file and icons 270install -Dm644 "assets/numbat.desktop" "${DPKG_DIR}/usr/share/applications/numbat.desktop" 271install -Dm644 "assets/numbat.svg" "${DPKG_DIR}/usr/share/icons/hicolor/scalable/apps/numbat.svg" 272 273for s in 16 22 24 32 48 64 128 256 512; do 274install -Dm644 "assets/numbat-${s}x${s}.png" "${DPKG_DIR}/usr/share/icons/hicolor/${s}x${s}/apps/numbat.png" 275done 276 277# Numbat prelude 278mkdir -p "${DPKG_DIR}/usr/share/${DPKG_BASENAME}" 279cp -r numbat/modules "${DPKG_DIR}/usr/share/${DPKG_BASENAME}" 280 281cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" <<EOF 282Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ 283Upstream-Name: ${{ needs.crate_metadata.outputs.name }} 284Source: ${{ needs.crate_metadata.outputs.homepage }} 285 286Files: * 287Copyright: ${{ needs.crate_metadata.outputs.maintainer }} 288Copyright: $COPYRIGHT_YEARS ${{ needs.crate_metadata.outputs.maintainer }} 289License: Apache-2.0 or MIT 290 291License: Apache-2.0 292On Debian systems, the complete text of the Apache-2.0 can be found in the 293file /usr/share/common-licenses/Apache-2.0. 294 295License: MIT 296Permission is hereby granted, free of charge, to any 297person obtaining a copy of this software and associated 298documentation files (the "Software"), to deal in the 299Software without restriction, including without 300limitation the rights to use, copy, modify, merge, 301publish, distribute, sublicense, and/or sell copies of 302the Software, and to permit persons to whom the Software 303is furnished to do so, subject to the following 304conditions: 305. 306The above copyright notice and this permission notice 307shall be included in all copies or substantial portions 308of the Software. 309. 310THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF 311ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 312TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 313PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT 314SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 315CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 316OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR 317IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 318DEALINGS IN THE SOFTWARE. 319EOF 320chmod 644 "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" 321 322# control file 323mkdir -p "${DPKG_DIR}/DEBIAN" 324cat > "${DPKG_DIR}/DEBIAN/control" <<EOF 325Package: ${DPKG_BASENAME} 326Version: ${DPKG_VERSION} 327Section: utils 328Priority: optional 329Maintainer: ${{ needs.crate_metadata.outputs.maintainer }} 330Homepage: ${{ needs.crate_metadata.outputs.homepage }} 331Architecture: ${DPKG_ARCH} 332Provides: ${{ needs.crate_metadata.outputs.name }} 333Conflicts: ${DPKG_CONFLICTS} 334Description: Statically typed programming language for scientific computations with first class support for physical dimensions and units 335EOF 336 337DPKG_PATH="${DPKG_STAGING}/${DPKG_NAME}" 338echo "DPKG_PATH=${DPKG_PATH}" >> $GITHUB_OUTPUT 339 340# build dpkg 341fakeroot dpkg-deb --build "${DPKG_DIR}" "${DPKG_PATH}" 342 343- name : "Artifact upload: tarball" 344uses : actions/upload-artifact@master 345with : 346name : ${{ steps.package.outputs.PKG_NAME }} 347path : ${{ steps.package.outputs.PKG_PATH }} 348 349- name : "Artifact upload: Debian package" 350uses : actions/upload-artifact@master 351if : steps.debian-package.outputs.DPKG_NAME 352with : 353name : ${{ steps.debian-package.outputs.DPKG_NAME }} 354path : ${{ steps.debian-package.outputs.DPKG_PATH }} 355 356- name : Check for release 357id : is-release 358shell : bash 359run : | 360unset IS_RELEASE ; if [[ $GITHUB_REF =~ ^refs/tags/v[0-9].* ]]; then IS_RELEASE='true' ; fi 361echo "IS_RELEASE=${IS_RELEASE}" >> $GITHUB_OUTPUT 362 363- name : Publish archives and packages 364uses : softprops/action-gh-release@v1 365if : steps.is-release.outputs.IS_RELEASE 366with : 367files : | 368${{ steps.package.outputs.PKG_PATH }} 369${{ steps.debian-package.outputs.DPKG_PATH }} 370env : 371GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}