build.yml 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. # https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions
  2. name: Build
  3. on:
  4. push:
  5. pull_request:
  6. workflow_dispatch:
  7. # https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
  8. defaults:
  9. run:
  10. shell: bash
  11. jobs:
  12. ###########################################################
  13. build:
  14. ###########################################################
  15. runs-on: ${{ matrix.runner }}
  16. strategy:
  17. fail-fast: false
  18. matrix:
  19. include:
  20. - target: linux-i386
  21. runner: ubuntu-18.04
  22. haxe_latest_dist: linux64/haxe_latest.tar.gz
  23. - target: linux-amd64
  24. runner: ubuntu-18.04
  25. haxe_latest_dist: linux64/haxe_latest.tar.gz
  26. - target: darwin
  27. runner: macos-10.15
  28. haxe_latest_dist: mac/haxe_latest.tar.gz
  29. - target: win32
  30. runner: windows-2019 # has VS2019 preinstalled which supports PlatformToolset <= v142, WindowsTargetPlatformVersion 10
  31. haxe_latest_dist: windows64/haxe_latest.zip
  32. ffmpeg_url: https://github.com/HaxeFoundation/hashlink/files/5648055/ffmpeg-3.4.2-win32-dev.zip
  33. msbuild_Configuration: Release
  34. msbuild_Platform: Win32
  35. msbuild_PlatformToolset: v142
  36. msbuild_WindowsTargetPlatformVersion: 8.1
  37. - target: win64
  38. runner: windows-2019 # has VS2019 preinstalled which supports PlatformToolset <= v142, WindowsTargetPlatformVersion 10
  39. haxe_latest_dist: windows64/haxe_latest.zip
  40. ffmpeg_url: https://github.com/HaxeFoundation/hashlink/files/5648056/ffmpeg-3.4.2-win64-dev.zip
  41. msbuild_Configuration: Release
  42. msbuild_Platform: x64
  43. msbuild_PlatformToolset: v142
  44. msbuild_WindowsTargetPlatformVersion: 8.1
  45. steps:
  46. - name: "SCM Checkout"
  47. uses: actions/checkout@v2
  48. - name: "Install: Visual C++ build tools workload for Visual Studio 2019 Build Tools"
  49. if: startsWith(matrix.target, 'win')
  50. run: choco install visualstudio2019buildtools visualstudio2019-workload-vctools
  51. - name: "Install: Windows 8.1 SDK"
  52. shell: powershell
  53. if: startsWith(matrix.target, 'win')
  54. # https://github.com/actions/virtual-environments/issues/842#issuecomment-643382166
  55. run: |
  56. Invoke-WebRequest -Method Get -Uri https://go.microsoft.com/fwlink/p/?LinkId=323507 -OutFile sdksetup.exe -UseBasicParsing
  57. Start-Process -Wait sdksetup.exe -ArgumentList "/q", "/norestart", "/features", "OptionId.WindowsDesktopSoftwareDevelopmentKit", "OptionId.NetFxSoftwareDevelopmentKit"
  58. - name: Add msbuild to PATH
  59. if: startsWith(matrix.target, 'win')
  60. uses: microsoft/[email protected]
  61. with:
  62. vs-version: '[15.0,16.0)'
  63. - name: "Install: Required Dev Packages"
  64. run: |
  65. set -eux
  66. case "${{ matrix.target }}" in
  67. linux-i386)
  68. echo "MARCH=32" >> $GITHUB_ENV
  69. sudo dpkg --add-architecture i386
  70. sudo apt-get update -y
  71. sudo apt-get install --no-install-recommends -y \
  72. gcc-multilib \
  73. libalut-dev:i386 \
  74. libmbedtls-dev:i386 \
  75. libopenal-dev:i386 \
  76. libpng-dev:i386 \
  77. libsdl2-dev:i386 \
  78. libturbojpeg0-dev:i386 \
  79. libuv1-dev:i386 \
  80. libvorbis-dev:i386 \
  81. libz-dev:i386 \
  82. zlib1g-dev:i386 \
  83. libsqlite3-dev:i386
  84. ;;
  85. linux-amd64)
  86. echo "MARCH=64" >> $GITHUB_ENV
  87. sudo apt-get update -y
  88. sudo apt-get install --no-install-recommends -y \
  89. libmbedtls-dev \
  90. libopenal-dev \
  91. libpng-dev \
  92. libsdl2-dev \
  93. libturbojpeg-dev \
  94. libuv1-dev \
  95. libvorbis-dev \
  96. libsqlite3-dev
  97. ;;
  98. darwin*)
  99. brew update
  100. brew bundle
  101. ;;
  102. win*)
  103. curl -fsSL --retry 3 --retry-delay 5 -o /tmp/sdl.zip https://www.libsdl.org/release/SDL2-devel-2.0.5-VC.zip
  104. curl -fsSL --retry 3 --retry-delay 5 -o /tmp/openal.zip https://openal-soft.org/openal-binaries/openal-soft-1.17.2-bin.zip
  105. curl -fsSL --retry 3 --retry-delay 5 -o /tmp/ffmpeg.zip ${{ matrix.ffmpeg_url }}
  106. 7z x /tmp/sdl.zip -oinclude; mv include/SDL2* include/sdl
  107. 7z x /tmp/openal.zip -oinclude; mv include/openal* include/openal
  108. 7z x /tmp/ffmpeg.zip -oinclude; mv include/ffmpeg* include/ffmpeg
  109. ;;
  110. esac
  111. - name: "Install: Neko"
  112. run: |
  113. set -eux
  114. case "${{ matrix.target }}" in
  115. linux*)
  116. sudo apt-get install --no-install-recommends -y neko
  117. ;;
  118. darwin*)
  119. brew install neko
  120. ;;
  121. win*)
  122. choco install --no-progress neko -y
  123. nekopath=$(find C:/ProgramData/chocolatey/lib/neko -name neko.dll -printf '%h\n')
  124. echo "NEKOPATH=$nekopath" >> $GITHUB_ENV
  125. ;;
  126. esac
  127. neko || true # print neko version
  128. - name: "Install: Haxe latest"
  129. run: |
  130. set -eux
  131. download_url="https://build.haxe.org/builds/haxe/${{ matrix.haxe_latest_dist }}"
  132. echo "Downloading [$download_url]..."
  133. if [[ ${{ matrix.target }} == win* ]]; then
  134. curl -fsSL --retry 3 --retry-delay 5 "$download_url" -o /tmp/haxe.zip
  135. 7z x /tmp/haxe.zip -o/tmp
  136. mv -v /tmp/haxe_* /tmp/haxe
  137. cygpath -w '/tmp/haxe/' >> $GITHUB_PATH
  138. echo "HAXE_STD_PATH=$(cygpath -w '/tmp/haxe/std')" >> $GITHUB_ENV
  139. else
  140. mkdir /tmp/haxe
  141. curl -fsSL --retry 3 --retry-delay 5 "$download_url" -o /tmp/haxe.tar.gz
  142. tar xzvf /tmp/haxe.tar.gz -C /tmp/haxe --strip-components=1
  143. echo "/tmp/haxe/" >> $GITHUB_PATH
  144. echo "HAXE_STD_PATH=/tmp/haxe/std" >> $GITHUB_ENV
  145. fi
  146. /tmp/haxe/haxe --version
  147. - name: "Configure: Haxelib"
  148. run: |
  149. set -eux
  150. haxelib setup ~/haxelib
  151. haxelib install hashlink
  152. haxelib list
  153. - name: "Build: HashLink"
  154. run: |
  155. set -eux
  156. case "${{ matrix.target }}" in
  157. linux*)
  158. make
  159. sudo make install
  160. sudo ldconfig
  161. ;;
  162. darwin*)
  163. make
  164. sudo make codesign_osx
  165. sudo make install
  166. ;;
  167. win*)
  168. MSBuild.exe hl.sln //nologo //m //clp:ErrorsOnly \
  169. //p:Configuration=${{ matrix.msbuild_Configuration }} \
  170. //p:Platform=${{ matrix.msbuild_Platform }} \
  171. //p:PlatformToolset=${{ matrix.msbuild_PlatformToolset }} \
  172. //p:WindowsTargetPlatformVersion=${{ matrix.msbuild_WindowsTargetPlatformVersion }}
  173. ;;
  174. esac
  175. ls -l .
  176. - name: "Test"
  177. run: |
  178. set -eux
  179. case "${{ matrix.target }}" in
  180. win32)
  181. ${{ matrix.msbuild_Configuration }}/hl.exe --version
  182. ;;
  183. win64)
  184. x64/${{ matrix.msbuild_Configuration }}/hl.exe --version
  185. ;;
  186. *)
  187. ./hl --version
  188. case ${{ matrix.target }} in
  189. linux*) ldd -v ./hl ;;
  190. darwin*) otool -L ./hl ;;
  191. esac
  192. haxe -hl hello.hl -cp other/tests -main HelloWorld -D interp
  193. ./hl hello.hl
  194. haxe -hl src/_main.c -cp other/tests -main HelloWorld
  195. make hlc
  196. ./hlc
  197. esac
  198. - name: "Package"
  199. run: |
  200. set -eux
  201. dist_folder=hashlink-$(git rev-parse --short $GITHUB_SHA)-${{ matrix.target }}
  202. #
  203. # Collect files for the distribution
  204. #
  205. mkdir -p $dist_folder/include
  206. cp src/hl.h $dist_folder/include
  207. cp src/hlc.h $dist_folder/include
  208. cp src/hlc_main.c $dist_folder/include
  209. case "${{ matrix.target }}" in
  210. linux*)
  211. cp hl $dist_folder/
  212. cp *.{hdll,so} $dist_folder/
  213. ;;
  214. darwin*)
  215. cp hl $dist_folder/
  216. cp *.{hdll,dylib} $dist_folder/
  217. ;;
  218. win32)
  219. cp ${{ matrix.msbuild_Configuration }}/*.{dll,exe,lib,hdll} $dist_folder/
  220. cp /c/Windows/System32/msvcr120.dll $dist_folder/
  221. cp include/openal/bin/Win32/soft_oal.dll $dist_folder/OpenAL32.dll
  222. cp include/sdl/lib/x86/SDL2.dll $dist_folder/
  223. ;;
  224. win64)
  225. cp x64/${{ matrix.msbuild_Configuration }}/*.{dll,exe,lib,hdll} $dist_folder/
  226. cp /c/Windows/System32/msvcr120.dll $dist_folder/
  227. cp include/openal/bin/Win64/soft_oal.dll $dist_folder/OpenAL32.dll
  228. cp include/sdl/lib/x64/SDL2.dll $dist_folder/
  229. ;;
  230. esac
  231. #
  232. # Create the tar.gz/zip
  233. #
  234. case "${{ matrix.target }}" in
  235. win*)
  236. # 7z switches: https://sevenzip.osdn.jp/chm/cmdline/switches/
  237. 7z a -spf -y -mx9 -bt hashlink-latest-${{ matrix.target }}.zip $dist_folder
  238. echo "HASHLINK_DISTRIBUTION=hashlink-latest-${{ matrix.target }}.zip" >> $GITHUB_ENV
  239. ;;
  240. *)
  241. tar cvfz hashlink-latest-${{ matrix.target }}.tar.gz $dist_folder
  242. echo "HASHLINK_DISTRIBUTION=hashlink-latest-${{ matrix.target }}.tar.gz" >> $GITHUB_ENV
  243. ;;
  244. esac
  245. - name: "Share: build artifact"
  246. uses: actions/upload-artifact@v2
  247. with:
  248. path: ${{ env.HASHLINK_DISTRIBUTION }}
  249. ###########################################################
  250. publish-latest-release:
  251. ###########################################################
  252. runs-on: ubuntu-latest
  253. needs:
  254. - build
  255. if: github.ref == 'refs/heads/master'
  256. concurrency: publish-latest-release # https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idconcurrency
  257. steps:
  258. - name: "SCM Checkout"
  259. # only required by "hub release create" to prevent "fatal: Not a git repository"
  260. uses: actions/checkout@v2
  261. - name: "Get: all build artifacts"
  262. uses: actions/download-artifact@v2
  263. - name: "Delete previous 'latest' release"
  264. run: |
  265. set -eu
  266. api_base_url="$GITHUB_API_URL/repos/$GITHUB_REPOSITORY"
  267. # delete 'latest' github release
  268. release_id=$(curl -fsL -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" https://api.github.com/repos/$GITHUB_REPOSITORY/releases | jq -r '.[] | select(.name == "latest") | .id')
  269. if [[ -n $release_id ]]; then
  270. echo "Deleting release [$api_base_url/releases/$release_id]..."
  271. curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$api_base_url/releases/$release_id"
  272. fi
  273. # delete 'latest' git tag
  274. tag_url="$api_base_url/git/refs/tags/latest"
  275. if curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsLo /dev/null --head "$tag_url"; then
  276. echo "Deleting tag [$tag_url]..."
  277. curl -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" -fsSL -X DELETE "$tag_url"
  278. fi
  279. - name: "Create 'latest' Release"
  280. env:
  281. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  282. run: |
  283. set -eux
  284. # https://hub.github.com/hub-release.1.html
  285. hub release create "latest" \
  286. --prerelease \
  287. --message "latest" \
  288. --attach "artifact/hashlink-latest-darwin.tar.gz" \
  289. --attach "artifact/hashlink-latest-linux-amd64.tar.gz" \
  290. --attach "artifact/hashlink-latest-win32.zip" \
  291. --attach "artifact/hashlink-latest-win64.zip" \
  292. --attach "artifact/hashlink-latest-linux-i386.tar.gz"
  293. - name: "Delete intermediate build artifacts"
  294. uses: geekyeggo/delete-artifact@1-glob-support # https://github.com/GeekyEggo/delete-artifact/
  295. with:
  296. name: "*"
  297. useGlob: true
  298. failOnError: false