issues2md.yml 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # .github/workflows/issues2md.yml
  2. # https://github.com/mattduck/gh2md/issues/11
  3. name: Issues2Markdown
  4. on:
  5. # allow to run the workflow manually
  6. workflow_dispatch:
  7. #push: # comment it to reduce update.
  8. schedule:
  9. # every day
  10. - cron: "0 0 * * *"
  11. # every hour
  12. #- cron: "0 * * * *"
  13. jobs:
  14. build:
  15. name: Backup github issues to markdown files
  16. runs-on: ubuntu-latest
  17. steps:
  18. - name: Set output path
  19. run: echo "GH2MD_OUTPUT_PATH=archive/github/issues/" >> $GITHUB_ENV
  20. - name: Check output path
  21. run: |
  22. if ! [[ "$GH2MD_OUTPUT_PATH" =~ ^[a-zA-Z0-9_/.+~-]+$ ]]; then
  23. echo "error: output path does not match the pattern ^[a-zA-Z0-9_/.+~-]+$"
  24. exit 1
  25. fi
  26. - name: checkout
  27. uses: actions/checkout@master
  28. with:
  29. persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
  30. fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
  31. - name: Run gh2md
  32. run: |
  33. pip3 install --user --upgrade setuptools
  34. pip3 install --user gh2md
  35. export PATH="$HOME/.local/bin:$PATH"
  36. gh2md --version || true
  37. export GITHUB_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}
  38. # fix: RuntimeError: Output directory already exists and has files in it
  39. git rm -rf $GH2MD_OUTPUT_PATH
  40. # workaround for https://github.com/mattduck/gh2md/pull/31
  41. mkdir -p $GH2MD_OUTPUT_PATH || true
  42. gh2md $GITHUB_REPOSITORY $GH2MD_OUTPUT_PATH/ghmd --idempotent --multiple-files --file-extension .ghmd
  43. #sudo apt-get install pandoc # pandoc 2.5 == too old
  44. - name: install pandoc
  45. uses: nikeee/setup-pandoc@v1
  46. - name: "pandoc: convert github-markdown to strict-markdown"
  47. run: |
  48. pandoc --version || true
  49. mkdir -p $GH2MD_OUTPUT_PATH/md
  50. find $GH2MD_OUTPUT_PATH/ghmd -name '*.ghmd' -type f | while read ghmd_path
  51. do
  52. echo "ghmd_path: $ghmd_path"
  53. base=$(basename $ghmd_path)
  54. base=${base%.*}
  55. md_path=$GH2MD_OUTPUT_PATH/md/$base.md
  56. #pandoc --verbose -f gfm+hard_line_breaks -t markdown_strict --wrap preserve $ghmd_path -o $md_path
  57. pandoc --verbose -f gfm+hard_line_breaks -t markdown_strict $ghmd_path -o $md_path
  58. done
  59. #- name: "cleanup: move .ghmd files to separate folder"
  60. # run: |
  61. # mkdir -p $GH2MD_OUTPUT_PATH/ghmd/
  62. # mv -v $GH2MD_OUTPUT_PATH*.ghmd $GH2MD_OUTPUT_PATH/ghmd/
  63. # remove .ghmd files to save space
  64. # usually, the .ghmd files can be reconstructed from the .md files
  65. - name: "cleanup: remove .ghmd files"
  66. run: |
  67. rm -rf $GH2MD_OUTPUT_PATH/ghmd
  68. - name: Build index readme.md
  69. run: |
  70. ./.github/workflows/issues2md-build-index.sh $GH2MD_OUTPUT_PATH/md $GH2MD_OUTPUT_PATH/readme.md
  71. - name: Commit files
  72. run: |
  73. git add $GH2MD_OUTPUT_PATH
  74. git config --local user.email "action@github.com"
  75. git config --local user.name "GitHub Action"
  76. if ! git commit -m "up $GH2MD_OUTPUT_PATH" -a
  77. then
  78. echo nothing to commit
  79. exit 0
  80. fi
  81. - name: Get branch name
  82. shell: bash
  83. run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
  84. id: get_branch
  85. - name: Push changes
  86. uses: ad-m/github-push-action@master
  87. with:
  88. github_token: ${{ secrets.GITHUB_TOKEN }}
  89. branch: ${{ steps.get_branch.outputs.branch }}