Skip to content

Commit 3f5d6a3

Browse files
Merge pull request #13 from LegReq/multibranch
Added multibranch support
2 parents f5f7ba9 + 8d56e0f commit 3f5d6a3

File tree

5 files changed

+114
-5
lines changed

5 files changed

+114
-5
lines changed

.github/workflows/push.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Push to any branch
2+
3+
on:
4+
push
5+
6+
permissions:
7+
id-token: write
8+
pages: write
9+
10+
jobs:
11+
push:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- name: Pandoc specification builder
16+
uses: legreq/pandoc-spec@multibranch
17+
with:
18+
include-repository: true
19+
include-pages: true
20+
include-branches: true

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/package-lock.json
22
/dist/
3+
/_site/
34
/node_modules/
45
/pandoc/pandoc-spec.css
56
/pandoc/pandoc-spec.css.map
6-
/test/_site/

action.yml

Lines changed: 90 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ inputs:
1616
required: false
1717
# Default must match default for path in actions/upload-pages-artifact.
1818
default: "_site/"
19+
include-branches:
20+
description: If true, includes non-default branch publication to the "_branch/<branch_name>" path; ignored if include-pages is false.
21+
required: false
22+
default-branch:
23+
description: Default branch for include-branches to filter; ignored if include-branches is false. Default is "main".
24+
required: false
25+
default: "main"
26+
pages-archive:
27+
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.
28+
required: false
29+
default: "_pages"
1930

2031
runs:
2132
using: composite
@@ -58,8 +69,6 @@ runs:
5869
echo "No scripts found."
5970
GREP_RESULT=1
6071
else
61-
echo "$NPM_SCRIPTS"
62-
6372
# Check for package-defined build.
6473
echo "$NPM_SCRIPTS" | grep -q "^ pandoc-spec-action$"
6574
GREP_RESULT=$?
@@ -90,6 +99,85 @@ runs:
9099
echo "Running pandoc-spec shell script"
91100
pandoc-spec
92101
fi
102+
103+
- name: Merge branches
104+
if: inputs.include-pages == 'true' && inputs.include-branches == 'true' && github.ref_type == 'branch'
105+
shell: bash
106+
run: |
107+
# Exit codes are handled by script.
108+
set +e
109+
110+
host_name=$(echo "${{ github.event.repository.owner.name }}.github.io" | tr "[:upper:]" "[:lower:]")
111+
repository_name="${{ github.event.repository.name }}"
112+
lower_repository_name=$(echo "$repository_name" | tr "[:upper:]" "[:lower:]")
113+
114+
if [[ "$lower_repository_name" == "host_name" ]]
115+
then
116+
pages_url="https://$host_name"
117+
else
118+
pages_url="https://$host_name/$repository_name"
119+
fi
120+
121+
pages_archive=${{ inputs.pages-archive }}
122+
123+
# Get and unzip GitHub Pages archive.
124+
curl -s $pages_url/"$pages_archive".zip -o "$pages_archive".zip
125+
if [[ $? -eq 0 ]]
126+
then
127+
unzip -qq "$pages_archive".zip -d "$pages_archive"
128+
rm "$pages_archive".zip
129+
else
130+
# First time including branches. Treat current content as default branch; will be fixed on next push to default branch.
131+
cp -r "${{ inputs.pages-path }}" "$pages_archive"/
132+
fi
133+
134+
cd "$pages_archive"
135+
136+
if [[ -d _branch ]]
137+
then
138+
cd _branch
139+
140+
BRANCHES=$(git branch --remotes --format=%\(refname:lstrip=-1\))
141+
142+
ls | while read -r branch
143+
do
144+
# Check than branch still exists.
145+
echo "BRANCHES" | grep -q "^$branch$"
146+
147+
if [[ $? -ne 0 ]]
148+
then
149+
# Branch no longer exists; delete from GitHub Pages.
150+
rm -rf "$branch"
151+
fi
152+
done
153+
154+
cd ..
155+
else
156+
mkdir _branch
157+
fi
158+
159+
branch=${{ github.ref_name }}
160+
161+
if [[ "$branch" == "${{ inputs.default-branch }}" ]]
162+
then
163+
# Move entire _branch directory.
164+
mv _branch "../${{ inputs.pages-path }}/_branch"
165+
else
166+
# Remove previous branch content if it exists and replace it with newly generated content.
167+
rm -rf "_branch/$branch"
168+
mkdir "_branch/$branch"
169+
mv "../${{ inputs.pages-path }}"/* "_branch/$branch"
170+
171+
# Move consolidated directory into place.
172+
mv * "../${{ inputs.pages-path }}"
173+
fi
174+
175+
cd "../${{ inputs.pages-path }}"
176+
177+
zip -q -r ../"$pages_archive" .
178+
mv ../"$pages_archive".zip .
179+
180+
cd ..
93181
94182
- name: Configure GitHub Pages
95183
if: inputs.include-pages == 'true'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
"sass": "sass --load-path=node_modules --quiet-deps --style=compressed pandoc/pandoc-spec.scss pandoc/pandoc-spec.css",
2929
"sass-watch": "sass --watch --load-path=node_modules --quiet-deps pandoc/pandoc-spec.scss pandoc/pandoc-spec.css",
3030
"build-dist": "npm run sass && tsup src/index.ts --format esm --dts --minify",
31-
"pandoc-spec-local": "tsx bin/pandoc-spec-local $*"
31+
"pandoc-spec-local": "tsx bin/pandoc-spec-local $*",
32+
"pandoc-spec-action": "npm run sass && tsx bin/pandoc-spec-local"
3233
},
3334
"bin": {
3435
"pandoc-spec": "bin/pandoc-spec"
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"cssFiles": [
2525
"index.css"
2626
],
27-
"outputDirectory": "test/_site",
27+
"outputDirectory": "_site",
2828
"cleanOutput": true,
2929
"outputFile": "index.html"
3030
}

0 commit comments

Comments
 (0)