2022-07-07 16:23:40 +02:00
|
|
|
# .github/workflows/issues2md.yml
|
|
|
|
# https://github.com/mattduck/gh2md/issues/11
|
|
|
|
|
|
|
|
name: Issues2Markdown
|
|
|
|
on:
|
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
|
2022-07-08 09:36:05 +02:00
|
|
|
#- cron: "0 0 * * *"
|
2022-07-08 21:45:43 +02:00
|
|
|
# every hour
|
|
|
|
- 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
|
|
|
|
gh2md $GITHUB_REPOSITORY $GH2MD_OUTPUT_PATH --idempotent --multiple-files --file-extension .ghmd
|
|
|
|
#sudo apt-get install pandoc # pandoc 2.5 == too old
|
|
|
|
# install nix to install pandoc 2.17
|
|
|
|
- name: install nix
|
2022-07-08 18:06:41 +02:00
|
|
|
uses: cachix/install-nix-action@master
|
2022-07-08 18:02:54 +02:00
|
|
|
with:
|
|
|
|
nix_path: nixpkgs=channel:nixos-unstable
|
2022-07-09 18:10:30 +02:00
|
|
|
- name: "pandoc: convert github-markdown to strict-markdown"
|
2022-07-08 18:06:41 +02:00
|
|
|
uses: workflow/nix-shell-action@main
|
2022-07-08 18:02:54 +02:00
|
|
|
with:
|
|
|
|
packages: pandoc
|
|
|
|
script: |
|
2022-07-09 18:10:30 +02:00
|
|
|
set -x
|
2022-07-09 11:18:23 +02:00
|
|
|
pandoc --version || true
|
2022-07-09 11:20:09 +02:00
|
|
|
find $GH2MD_OUTPUT_PATH -name '*.ghmd' -type f | while read path
|
2022-07-08 18:02:54 +02:00
|
|
|
do
|
2022-07-09 11:20:09 +02:00
|
|
|
base="${path%.*}"
|
|
|
|
pandoc --verbose -f gfm+hard_line_breaks -t markdown_strict "$base.ghmd" -o "$base.md"
|
2022-07-08 18:02:54 +02:00
|
|
|
done
|
|
|
|
- name: "cleanup: move .ghmd files to separate folder"
|
|
|
|
run: |
|
2022-07-09 09:19:25 +02:00
|
|
|
mkdir -p $GH2MD_OUTPUT_PATH/ghmd/
|
|
|
|
mv -v $GH2MD_OUTPUT_PATH*.ghmd $GH2MD_OUTPUT_PATH/ghmd/
|
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 }}
|