Skip to content

Commit 3890823

Browse files
feat(gh-pages)!: reduce gh-pages history and size
1 parent 542df46 commit 3890823

1 file changed

Lines changed: 46 additions & 1 deletion

File tree

.github/workflows/jekyll-build.yml

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ permissions: {}
55
on:
66
workflow_call:
77
inputs:
8+
amend:
9+
description: 'Amend the current deployment commit instead of creating a new commit'
10+
required: false
11+
default: true
12+
type: boolean
813
site_artifact:
914
description: 'Artifact name to download'
1015
required: false
@@ -32,6 +37,16 @@ on:
3237
required: false
3338
default: true
3439
type: boolean
40+
force:
41+
description: 'Force-push the deployment branch'
42+
required: false
43+
default: true
44+
type: boolean
45+
squash_history:
46+
description: 'Replace existing deployment history with a single commit, then amend it on future deployments'
47+
required: false
48+
default: true
49+
type: boolean
3550
theme_ref:
3651
description: 'Branch, tag, or commit SHA of the theme repository to use'
3752
required: false
@@ -60,11 +75,14 @@ on:
6075
required: true
6176

6277
env:
78+
INPUT_AMEND: ${{ inputs.amend }}
6379
INPUT_SITE_ARTIFACT: ${{ inputs.site_artifact }}
6480
INPUT_EXTRACT_ARCHIVE: ${{ inputs.extract_archive }}
6581
INPUT_CONFIG_FILE: ${{ inputs.config_file }}
6682
INPUT_TARGET_BRANCH: ${{ inputs.target_branch }}
6783
INPUT_CLEAN_GH_PAGES: ${{ inputs.clean_gh_pages }}
84+
INPUT_FORCE: ${{ inputs.force }}
85+
INPUT_SQUASH_HISTORY: ${{ inputs.squash_history }}
6886
INPUT_THEME_REF: ${{ inputs.theme_ref }}
6987
INPUT_BASE_URL: ${{ inputs.base_url }}
7088

@@ -251,6 +269,32 @@ jobs:
251269
fetch-depth: 0 # otherwise, will fail to push refs to dest repo
252270
filter: blob:none
253271

272+
- name: Prepare deployment history
273+
id: deployment-history
274+
working-directory: gh-pages
275+
env:
276+
AMEND: ${{ inputs.amend }}
277+
FORCE: ${{ inputs.force }}
278+
SQUASH_HISTORY: ${{ inputs.squash_history }}
279+
run: |
280+
amend="${AMEND}"
281+
282+
if [[ "${FORCE}" != "true" ]] &&
283+
{ [[ "${AMEND}" == "true" ]] || [[ "${SQUASH_HISTORY}" == "true" ]]; }; then
284+
echo "::error::force must be enabled when amend or squash_history is enabled."
285+
exit 1
286+
fi
287+
288+
if [[ "${SQUASH_HISTORY}" == "true" ]]; then
289+
commit_count="$(git rev-list --count HEAD)"
290+
if ((commit_count > 1)) || [[ "${AMEND}" != "true" ]]; then
291+
git checkout --orphan deployment
292+
amend=false
293+
fi
294+
fi
295+
296+
echo "amend=${amend}" >> "${GITHUB_OUTPUT}"
297+
254298
# empty contents of gh-pages
255299
- name: Clean
256300
if: env.INPUT_CLEAN_GH_PAGES == 'true'
@@ -277,5 +321,6 @@ jobs:
277321
author_name: ${{ inputs.gh_bot_name }}
278322
directory: gh-pages
279323
branch: ${{ env.INPUT_TARGET_BRANCH }}
280-
force: false
324+
amend: ${{ steps.deployment-history.outputs.amend }}
325+
force: ${{ inputs.force }}
281326
message: "Deploy site from ${{ github.sha }}"

0 commit comments

Comments
 (0)