docs.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. name: Generate Documentation
  2. on:
  3. push:
  4. paths-ignore:
  5. - "cmake/**"
  6. branches: ['*']
  7. tags: ['*']
  8. pull_request:
  9. paths:
  10. - "docs/sphinx/**"
  11. workflow_dispatch:
  12. jobs:
  13. docs:
  14. runs-on: ubuntu-latest
  15. outputs:
  16. commitHash: ${{ steps.setup.outputs.commitHash }}
  17. commitBranch: ${{ steps.setup.outputs.commitBranch }}
  18. fullCommitHash: ${{ steps.setup.outputs.fullCommitHash }}
  19. env:
  20. BUILD_CF_ARTIFACT: ${{ startsWith(github.ref, 'refs/tags/') || github.event_name == 'workflow_dispatch' }}
  21. steps:
  22. - name: Checkout
  23. uses: actions/checkout@v3
  24. - name: Setup Environment
  25. id: setup
  26. run: |
  27. BRANCH=$(git describe --exact-match --tags 2> /dev/null || git branch --show-current)
  28. # Remove patch version from tag
  29. BRANCH=$(echo ${BRANCH} | sed -e 's/\.[0-9]*$//')
  30. echo "commitBranch=${BRANCH}" >> $GITHUB_OUTPUT
  31. echo "commitHash=$(git describe --exact-match --tags 2> /dev/null || git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
  32. echo "fullCommitHash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
  33. - name: Bump Version Number
  34. shell: bash
  35. if: github.event_name != 'pull_request'
  36. run: |
  37. VERTEST="\#define\sLIBOBS_API_\w+_VER\s([0-9]{1,2})"
  38. VER=""
  39. MAJOR=""
  40. while IFS= read -r l
  41. do
  42. if [[ $l =~ $VERTEST ]]; then
  43. if [[ $VER = '' ]]; then MAJOR="${BASH_REMATCH[1]}"; else VER+="."; fi
  44. VER+="${BASH_REMATCH[1]}"
  45. fi
  46. done < "libobs/obs-config.h"
  47. SVER="version = '([0-9\.]+)'"
  48. RVER="version = '$VER'"
  49. SREL="release = '([0-9\.]+)'"
  50. RREL="release = '$VER'"
  51. SCOPY="copyright = '([A-Za-z0-9, ]+)'"
  52. RCOPY="copyright = '2017-$(date +"%Y"), Lain Bailey'"
  53. sed -i -E -e "s/${SVER}/${RVER}/g" -e "s/${SREL}/${RREL}/g" -e "s/${SCOPY}/${RCOPY}/g" docs/sphinx/conf.py
  54. - uses: totaldebug/[email protected]
  55. with:
  56. sphinx_src: 'docs/sphinx'
  57. build_only: True
  58. target_branch: 'master'
  59. target_path: '../home/_build'
  60. pre_build_commands: 'pip install -Iv sphinx==5.1.1'
  61. - name: Disable link extensions
  62. shell: bash
  63. if: ${{ env.BUILD_CF_ARTIFACT == 'true' }}
  64. run: |
  65. SOPT="html_link_suffix = None"
  66. ROPT="html_link_suffix = ''"
  67. sed -i -e "s/${SOPT}/${ROPT}/g" docs/sphinx/conf.py
  68. - uses: totaldebug/[email protected]
  69. if: ${{ env.BUILD_CF_ARTIFACT == 'true' }}
  70. with:
  71. sphinx_src: 'docs/sphinx'
  72. build_only: True
  73. target_branch: 'master'
  74. target_path: '../home/_build_cf'
  75. pre_build_commands: 'pip install -Iv sphinx==5.1.1'
  76. - uses: actions/upload-artifact@v3
  77. with:
  78. name: 'OBS Studio Docs ${{ steps.setup.outputs.commitHash }}'
  79. path: |
  80. ${{ runner.temp }}/_github_home/_build
  81. !${{ runner.temp }}/_github_home/_build/.doctrees
  82. - uses: actions/upload-artifact@v3
  83. if: ${{ env.BUILD_CF_ARTIFACT == 'true' }}
  84. with:
  85. name: 'CF Pages ${{ steps.setup.outputs.commitHash }}'
  86. path: |
  87. ${{ runner.temp }}/_github_home/_build_cf
  88. !${{ runner.temp }}/_github_home/_build_cf/.doctrees
  89. deploy:
  90. runs-on: ubuntu-latest
  91. needs: docs
  92. if: ${{ github.event_name == 'workflow_dispatch' || (github.repository_owner == 'obsproject' && startsWith(github.ref, 'refs/tags/') && github.event_name != 'pull_request') }}
  93. environment:
  94. name: cf-pages-deploy
  95. concurrency:
  96. group: "cf-pages-deployment"
  97. cancel-in-progress: true
  98. steps:
  99. - uses: actions/download-artifact@v3
  100. with:
  101. name: 'CF Pages ${{ needs.docs.outputs.commitHash }}'
  102. path: docs
  103. - name: Setup redirects
  104. run: |
  105. echo "/previous/27.2 https://obsproject.com/docs/27.2 302" >> docs/_redirects
  106. echo "/previous/:major.:minor https://:major-:minor.${{ vars.CF_PAGES_PROJECT }}.pages.dev 302" >> docs/_redirects
  107. - name: Publish to live page
  108. if: ${{ !contains(needs.docs.outputs.commitBranch, 'beta') && !contains(needs.docs.outputs.commitBranch, 'rc') }}
  109. uses: cloudflare/wrangler-action@4c10c1822abba527d820b29e6333e7f5dac2cabd
  110. with:
  111. workingDirectory: docs
  112. apiToken: ${{ secrets.CF_API_TOKEN }}
  113. accountId: ${{ secrets.CF_ACCOUNT_ID }}
  114. command: pages publish . --project-name=${{ vars.CF_PAGES_PROJECT }} --commit-hash='${{ needs.docs.outputs.fullCommitHash }}'
  115. - name: Publish to tag alias
  116. if: ${{ startsWith(github.ref, 'refs/tags/') }}
  117. uses: cloudflare/wrangler-action@4c10c1822abba527d820b29e6333e7f5dac2cabd
  118. with:
  119. workingDirectory: docs
  120. apiToken: ${{ secrets.CF_API_TOKEN }}
  121. accountId: ${{ secrets.CF_ACCOUNT_ID }}
  122. command: pages publish . --project-name=${{ vars.CF_PAGES_PROJECT }} --commit-hash='${{ needs.docs.outputs.fullCommitHash }}' --branch='${{ needs.docs.outputs.commitBranch }}'