From b647e354b331599fb1c4c812c6eae432161c450e Mon Sep 17 00:00:00 2001 From: Malcolm Langfield <35980963+langfield@users.noreply.github.com> Date: Mon, 6 Nov 2023 07:11:35 -0500 Subject: [PATCH] Add Jekyll gihub pages workflow for subdeck repos * Add workflow file for subdecks * Use ki to make test repository in `test_subdeck.sh` --- .github/workflows/jekyll-gh-pages.yml.example | 53 +++++++++++++++++++ ki/maybes.py | 2 + subdeck | 7 +++ tests/test_subdeck.sh | 13 +++-- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/jekyll-gh-pages.yml.example diff --git a/.github/workflows/jekyll-gh-pages.yml.example b/.github/workflows/jekyll-gh-pages.yml.example new file mode 100644 index 00000000..2097e054 --- /dev/null +++ b/.github/workflows/jekyll-gh-pages.yml.example @@ -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 diff --git a/ki/maybes.py b/ki/maybes.py index 45458f5d..5da74656 100644 --- a/ki/maybes.py +++ b/ki/maybes.py @@ -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 diff --git a/subdeck b/subdeck index 9e359d4a..cfebfa43 100755 --- a/subdeck +++ b/subdeck @@ -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'" diff --git a/tests/test_subdeck.sh b/tests/test_subdeck.sh index 22b35dbd..d534968e 100755 --- a/tests/test_subdeck.sh +++ b/tests/test_subdeck.sh @@ -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 @@ -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 -