Skip to content

Commit

Permalink
Add Jekyll gihub pages workflow for subdeck repos
Browse files Browse the repository at this point in the history
* Add workflow file for subdecks
* Use ki to make test repository in `test_subdeck.sh`
  • Loading branch information
langfield committed Nov 6, 2023
1 parent 286b674 commit b647e35
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 4 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/jekyll-gh-pages.yml.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Sample workflow for building and deploying a Jekyll site to GitHub Pages
name: Deploy Jekyll with GitHub Pages dependencies preinstalled

on:
# Runs on pushes targeting the default branch
push:
branches: ["main"]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
concurrency:
group: "pages"
cancel-in-progress: false

jobs:
# Build job
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Make index.md
run: find . -name '*.md' -not -path '*/.*' -printf "%d %p\n" | sort -n | sed 's/^[0-9]\+\s//g' | xargs -I{} bash -c 'cat {} | sed "s,^\# Note,# {},g" | sed "s/^#/###/g" && printf "\n---\n"' > index.md
- name: Setup Pages
uses: actions/configure-pages@v3
- name: Build with Jekyll
uses: actions/jekyll-build-pages@v1
with:
source: ./
destination: ./_site
- name: Upload artifact
uses: actions/upload-pages-artifact@v2

# Deployment job
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
2 changes: 2 additions & 0 deletions ki/maybes.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ def empty_kirepo(root: EmptyDir) -> Tuple[EmptyDir, EmptyDir]:
"""Initialize subdirs for a ki repo."""
kidir = F.mksubdir(root, Path(KI))
mediadir = F.mksubdir(EmptyDir(root), Path(MEDIA))
workflowsdir = F.mksubdir(EmptyDir(root), Path(".github/workflows"))
_ = F.copyfile(F.chk(Path(__file__).parent.parent / ".github/workflows/jekyll-gh-pages.yml.example"), F.chk(workflowsdir / "jekyll-gh-pages.yml.example"))
return kidir, mediadir


Expand Down
7 changes: 7 additions & 0 deletions subdeck
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,21 @@ mkdir -p /tmp/ki
cd /tmp/ki
git clone $root $subdeck
cd $subdeck
echo "About to filter repo"
git filter-repo --force --subdirectory-filter $subdeck --path-rename $subdeck/:
cd $(git rev-parse --show-toplevel)
git remote add origin $remote
echo "Just added origin"
mkdir -p .github/workflows
cp $root/.github/workflows/jekyll-gh-pages.yml.example .github/workflows/jekyll-gh-pages.yml
git add .github
git commit -m "Add github pages CI workflow"
git push -u origin main

cd $root
git rm -r $subdeck
git commit -m "Remove \`$subdeck\`"
rm -rf $subdeck
echo "Just deleted prefix"
git subtree add --prefix $subdeck $remote main
echo "commits for deck '$subdeck' pushed to '$remote'"
13 changes: 9 additions & 4 deletions tests/test_subdeck.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#!/usr/bin/env bash
set -e

pip install -e .

# Create root repository.
rm -rf /tmp/subtree
rm -rf /tmp/collections
mkdir -p /tmp/subtree
cp -r tests/data/repos/multideck /tmp/subtree/multideck
mkdir -p /tmp/collections
cp tests/data/collections/multideck.anki2 /tmp/collections/multideck.anki2
cd /tmp/subtree
ki clone /tmp/collections/multideck.anki2
cd /tmp/subtree/multideck
git init --initial-branch main
git add .
git commit -m "Initial commit"

# Create subtree (local) remote.
mkdir /tmp/subtree/github
Expand Down Expand Up @@ -52,12 +55,14 @@ cd /tmp/subtree/multideck
git subtree pull -m "Merge branch 'main' of /tmp/subtree/github" --prefix aa /tmp/subtree/github main

echo ""
git log --oneline -n 20
git log --oneline -n 20 | grep "Add b"
git log --oneline -n 20 | grep "Add c"

echo ""
cd /tmp/subtree/github
git checkout main
git log --oneline -n 20
git log --oneline -n 20 | grep "Add b"
git log --oneline -n 20 | grep "Add c"
git checkout -

0 comments on commit b647e35

Please sign in to comment.