2022-07-07 16:23:40 +02:00
|
|
|
# .github/workflows/issues2md.yml
|
|
|
|
# https://github.com/mattduck/gh2md/issues/11
|
|
|
|
|
|
|
|
name: Issues2Markdown
|
|
|
|
on:
|
2023-09-05 07:50:25 +02:00
|
|
|
# allow to run the workflow manually
|
|
|
|
workflow_dispatch:
|
2022-07-08 10:30:59 +02:00
|
|
|
#push: # comment it to reduce update.
|
2022-07-07 16:23:40 +02:00
|
|
|
schedule:
|
|
|
|
# every day
|
2023-09-05 07:29:38 +02:00
|
|
|
- cron: "0 0 * * *"
|
2022-07-08 21:45:43 +02:00
|
|
|
# every hour
|
2023-09-05 07:29:38 +02:00
|
|
|
#- cron: "0 * * * *"
|
2022-07-07 16:23:40 +02:00
|
|
|
jobs:
|
|
|
|
build:
|
2022-07-09 09:19:25 +02:00
|
|
|
name: Backup github issues to markdown files
|
2022-07-07 16:23:40 +02:00
|
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
2022-07-09 09:19:25 +02:00
|
|
|
- name: Set output path
|
2022-07-08 21:45:43 +02:00
|
|
|
run: echo "GH2MD_OUTPUT_PATH=archive/github/issues/" >> $GITHUB_ENV
|
2022-07-09 09:19:25 +02:00
|
|
|
- name: Check output path
|
|
|
|
run: |
|
2022-07-09 09:28:31 +02:00
|
|
|
if ! [[ "$GH2MD_OUTPUT_PATH" =~ ^[a-zA-Z0-9_/.+~-]+$ ]]; then
|
|
|
|
echo "error: output path does not match the pattern ^[a-zA-Z0-9_/.+~-]+$"
|
2022-07-09 09:19:25 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
- name: checkout
|
|
|
|
uses: actions/checkout@master
|
2022-07-07 16:23:40 +02:00
|
|
|
with:
|
|
|
|
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
|
|
|
|
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo
|
2022-07-09 09:19:25 +02:00
|
|
|
- name: Run gh2md
|
2022-07-07 16:23:40 +02:00
|
|
|
run: |
|
|
|
|
pip3 install --user --upgrade setuptools
|
|
|
|
pip3 install --user gh2md
|
2022-07-08 09:36:05 +02:00
|
|
|
export PATH="$HOME/.local/bin:$PATH"
|
2022-07-08 19:12:10 +02:00
|
|
|
gh2md --version || true
|
2022-07-08 09:36:05 +02:00
|
|
|
export GITHUB_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}
|
2022-07-08 10:04:32 +02:00
|
|
|
# fix: RuntimeError: Output directory already exists and has files in it
|
2022-07-08 18:02:54 +02:00
|
|
|
git rm -rf $GH2MD_OUTPUT_PATH
|
2022-07-08 10:06:34 +02:00
|
|
|
# workaround for https://github.com/mattduck/gh2md/pull/31
|
2022-07-08 18:02:54 +02:00
|
|
|
mkdir -p $GH2MD_OUTPUT_PATH || true
|
2023-09-05 07:47:21 +02:00
|
|
|
gh2md $GITHUB_REPOSITORY $GH2MD_OUTPUT_PATH/ghmd --idempotent --multiple-files --file-extension .ghmd
|
2022-07-08 18:02:54 +02:00
|
|
|
#sudo apt-get install pandoc # pandoc 2.5 == too old
|
2023-09-05 07:59:07 +02:00
|
|
|
- name: install pandoc
|
|
|
|
uses: nikeee/setup-pandoc@v1
|
2022-07-09 18:10:30 +02:00
|
|
|
- name: "pandoc: convert github-markdown to strict-markdown"
|
2023-09-05 07:59:07 +02:00
|
|
|
run: |
|
|
|
|
pandoc --version || true
|
|
|
|
mkdir -p $GH2MD_OUTPUT_PATH/md
|
|
|
|
find $GH2MD_OUTPUT_PATH/ghmd -name '*.ghmd' -type f | while read ghmd_path
|
|
|
|
do
|
2023-09-05 08:06:21 +02:00
|
|
|
echo "ghmd_path: $ghmd_path"
|
2023-09-05 07:59:07 +02:00
|
|
|
base=$(basename $ghmd_path)
|
|
|
|
base=${base%.*}
|
|
|
|
md_path=$GH2MD_OUTPUT_PATH/md/$base.md
|
2023-12-21 17:45:39 +01:00
|
|
|
pandoc --verbose -f gfm+hard_line_breaks -t markdown_strict --wrap preserve $ghmd_path -o $md_path
|
2023-09-05 07:59:07 +02:00
|
|
|
done
|
2023-09-05 07:47:21 +02:00
|
|
|
#- name: "cleanup: move .ghmd files to separate folder"
|
|
|
|
# run: |
|
|
|
|
# mkdir -p $GH2MD_OUTPUT_PATH/ghmd/
|
|
|
|
# mv -v $GH2MD_OUTPUT_PATH*.ghmd $GH2MD_OUTPUT_PATH/ghmd/
|
2023-09-05 07:59:22 +02:00
|
|
|
# remove .ghmd files to save space
|
|
|
|
# usually, the .ghmd files can be reconstructed from the .md files
|
|
|
|
- name: "cleanup: remove .ghmd files"
|
|
|
|
run: |
|
|
|
|
rm -rf $GH2MD_OUTPUT_PATH/ghmd
|
2023-09-05 07:47:21 +02:00
|
|
|
- name: Build index readme.md
|
2022-07-08 18:02:54 +02:00
|
|
|
run: |
|
2023-09-05 08:00:41 +02:00
|
|
|
./.github/workflows/issues2md-build-index.sh $GH2MD_OUTPUT_PATH/md $GH2MD_OUTPUT_PATH/readme.md
|
2022-07-07 16:23:40 +02:00
|
|
|
- name: Commit files
|
|
|
|
run: |
|
2022-07-08 18:02:54 +02:00
|
|
|
git add $GH2MD_OUTPUT_PATH
|
2022-07-07 16:23:40 +02:00
|
|
|
git config --local user.email "action@github.com"
|
|
|
|
git config --local user.name "GitHub Action"
|
2022-07-08 18:02:54 +02:00
|
|
|
if ! git commit -m "up $GH2MD_OUTPUT_PATH" -a
|
|
|
|
then
|
|
|
|
echo nothing to commit
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
- name: Get branch name
|
2022-07-07 16:23:40 +02:00
|
|
|
shell: bash
|
|
|
|
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
|
2022-07-08 18:02:54 +02:00
|
|
|
id: get_branch
|
2022-07-07 16:23:40 +02:00
|
|
|
- name: Push changes
|
|
|
|
uses: ad-m/github-push-action@master
|
|
|
|
with:
|
|
|
|
github_token: ${{ secrets.GITHUB_TOKEN }}
|
2022-07-08 18:02:54 +02:00
|
|
|
branch: ${{ steps.get_branch.outputs.branch }}
|