build.yml 5.9 KB

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