|
| 1 | +# modified from https://github.com/simonmichael/hledger/blob/master/.github/workflows/linux.yml |
| 2 | + |
| 3 | +name: CI (Unix) |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: [master, ci-*, ci] |
| 8 | + tags: |
| 9 | + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 |
| 10 | + pull_request: |
| 11 | + branches: [master] |
| 12 | + |
| 13 | +jobs: |
| 14 | + build-and-test: |
| 15 | + runs-on: ${{ matrix.os }} |
| 16 | + strategy: |
| 17 | + matrix: |
| 18 | + os: [ubuntu-latest, macos-latest] |
| 19 | + fail-fast: false |
| 20 | + steps: |
| 21 | + |
| 22 | + - name: 📥 Checkout repository |
| 23 | + uses: actions/checkout@v4 |
| 24 | + |
| 25 | + - name: 🔍 Determine stack resolver & GHC |
| 26 | + run: | |
| 27 | + STACK_RESOLVER=$(yq .resolver stack.yaml) |
| 28 | + GHC_VERSION=$(echo $(yq .compiler stack.yaml) | cut -c 5-) |
| 29 | + echo STACK_RESOLVER="${STACK_RESOLVER}" >> "${GITHUB_ENV}" |
| 30 | + echo GHC_VERSION="${GHC_VERSION}" >> "${GITHUB_ENV}" |
| 31 | +
|
| 32 | + # things to be restored: |
| 33 | + # Include STACK_RESOLVER in cache key, otherwise caches accumulate build products for different resolvers. |
| 34 | + |
| 35 | + - name: 💾 Restore cached stack global package db |
| 36 | + id: stack-global |
| 37 | + uses: actions/cache/restore@v4 |
| 38 | + with: |
| 39 | + path: ~/.stack |
| 40 | + key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global-${{ hashFiles('**.yaml') }} |
| 41 | + restore-keys: | |
| 42 | + ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-global |
| 43 | +
|
| 44 | + - name: 💾 Restore cached .stack-work |
| 45 | + id: stack-work |
| 46 | + uses: actions/cache/restore@v4 |
| 47 | + with: |
| 48 | + path: .stack-work |
| 49 | + key: ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work-${{ hashFiles('**.yaml') }} |
| 50 | + restore-keys: | |
| 51 | + ${{ runner.os }}-stack-resolver-${{ env.STACK_RESOLVER }}-work |
| 52 | +
|
| 53 | + # actions: |
| 54 | + - name: Set PKG_CONFIG_PATH for the ICU library (on macOS) |
| 55 | + if: runner.os == 'macOS' |
| 56 | + run: | |
| 57 | + echo PKG_CONFIG_PATH="$(brew --prefix)/opt/icu4c/lib/pkgconfig" >> "${GITHUB_ENV}" |
| 58 | +
|
| 59 | + - name: ⏬ Setup Haskell |
| 60 | + uses: haskell-actions/setup@v2 |
| 61 | + id: setup-haskell |
| 62 | + with: |
| 63 | + ghc-version: ${{ env.GHC_VERSION }} |
| 64 | + enable-stack: true |
| 65 | + stack-version: 'latest' |
| 66 | + |
| 67 | + - name: ⏬ Install dependencies |
| 68 | + run: | |
| 69 | + stack build |
| 70 | +
|
| 71 | + - name: 🔨 Build and run tests |
| 72 | + run: | |
| 73 | + stack test |
| 74 | + |
| 75 | + # things to be cached |
| 76 | + |
| 77 | + - name: 💾 Cache stack global package db |
| 78 | + if: always() && steps.stack-global.outputs.cache-hit != 'true' |
| 79 | + uses: actions/cache/save@v3 |
| 80 | + with: |
| 81 | + path: ~/.stack |
| 82 | + key: ${{ steps.stack-global.outputs.cache-primary-key }} |
| 83 | + |
| 84 | + - name: 💾 Cache .stack-work |
| 85 | + if: always() && steps.stack-work.outputs.cache-hit != 'true' |
| 86 | + uses: actions/cache/save@v3 |
| 87 | + with: |
| 88 | + path: .stack-work |
| 89 | + key: ${{ steps.stack-work.outputs.cache-primary-key }} |
| 90 | + |
| 91 | + |
| 92 | + - name: 🔗 Bundle ICU4C DLLs (on macOS) |
| 93 | + if: runner.os == 'macOS' |
| 94 | + run: | # Bundle icu4c DLLs |
| 95 | +
|
| 96 | + # see if icu4c has been installed |
| 97 | + if [ "$(brew list | grep icu4c)" = "" ] |
| 98 | + then |
| 99 | + echo "installing icu4c" |
| 100 | + brew install icu4c |
| 101 | + fi |
| 102 | +
|
| 103 | + # get the directory of the DDLs we want (icuuc, icui18n, icudata) |
| 104 | + dylib_dir=$(dirname "$(brew list icu4c | grep icuuc.dylib)") |
| 105 | + echo "dylib_dir: $dylib_dir" |
| 106 | +
|
| 107 | + # find the path of "als" |
| 108 | + executable=$(find "$(stack path --local-install-root)"/bin -name "als") |
| 109 | + echo "executable: $executable" |
| 110 | +
|
| 111 | + # remove the old dylib, and make a new one |
| 112 | + rm -rf dylib |
| 113 | + mkdir dylib |
| 114 | +
|
| 115 | + ################################################################################ |
| 116 | + # icuuc |
| 117 | + ################################################################################ |
| 118 | +
|
| 119 | + icuuc_id=$(otool -L "$executable" | grep icuuc | awk '{print $1}') |
| 120 | + icuuc_id_basename=$(basename "$icuuc_id") |
| 121 | +
|
| 122 | + icuuc_path=$dylib_dir/$icuuc_id_basename |
| 123 | + icuuc_path_new=dylib/$icuuc_id_basename |
| 124 | + icuuc_id_new=@loader_path/dylib/$icuuc_id_basename |
| 125 | +
|
| 126 | + # copy icuuc to the new directory |
| 127 | + cp "$icuuc_path" "$icuuc_path_new" |
| 128 | +
|
| 129 | + # change icuuc's ID referenced by ALS |
| 130 | + install_name_tool -change "$icuuc_id" "$icuuc_id_new" "$executable" |
| 131 | +
|
| 132 | + echo "icuuc referenced by ALS" |
| 133 | + echo " old ID : $icuuc_id" |
| 134 | + echo " new ID : $icuuc_id_new" |
| 135 | + echo " old path: $icuuc_path" |
| 136 | + echo " new path: $icuuc_path_new" |
| 137 | +
|
| 138 | + ################################################################################ |
| 139 | + # icui18n |
| 140 | + ################################################################################ |
| 141 | +
|
| 142 | + icui18n_id=$(otool -L "$executable" | grep icui18n | awk '{print $1}') |
| 143 | + icui18n_id_basename=$(basename "$icui18n_id") |
| 144 | +
|
| 145 | + icui18n_path=$dylib_dir/$icui18n_id_basename |
| 146 | + icui18n_path_new=dylib/$icui18n_id_basename |
| 147 | + icui18n_id_new=@loader_path/dylib/$icui18n_id_basename |
| 148 | +
|
| 149 | + # copy icui18n to the new directory |
| 150 | + cp "$icui18n_path" "$icui18n_path_new" |
| 151 | +
|
| 152 | + # change icui18n's ID referenced by ALS |
| 153 | + install_name_tool -change "$icui18n_id" "$icui18n_id_new" "$executable" |
| 154 | +
|
| 155 | + echo "icui18n referenced by ALS" |
| 156 | + echo " old ID : $icui18n_id" |
| 157 | + echo " new ID : $icui18n_id_new" |
| 158 | + echo " old path: $icui18n_path" |
| 159 | + echo " new path: $icui18n_path_new" |
| 160 | +
|
| 161 | + ################################################################################ |
| 162 | + # icudata |
| 163 | + ################################################################################ |
| 164 | +
|
| 165 | + # otool -L "$icui18n_id" | grep icudata | awk '{print $1}' |
| 166 | + icudata_id=$(otool -L "$icuuc_path" | grep icudata | awk '{print $1}') |
| 167 | + icudata_id_basename=$(basename "$icudata_id") |
| 168 | +
|
| 169 | + icudata_path=$dylib_dir/$icudata_id_basename |
| 170 | + icudata_path_new=dylib/$icudata_id_basename |
| 171 | +
|
| 172 | + # copy icudata to the new directory |
| 173 | + cp "$icudata_path" "$icudata_path_new" |
| 174 | +
|
| 175 | + # no need of changing the ID because supposely it's already of "@loader_path" |
| 176 | +
|
| 177 | + echo "icudata referenced by icuuc" |
| 178 | + echo " old ID : $icudata_id" |
| 179 | + echo " old path : $icudata_path" |
| 180 | + echo " new path : $icudata_path_new" |
| 181 | +
|
| 182 | +
|
| 183 | + - name: 📦 Compress files |
| 184 | + id: zip |
| 185 | + run: | |
| 186 | + # locate the data-dir |
| 187 | + datadir=$(find "$(stack path --snapshot-install-root)/share" -type d -name "Agda-*") |
| 188 | + echo "datadir: $datadir" |
| 189 | +
|
| 190 | + # locate the executable |
| 191 | + executable=$(find "$(stack path --local-install-root)/bin" -name "als") |
| 192 | + echo "executable: $executable" |
| 193 | +
|
| 194 | + # make a temporary directory for compresssing |
| 195 | + mkdir zip |
| 196 | + cp -r "$datadir" zip/data |
| 197 | + if [[ ${{ runner.os }} == "macOS" ]]; then |
| 198 | + cp -r dylib zip/dylib |
| 199 | + fi |
| 200 | + cp "$executable" zip/ |
| 201 | +
|
| 202 | + # compress |
| 203 | + if [[ ${{ runner.os }} == "Linux" ]]; then |
| 204 | + cd zip |
| 205 | + zip -r als-ubuntu.zip ./* |
| 206 | + cd .. |
| 207 | + mv zip/als-ubuntu.zip . |
| 208 | + fi |
| 209 | + if [[ ${{ runner.os }} == "macOS" ]]; then |
| 210 | + cd zip |
| 211 | + zip -r als-macos.zip ./* |
| 212 | + cd .. |
| 213 | + mv zip/als-macos.zip . |
| 214 | + fi |
| 215 | +
|
| 216 | + - name: 🔨 Build and run tests |
| 217 | + run: | |
| 218 | + |
| 219 | + stack test --ta --als-path=zip/als |
| 220 | +
|
| 221 | + # release (optional) |
| 222 | + - name: 🚢 Release Artifacts |
| 223 | + if: startsWith(github.ref, 'refs/tags/v') # so that only commits with a git tag would upload artifacts |
| 224 | + env: |
| 225 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 226 | + run: | |
| 227 | + gh release upload ${{ github.ref_name }} als-ubuntu.zip --clobber |
0 commit comments