build.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. name: Build
  2. on:
  3. push:
  4. branches: [ master ]
  5. tags: [ 'v*' ]
  6. pull_request:
  7. branches: [ master ]
  8. jobs:
  9. build:
  10. strategy:
  11. matrix:
  12. program:
  13. - higan-ui
  14. - icarus
  15. os:
  16. - name: ubuntu
  17. version: latest
  18. - name: windows
  19. version: latest
  20. - name: macos
  21. version: latest
  22. runs-on: ${{ matrix.os.name }}-${{ matrix.os.version }}
  23. steps:
  24. - uses: actions/checkout@v2
  25. - name: Install Dependencies
  26. if: matrix.os.name == 'ubuntu'
  27. run: |
  28. sudo apt-get update -y -qq
  29. sudo apt-get install libsdl2-dev libgtksourceview2.0-dev libgtk2.0-dev libao-dev libopenal-dev
  30. - name: Make
  31. run: make -j4 -C ${{ matrix.program }} build=performance local=false
  32. - name: Upload
  33. uses: actions/upload-artifact@v2
  34. with:
  35. name: ${{ matrix.program }}-${{ matrix.os.name }}
  36. path: ${{ matrix.program }}/out/*
  37. release:
  38. if: github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/')
  39. runs-on: ubuntu-latest
  40. needs:
  41. - build
  42. steps:
  43. - uses: actions/checkout@v2
  44. with:
  45. path: 'src'
  46. - name: Download Artifacts
  47. uses: actions/download-artifact@v2
  48. with:
  49. path: 'bin'
  50. - name: Package Artifacts
  51. run: |
  52. set -eu
  53. case ${GITHUB_REF} in
  54. refs/tags/*) suffix="-${GITHUB_REF#refs/tags/}" ;;
  55. refs/heads/master) suffix="-nightly" ;;
  56. *) suffix="" ;;
  57. esac
  58. srcdir="${GITHUB_WORKSPACE}/src"
  59. bindir="${GITHUB_WORKSPACE}/bin"
  60. # Hack: Workaround for GitHub artifacts losing attributes.
  61. for program in higan-ui icarus
  62. do
  63. chmod +x ${bindir}/${program}-ubuntu/*
  64. chmod +x ${bindir}/${program}-macos/*/Contents/MacOS/*
  65. done
  66. for os in ubuntu windows macos
  67. do
  68. mkdir "${os}"
  69. cd "${os}"
  70. # Package higan.
  71. outdir=higan${suffix}
  72. mkdir ${outdir}
  73. mkdir ${outdir}/Systems
  74. cp -ar ${bindir}/higan-ui-${os}/* ${outdir}
  75. cp -ar ${bindir}/icarus-${os}/* ${outdir}
  76. cp -a ${srcdir}/higan/System ${outdir}/Templates
  77. cp -a ${srcdir}/icarus/Database ${outdir}
  78. cp -a ${srcdir}/icarus/Firmware ${outdir}
  79. cp -a ${srcdir}/GPLv3.txt ${outdir}
  80. cp -a ${srcdir}/extras/* ${outdir}
  81. zip -r ../higan-${os}.zip ${outdir}
  82. cd -
  83. done
  84. - name: Create Release
  85. id: release
  86. env:
  87. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  88. run: |
  89. set -eu
  90. github_rest()
  91. {
  92. local method="${1}"
  93. local url="https://api.github.com${2}"
  94. shift 2
  95. >&2 echo "${method} ${url}"
  96. curl \
  97. --fail \
  98. -H "Accept: application/vnd.github.v3+json" \
  99. -H "Authorization: token ${GITHUB_TOKEN}" \
  100. -X "${method}" \
  101. "${url}" \
  102. "$@"
  103. }
  104. github_get_release_id_for_tag()
  105. {
  106. payload=$(github_rest GET "/repos/${GITHUB_REPOSITORY}/releases/tags/${1}") || return
  107. echo "${payload}" | jq .id
  108. }
  109. github_delete_release_by_id()
  110. {
  111. github_rest DELETE "/repos/${GITHUB_REPOSITORY}/releases/${1}"
  112. }
  113. github_create_release()
  114. {
  115. local payload="{
  116. \"tag_name\": \"${1}\",
  117. \"target_commitish\": \"${2}\",
  118. \"name\": \"${3}\",
  119. \"body\": \"${4}\",
  120. \"draft\": ${5},
  121. \"prerelease\": ${6}
  122. }"
  123. github_rest POST "/repos/${GITHUB_REPOSITORY}/releases" -d "${payload}"
  124. }
  125. make_nightly_release()
  126. {
  127. github_create_release \
  128. nightly \
  129. "${GITHUB_SHA}" \
  130. "higan nightly $(date +"%Y-%m-%d")" \
  131. "Auto-generated nightly release on $(date -u +"%Y-%m-%d %T %Z")" \
  132. false \
  133. true
  134. }
  135. make_version_release()
  136. {
  137. github_create_release \
  138. "${1}" \
  139. "${GITHUB_SHA}" \
  140. "higan ${1}" \
  141. "This is higan ${1}, released on $(date +"%Y-%m-%d")." \
  142. false \
  143. false
  144. }
  145. case ${GITHUB_REF} in
  146. refs/tags/*)
  147. # Create a new version release using the current revision.
  148. echo "UPLOAD_URL=$(make_version_release ${GITHUB_REF#refs/tags/} | jq -r .upload_url)" >> $GITHUB_ENV
  149. ;;
  150. refs/heads/master)
  151. # Check for an existing nightly release.
  152. { release_id=$(github_get_release_id_for_tag nightly); status=$?; } || true
  153. # Delete existing nightly release if it exists.
  154. case ${status} in
  155. 0) github_delete_release_by_id "${release_id}" ;;
  156. 22) >&2 echo "No current nightly release; skipping tag deletion." ;;
  157. *) >&2 echo "API call failed unexpectedly." && exit 1 ;;
  158. esac
  159. # Create a new nightly release using the current revision.
  160. echo "UPLOAD_URL=$(make_nightly_release | jq -r .upload_url)" >> $GITHUB_ENV
  161. ;;
  162. esac
  163. - name: Upload higan-ubuntu
  164. uses: actions/upload-release-asset@v1
  165. env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }
  166. with: { upload_url: '${{ env.UPLOAD_URL }}', asset_path: 'higan-ubuntu.zip', asset_name: 'higan-ubuntu.zip', asset_content_type: 'application/zip' }
  167. - name: Upload higan-windows
  168. uses: actions/upload-release-asset@v1
  169. env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }
  170. with: { upload_url: '${{ env.UPLOAD_URL }}', asset_path: 'higan-windows.zip', asset_name: 'higan-windows.zip', asset_content_type: 'application/zip' }
  171. - name: Upload higan-macos
  172. uses: actions/upload-release-asset@v1
  173. env: { GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}' }
  174. with: { upload_url: '${{ env.UPLOAD_URL }}', asset_path: 'higan-macos.zip', asset_name: 'higan-macos.zip', asset_content_type: 'application/zip' }