switch.yml 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. name: switch
  2. on:
  3. push:
  4. branches:
  5. - master
  6. - feature/gh-actions-switch-cache
  7. tags:
  8. - '*'
  9. pull_request: {}
  10. workflow_dispatch:
  11. jobs:
  12. build_switch:
  13. name: Build Switch
  14. runs-on: ubuntu-latest
  15. container:
  16. image: 'devkitpro/devkita64'
  17. steps:
  18. - name: Checkout code
  19. uses: actions/checkout@v2
  20. with:
  21. # We need 0 so we get all commits for mtime!
  22. fetch-depth: 0
  23. path: "./stk-code"
  24. - name: Grab assets
  25. run: |
  26. wget -q https://github.com/supertuxkart/stk-assets-mobile/releases/download/git/stk-assets-full.zip
  27. unzip -q stk-assets-full.zip -d stk-assets
  28. rm stk-assets-full.zip
  29. - name: Restore modified date
  30. run: |
  31. cd stk-code
  32. git restore-mtime .
  33. cd ..
  34. # Env setup!
  35. - name: Configure packaging name for git master branch
  36. if: ${{ github.ref == 'refs/heads/master' }}
  37. run: |
  38. echo "release_tag=git`date +%Y%m%d`" >> $GITHUB_ENV
  39. echo "release_name=preview" >> $GITHUB_ENV
  40. - name: Configure packaging name for tag
  41. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  42. run: |
  43. echo "release_tag=`basename $GITHUB_REF`" >> $GITHUB_ENV
  44. echo "release_name=`basename $GITHUB_REF`" >> $GITHUB_ENV
  45. - name: Configure packaging name for non-releasing branch
  46. if: ${{ (github.ref != 'refs/heads/master' && !startsWith(github.ref, 'refs/tags/')) || github.repository_owner != 'supertuxkart' }}
  47. run: |
  48. echo "release_tag=" >> $GITHUB_ENV
  49. echo "release_name=" >> $GITHUB_ENV
  50. - name: Check for prerelease
  51. if: ${{ github.ref == 'refs/heads/master' || contains(github.ref, 'rc') || contains(github.ref, 'beta') }}
  52. run: |
  53. echo "release_pre=true" >> $GITHUB_ENV
  54. - name: Check for non-prerelease
  55. if: ${{ github.ref != 'refs/heads/master' && !contains(github.ref, 'rc') && !contains(github.ref, 'beta') }}
  56. run: |
  57. echo "release_pre=false" >> $GITHUB_ENV
  58. - name: Show packaging name
  59. run : |
  60. echo "${{ env.release_tag }}"
  61. echo "${{ env.release_name }}"
  62. echo "${{ env.release_pre }}"
  63. - name: List build cache restore keys
  64. shell : bash
  65. run: |
  66. # Look for the last 9 build caches (GitHub supports max 10 including current one)
  67. for number in 1 2 3 4 5 6 7 8 9
  68. do
  69. id=$((${{ github.run_number }} - number))
  70. echo "cache_$number=switch-${{ github.ref }}-$id" >> $GITHUB_ENV
  71. done
  72. - name: Handle build cache
  73. uses: actions/cache@v2
  74. with:
  75. # This is unnecessarily verbose and might break, but again ! seems broken
  76. # See: https://github.com/Mstrodl/stk-code/runs/2333673736?check_suite_focus=true#step:16:34
  77. path: |
  78. stk-code/cmake_build/CMakeFiles
  79. stk-code/cmake_build/Makefile
  80. stk-code/cmake_build/lib
  81. stk-code/cmake_build/bin/supertuxkart
  82. stk-code/cmake_build/*.cmake
  83. stk-code/cmake_build/*.txt
  84. # Make sure PRs can't overwrite!
  85. key: switch-${{ github.ref }}-${{ github.run_number }}
  86. restore-keys: |
  87. ${{ env.cache_1 }}
  88. ${{ env.cache_2 }}
  89. ${{ env.cache_3 }}
  90. ${{ env.cache_4 }}
  91. ${{ env.cache_5 }}
  92. ${{ env.cache_6 }}
  93. ${{ env.cache_7 }}
  94. ${{ env.cache_8 }}
  95. ${{ env.cache_9 }}
  96. - name: Run build script
  97. run: |
  98. cd stk-code/switch
  99. PROJECT_VERSION="${{ env.release_tag }}" ./make.sh
  100. - name: Create release
  101. uses: ncipollo/release-action@v1.8.8
  102. if: ${{ env.release_tag != '' }}
  103. with:
  104. token: ${{ secrets.GITHUB_TOKEN }}
  105. artifacts: "stk-code/cmake_build/bin/SuperTuxKart-${{ env.release_tag }}-switch.zip"
  106. tag: ${{ env.release_name }}
  107. omitBodyDuringUpdate: true
  108. omitNameDuringUpdate: true
  109. allowUpdates: true
  110. prerelease: ${{ env.release_pre }}