|
| 1 | +name: CICD |
| 2 | + |
| 3 | +# Copyright (C) 2020 ~ Roy Ivy III <rivy.dev@gmail.com>; MIT+Apache-2.0 license |
| 4 | + |
| 5 | +# spell-checker:ignore (abbrev/acronyms) ASAN CICD CodeCOV LLVM MSVC MacOS MinGW OSID TSAN UBSAN |
| 6 | +# spell-checker:ignore (env/flags) CFLAGS CXXFLAGS LDFLAGS Ccodegen Coverflow fsanitize |
| 7 | +# spell-checker:ignore (jargon) SHAs deps falsey softprops toolchain truthy |
| 8 | +# spell-checker:ignore (names) Bionic Bionic's Peltoche Xenial ilammy rivy |
| 9 | +# spell-checker:ignore (shell/tools) chmod choco clippy cmake ctest dmake dpkg esac fakeroot gmake grcov halium lcov libssl libtsan mkdir popd printf pushd rustc rustfmt rustup shopt valgrind xargs xcode |
| 10 | +# spell-checker:ignore (misc) alnum gnueabihf issuecomment libc libncurses maint multilib ncurses nullglob onexitbegin onexitend uutils |
| 11 | + |
| 12 | +# spell-checker:ignore () lessecho lesskey |
| 13 | + |
| 14 | +env: |
| 15 | + PROJECT_NAME: less |
| 16 | + PROJECT_DESC: "`less` is more" |
| 17 | + |
| 18 | +on: [push, pull_request] |
| 19 | + |
| 20 | +jobs: |
| 21 | + build: |
| 22 | + name: Build |
| 23 | + runs-on: ${{ matrix.job.os }} |
| 24 | + strategy: |
| 25 | + fail-fast: false |
| 26 | + matrix: |
| 27 | + job: |
| 28 | + - { os: ubuntu-latest, compiler: clang, arch: x32 } |
| 29 | + - { os: ubuntu-latest, compiler: clang, arch: x64 } |
| 30 | + - { os: ubuntu-latest, compiler: gcc, arch: x32 } |
| 31 | + - { os: ubuntu-latest, compiler: gcc, arch: x64 } |
| 32 | + - { os: ubuntu-latest, compiler: clang, arch: x32, static: static } |
| 33 | + - { os: ubuntu-latest, compiler: clang, arch: x64, static: static } |
| 34 | + - { os: ubuntu-latest, compiler: gcc, arch: x32, static: static } |
| 35 | + - { os: ubuntu-latest, compiler: gcc, arch: x64, static: static } |
| 36 | + # - { os: macos-latest, compiler: xcode, version: "11.3" } |
| 37 | + - { os: windows-latest, compiler: cl, arch: x32 } |
| 38 | + - { os: windows-latest, compiler: cl, arch: x64 } |
| 39 | + - { os: windows-latest, compiler: clang, arch: x32 } |
| 40 | + - { os: windows-latest, compiler: clang, arch: x64 } |
| 41 | + # - { os: windows-latest, compiler: gcc, arch: x32 } ## unavailable |
| 42 | + - { os: windows-latest, compiler: gcc, arch: x64 } |
| 43 | + - { os: windows-latest, compiler: cl, arch: x32, static: static } |
| 44 | + - { os: windows-latest, compiler: cl, arch: x64, static: static } |
| 45 | + - { os: windows-latest, compiler: clang, arch: x32, static: static } |
| 46 | + - { os: windows-latest, compiler: clang, arch: x64, static: static } |
| 47 | + # - { os: windows-latest, compiler: gcc, arch: x32, static: static } ## unavailable |
| 48 | + - { os: windows-latest, compiler: gcc, arch: x64, static: static } |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@v1 |
| 51 | + - name: Initialize workflow variables |
| 52 | + id: vars |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + ## VARs setup |
| 56 | + log() { for var in "$@" ; do echo ${var}="${!var}"; done; } |
| 57 | + outputs() { for var in "$@" ; do echo steps.vars.outputs.${var}="${!var}"; echo ::set-output name=${var}::${!var}; done; } |
| 58 | + # staging directory |
| 59 | + STAGING='_staging' |
| 60 | + outputs STAGING |
| 61 | + # normalize ARCH_ID |
| 62 | + case '${{ matrix.job.arch }}' in |
| 63 | + 32 | x32 | x86 | i686) ARCH_ID='x86' ; CONFIG_ARCH_ID='i686' ; CC_ARCH_ID='32' ;; |
| 64 | + 64 | x64 | x86_64) ARCH_ID='x64' ; CONFIG_ARCH_ID='x86_64' ; CC_ARCH_ID='64' ;; |
| 65 | + *) ARCH_ID='${{ matrix.job.arch }}' ;; |
| 66 | + esac; |
| 67 | + outputs ARCH_ID CONFIG_ARCH_ID CC_ARCH_ID |
| 68 | + # handle STATIC |
| 69 | + LDFLAGS_STATIC="$( if [ '${{ matrix.job.static }}' == 'static' ]; then echo '-static'; fi; )" |
| 70 | + outputs LDFLAGS_STATIC |
| 71 | + # determine EXE suffix |
| 72 | + EXE_suffix="$( case '${{ matrix.job.os }}' in windows-*) echo '.exe' ;; esac; )" |
| 73 | + outputs EXE_suffix |
| 74 | + # parse commit reference info |
| 75 | + log GITHUB_REF GITHUB_SHA |
| 76 | + REF_NAME=${GITHUB_REF#refs/*/} |
| 77 | + unset REF_BRANCH ; case "${GITHUB_REF}" in refs/heads/*) REF_BRANCH=${GITHUB_REF#refs/heads/} ;; esac; |
| 78 | + unset REF_TAG ; case "${GITHUB_REF}" in refs/tags/*) REF_TAG=${GITHUB_REF#refs/tags/} ;; esac; |
| 79 | + REF_SHAS=${GITHUB_SHA:0:8} |
| 80 | + outputs REF_NAME REF_BRANCH REF_TAG REF_SHAS |
| 81 | + # package name |
| 82 | + PKG_suffix=".tar.gz" ; case '${{ matrix.job.os }}' in windows-*) PKG_suffix=".zip" ;; esac; |
| 83 | + OS_name=$( echo "${{ matrix.job.os }}" | grep -Eo '^\s*([^-]+)' | tr '[:upper:]' '[:lower:]' ) |
| 84 | + PKG_OSID=${OS_name} |
| 85 | + case "${OS_name}" in macos) PKG_OSID=mac ;; ubuntu) PKG_OSID=nix ;; windows) PKG_OSID=win ;; esac; |
| 86 | + if [ '${{ matrix.job.static }}' == 'static' ]; then |
| 87 | + STATIC_suffix=".static" |
| 88 | + PKG_prefix="${PROJECT_NAME}-${REF_TAG:-$REF_SHAS}-${PKG_OSID}-${{ matrix.job.arch }}" |
| 89 | + else |
| 90 | + STATIC_suffix=".dyn" |
| 91 | + PKG_prefix="${PROJECT_NAME}-${REF_TAG:-$REF_SHAS}-${OS_name}-${{ matrix.job.arch }}" |
| 92 | + fi |
| 93 | + PKG_stem="${PKG_prefix}${STATIC_suffix}.(${{ matrix.job.compiler }})" |
| 94 | + PKG_name="${PKG_stem}${PKG_suffix}" |
| 95 | + PUB_name="${PKG_prefix}${PKG_suffix}" |
| 96 | + outputs PKG_prefix PKG_suffix PKG_stem PKG_name PUB_name |
| 97 | + # deployable tag? (ie, leading "vM" or "M"; M == version number) |
| 98 | + # * restrict publishing to specific 'static' builds |
| 99 | + unset DEPLOYABLE |
| 100 | + if [[ $REF_TAG =~ ^[vV]?[0-9].* ]] && [[ '${{ matrix.job.static }}' == 'static' ]]; then |
| 101 | + case '${{ matrix.job.os }}' in |
| 102 | + windows-*) |
| 103 | + if [ "${ARCH_ID}" == 'x86' ] && [ '${{ matrix.job.compiler }}' == 'cl' ]; then DEPLOYABLE='true' ; fi |
| 104 | + if [ "${ARCH_ID}" == 'x64' ] && [ '${{ matrix.job.compiler }}' == 'gcc' ]; then DEPLOYABLE='true' ; fi |
| 105 | + ;; |
| 106 | + ubuntu-*) |
| 107 | + if [ '${{ matrix.job.compiler }}' == 'clang' ]; then DEPLOYABLE='true' ; fi |
| 108 | + ;; |
| 109 | + esac |
| 110 | + fi |
| 111 | + outputs DEPLOYABLE |
| 112 | + # * strip executable? |
| 113 | + STRIP="strip" ; case '${{ matrix.job.os }}' in windows-*) STRIP='' ;; esac; |
| 114 | + outputs STRIP |
| 115 | + - name: Create all needed build/work directories |
| 116 | + shell: bash |
| 117 | + run: | |
| 118 | + ## create build/work space |
| 119 | + mkdir -p '${{ steps.vars.outputs.STAGING }}' |
| 120 | + mkdir -p '${{ steps.vars.outputs.STAGING }}'/publish |
| 121 | + mkdir -p '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}' |
| 122 | + mkdir -p '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}/bin' |
| 123 | + - uses: ilammy/msvc-dev-cmd@v1 |
| 124 | + with: |
| 125 | + arch: ${{ steps.vars.outputs.ARCH_ID }} |
| 126 | + # ref: <https://github.com/actions/virtual-environments/issues/104#issuecomment-596259045>@@<http://archive.is/orSp7> |
| 127 | + - name: Install LLVM |
| 128 | + run: choco install -y llvm |
| 129 | + if: runner.os == 'Windows' && matrix.job.compiler == 'clang' |
| 130 | + - name: Install/setup prerequisites |
| 131 | + shell: bash |
| 132 | + run: | |
| 133 | + ## install/setup prerequisites |
| 134 | + case '${{ matrix.job.os }}' in |
| 135 | + ubuntu-*) |
| 136 | + sudo dpkg --add-architecture i386 |
| 137 | + sudo dpkg --add-architecture amd64 |
| 138 | + # note: list of current dpkg architectures held at '/var/lib/dpkg/arch' |
| 139 | + sudo apt-get -y update |
| 140 | + sudo apt-get -y install lib32ncurses5-dev libncurses5-dev gcc-multilib clang |
| 141 | + ;; |
| 142 | + windows-*) |
| 143 | + case '${{ matrix.job.compiler }}' in clang) echo "::add-path::C:/Program Files/LLVM/bin" ;; esac; |
| 144 | + ;; |
| 145 | + esac |
| 146 | + case '${{ matrix.job.compiler }}' in |
| 147 | + cl) CC=cl ; CXX=cl |
| 148 | + # repair for link path error (o/w '/usr/bin/link' takes priority) |
| 149 | + LD=$(which "${CC}")/../link.exe |
| 150 | + ;; |
| 151 | + clang) CC=clang ; CXX=clang++ ; LD=${CXX} ;; |
| 152 | + gcc) CC=gcc ; CXX=g++ ; LD=${CXX} ;; |
| 153 | + esac |
| 154 | + echo "::set-env name=CC::${CC}" |
| 155 | + echo "::set-env name=CXX::${CXX}" |
| 156 | + echo "::set-env name=LD::${LD}" |
| 157 | + - name: Info |
| 158 | + shell: bash |
| 159 | + run: | |
| 160 | + # Info |
| 161 | + ### environment |
| 162 | + ## commit info |
| 163 | + echo "## commit" |
| 164 | + echo GITHUB_REF=${GITHUB_REF} |
| 165 | + echo GITHUB_SHA=${GITHUB_SHA} |
| 166 | + ## tooling info display |
| 167 | + echo "## tooling" |
| 168 | + which cl 2>/dev/null && (cl 2>&1 | head -1) || true |
| 169 | + which clang 2>/dev/null && (clang --version | head -1) || true |
| 170 | + which gcc 2>/dev/null && (gcc --version | head -1) || true |
| 171 | + which link 2>/dev/null || true |
| 172 | + echo "CC=${CC}" |
| 173 | + echo "CXX=${CXX}" |
| 174 | + - name: Build |
| 175 | + shell: bash |
| 176 | + run: | |
| 177 | + case '${{ matrix.job.os }}' in |
| 178 | + ubuntu-*) |
| 179 | + sudo chmod a+x ./configure |
| 180 | + CFLAGS="-g -O2 -m${{ steps.vars.outputs.CC_ARCH_ID }}" |
| 181 | + LDFLAGS="-m${{ steps.vars.outputs.CC_ARCH_ID }} ${{ steps.vars.outputs.LDFLAGS_STATIC }}" |
| 182 | + CFLAGS="$(echo "${CFLAGS}" | xargs echo)" ## compress/trim whitespace |
| 183 | + LDFLAGS="$(echo "${LDFLAGS}" | xargs echo)" ## compress/trim whitespace |
| 184 | + ./configure CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" |
| 185 | + ;; |
| 186 | + windows-*) |
| 187 | + cp Makefile.win Makefile |
| 188 | + ;; |
| 189 | + esac |
| 190 | + make CC="${CC}" CXX="${CXX}" LD="${LD}" ARCH='${{ steps.vars.outputs.ARCH_ID }}' STATIC='${{ matrix.job.static }}' all |
| 191 | + for exe in '${{ env.PROJECT_NAME }}' lessecho lesskey ; do |
| 192 | + cp "${exe}${{ steps.vars.outputs.EXE_suffix }}" '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}/bin/' |
| 193 | + done |
| 194 | + # `strip` binary (if needed) |
| 195 | + if [ -n "${{ steps.vars.outputs.STRIP }}" ]; then "${{ steps.vars.outputs.STRIP }}" '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}/bin/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }}' ; fi |
| 196 | + # - name: Test |
| 197 | + # uses: actions-rs/cargo@v1 |
| 198 | + # with: |
| 199 | + # use-cross: ${{ steps.vars.outputs.CARGO_USE_CROSS }} |
| 200 | + # command: test |
| 201 | + # args: --target=${{ matrix.job.target }} ${{ steps.vars.outputs.CARGO_TEST_OPTIONS}} ${{ matrix.job.cargo-options }} ${{ steps.vars.outputs.CARGO_FEATURES_OPTION }} |
| 202 | + - name: Archive artifacts |
| 203 | + uses: actions/upload-artifact@master |
| 204 | + with: |
| 205 | + name: ${{ steps.vars.outputs.PKG_stem }} |
| 206 | + path: ${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}/bin/${{ env.PROJECT_NAME }}${{ steps.vars.outputs.EXE_suffix }} |
| 207 | + - name: Package |
| 208 | + # if: steps.vars.outputs.DEPLOYABLE |
| 209 | + shell: bash |
| 210 | + run: | |
| 211 | + ## package artifact(s) |
| 212 | + # add README and LICENSE to package |
| 213 | + ## * spell-checker:ignore EADME ICENSE |
| 214 | + (shopt -s nullglob; for f in [R]"EADME"{,.*}; do cp $f '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}/' ; done) |
| 215 | + (shopt -s nullglob; for f in [L]"ICENSE"{-*,}{,.*}; do cp $f '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}/' ; done) |
| 216 | + # compression/finalize package |
| 217 | + pushd '${{ steps.vars.outputs.STAGING }}/${{ steps.vars.outputs.PKG_stem }}' >/dev/null |
| 218 | + case '${{ matrix.job.os }}' in |
| 219 | + windows-*) 7z -y a ../publish/'${{ steps.vars.outputs.PUB_name }}' * ;; |
| 220 | + *) tar czf ../publish/'${{ steps.vars.outputs.PUB_name }}' * ;; |
| 221 | + esac |
| 222 | + popd >/dev/null |
| 223 | + - name: Publish |
| 224 | + uses: softprops/action-gh-release@v1 |
| 225 | + if: steps.vars.outputs.DEPLOYABLE |
| 226 | + with: |
| 227 | + files: | |
| 228 | + ${{ steps.vars.outputs.STAGING }}/publish/* |
| 229 | + env: |
| 230 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments