Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Push to any branch

on:
push

permissions:
id-token: write
pages: write

jobs:
push:
runs-on: ubuntu-latest

steps:
- name: Pandoc specification builder
uses: legreq/pandoc-spec@multibranch
with:
include-repository: true
include-pages: true
include-branches: true
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/package-lock.json
/dist/
/_site/
/node_modules/
/pandoc/pandoc-spec.css
/pandoc/pandoc-spec.css.map
/test/_site/
92 changes: 90 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ inputs:
required: false
# Default must match default for path in actions/upload-pages-artifact.
default: "_site/"
include-branches:
description: If true, includes non-default branch publication to the "_branch/<branch_name>" path; ignored if include-pages is false.
required: false
default-branch:
description: Default branch for include-branches to filter; ignored if include-branches is false. Default is "main".
required: false
default: "main"
pages-archive:
description: Pages archive name; ignored if include-branches is false. Default is "_pages". Temporary directory with this name will be created during build and ZIP file with this name will be published to the root.
required: false
default: "_pages"

runs:
using: composite
Expand Down Expand Up @@ -58,8 +69,6 @@ runs:
echo "No scripts found."
GREP_RESULT=1
else
echo "$NPM_SCRIPTS"

# Check for package-defined build.
echo "$NPM_SCRIPTS" | grep -q "^ pandoc-spec-action$"
GREP_RESULT=$?
Expand Down Expand Up @@ -90,6 +99,85 @@ runs:
echo "Running pandoc-spec shell script"
pandoc-spec
fi

- name: Merge branches
if: inputs.include-pages == 'true' && inputs.include-branches == 'true' && github.ref_type == 'branch'
shell: bash
run: |
# Exit codes are handled by script.
set +e

host_name=$(echo "${{ github.event.repository.owner.name }}.github.io" | tr "[:upper:]" "[:lower:]")
repository_name="${{ github.event.repository.name }}"
lower_repository_name=$(echo "$repository_name" | tr "[:upper:]" "[:lower:]")

if [[ "$lower_repository_name" == "host_name" ]]
then
pages_url="https://$host_name"
else
pages_url="https://$host_name/$repository_name"
fi

pages_archive=${{ inputs.pages-archive }}

# Get and unzip GitHub Pages archive.
curl -s $pages_url/"$pages_archive".zip -o "$pages_archive".zip
if [[ $? -eq 0 ]]
then
unzip -qq "$pages_archive".zip -d "$pages_archive"
rm "$pages_archive".zip
else
# First time including branches. Treat current content as default branch; will be fixed on next push to default branch.
cp -r "${{ inputs.pages-path }}" "$pages_archive"/
fi

cd "$pages_archive"

if [[ -d _branch ]]
then
cd _branch

BRANCHES=$(git branch --remotes --format=%\(refname:lstrip=-1\))

ls | while read -r branch
do
# Check than branch still exists.
echo "BRANCHES" | grep -q "^$branch$"

if [[ $? -ne 0 ]]
then
# Branch no longer exists; delete from GitHub Pages.
rm -rf "$branch"
fi
done

cd ..
else
mkdir _branch
fi

branch=${{ github.ref_name }}

if [[ "$branch" == "${{ inputs.default-branch }}" ]]
then
# Move entire _branch directory.
mv _branch "../${{ inputs.pages-path }}/_branch"
else
# Remove previous branch content if it exists and replace it with newly generated content.
rm -rf "_branch/$branch"
mkdir "_branch/$branch"
mv "../${{ inputs.pages-path }}"/* "_branch/$branch"

# Move consolidated directory into place.
mv * "../${{ inputs.pages-path }}"
fi

cd "../${{ inputs.pages-path }}"

zip -q -r ../"$pages_archive" .
mv ../"$pages_archive".zip .

cd ..

- name: Configure GitHub Pages
if: inputs.include-pages == 'true'
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"sass": "sass --load-path=node_modules --quiet-deps --style=compressed pandoc/pandoc-spec.scss pandoc/pandoc-spec.css",
"sass-watch": "sass --watch --load-path=node_modules --quiet-deps pandoc/pandoc-spec.scss pandoc/pandoc-spec.css",
"build-dist": "npm run sass && tsup src/index.ts --format esm --dts --minify",
"pandoc-spec-local": "tsx bin/pandoc-spec-local $*"
"pandoc-spec-local": "tsx bin/pandoc-spec-local $*",
"pandoc-spec-action": "npm run sass && tsx bin/pandoc-spec-local"
},
"bin": {
"pandoc-spec": "bin/pandoc-spec"
Expand Down
2 changes: 1 addition & 1 deletion test/pandoc-spec.options.json → pandoc-spec.options.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"cssFiles": [
"index.css"
],
"outputDirectory": "test/_site",
"outputDirectory": "_site",
"cleanOutput": true,
"outputFile": "index.html"
}