-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A github actions example to extract issues of the repo itself #11
Comments
@0ut0fcontrol thanks for sharing this, it's super cool! I'll find somewhere sensible to publicise it - at least link to it from the README. I think I should set it up for gh2md itself. I'm glad this is useful for you and still working OK. I haven't used it much recently, so I'm not sure if there are any problems or obvious features that would help - feel free to open issues if you do have anything. |
@mattduck My purpose is to backup my repo with issues. And the issues is readable even when I do not has access to github.com. Combining (I am not test other tools yet, this may not be the best way to do this.) Here is a script to setup crontab to fetch repos and convert #!/bin/bash
# crontab -e
# 0 1 * * * bash path_to/backup_issues/backup_issues.sh &> path_to/backup_issues/backup_issues.sh.log
# backup_issues
# ├── backup_issues.sh
# ├── repo1
# ├── repo2
# └── repo3
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
for i in $DIR/*/; do
date
cd $i
pwd
git fetch --all --verbose
git pull
test -f issues.md && pandoc --self-contained issues.md -o issues.html --metadata title=backup_issues
test -f issues.html && echo "backup issues in ${i}issues.html"
echo "#############################################################################"
done |
@0ut0fcontrol I've added this to the repo now - worked fine first time. Thanks again! If I get some time soon, I'll add a flag to optionally remove the timestamp message in the file - this way you'll only get a commit if the content has changed, instead of a new commit on every run due to the unique timestamp. |
@mattduck Thank you. It seems that |
@0ut0fcontrol I've just fixed that. Back when I wrote this I didn't need to export closed PRs, and for some reason instead of making it configurable I just hardcoded it. I've updated the default behaviour to fetch everything by default. You can selectively disable parts with |
I'm gonna close this issue just so I know that there's no work to do on it. Will leave it pinned though. |
The workflow always has this issue, is that because I am using Chinese?
|
@JimmyLv Yes, gh2md with python2 can not process issues with Chinese characters. I will update the example in this issue and create a PR to modify |
my version of
# .github/workflows/issues2md.yml
# https://github.com/mattduck/gh2md/issues/11
name: Issues2Markdown
on:
#push: # comment it to reduce update.
schedule:
# every day
#- cron: "0 0 * * *"
# every hour
- cron: "0 * * * *"
jobs:
build:
name: Backup github issues to markdown files
runs-on: ubuntu-latest
steps:
- name: Set output path
run: echo "GH2MD_OUTPUT_PATH=archive/github/issues/" >> $GITHUB_ENV
- name: Check output path
run: |
if ! [[ "$GH2MD_OUTPUT_PATH" =~ ^[a-zA-Z0-9_/.+~-]+$ ]]; then
echo "error: output path does not match the pattern ^[a-zA-Z0-9_/.+~-]+$"
exit 1
fi
- name: checkout
uses: actions/checkout@master
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
- name: Run gh2md
run: |
pip3 install --user --upgrade setuptools
pip3 install --user gh2md
export PATH="$HOME/.local/bin:$PATH"
gh2md --version || true
export GITHUB_ACCESS_TOKEN=${{ secrets.GITHUB_TOKEN }}
# fix: RuntimeError: Output directory already exists and has files in it
git rm -rf $GH2MD_OUTPUT_PATH
# workaround for https://github.com/mattduck/gh2md/pull/31
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
uses: cachix/install-nix-action@master
with:
nix_path: nixpkgs=channel:nixos-unstable
- name: "pandoc: convert github-markdown to strict-markdown"
uses: workflow/nix-shell-action@main
with:
packages: pandoc
script: |
set -x
pandoc --version || true
find $GH2MD_OUTPUT_PATH -name '*.ghmd' -type f | while read path
do
base="${path%.*}"
pandoc --verbose -f gfm+hard_line_breaks -t markdown_strict "$base.ghmd" -o "$base.md"
done
- 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/
- name: Commit files
run: |
git add $GH2MD_OUTPUT_PATH
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
if ! git commit -m "up $GH2MD_OUTPUT_PATH" -a
then
echo nothing to commit
exit 0
fi
- name: Get branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: get_branch
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ steps.get_branch.outputs.branch }} |
|
Thank you for your great work.
I add my github actions example here, in case someone needs it.
it backups all issues every day.
Because it only backup the issues belong to the repository that contains this workflow. It does not limit by the GitHub API rate.
The text was updated successfully, but these errors were encountered: