-
Notifications
You must be signed in to change notification settings - Fork 2
/
action.yml
65 lines (55 loc) · 2.92 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
name: GitHub Pages Overwriter
author: rayluo
# Description needs to be shorter than 125 bytes.
description: Overwrite your Github Pages branch with content of current workdir, thus deploy/publish without polluting your repo history.
inputs:
source-directory:
description: The name of the source directory that you wish it to become the wwwroot of your website
required: false
default: .
target-branch:
description: The name of the branch that would be REMOVED and replaced by the content of current workdir, you will then configure your Github Pages to serve this branch.
required: false
default: gh-pages
runs:
using: composite
steps:
- shell: bash
run: |
# The following 2 lines are not really necessary,
# because we do not intend to push current branch.
# But we choose to use target branch name as a temporary local work branch,
# thus avoid a potential error of committing to the trigger branch.
git branch -f ${{ inputs.target-branch }} HEAD
git checkout ${{ inputs.target-branch }}
# The commit and push happen to work without authentication
# https://docs.github.com/en/actions/reference/authentication-in-a-workflow
git config user.name "Github Pages Overwriter"
git config user.email "GithubPagesOverwriter@users.noreply.github.com"
# The previous commit message may contain reference to github issues,
# we wipe it out, so that it won't show up in the inevitable duplicate commit.
git commit --amend -m "This commit will be automatically published"
# Generate such a new file to make sure the subsequent commit would succeed
# Such a file WITHOUT leading dot (.) is also visible in outcome website.
# FYI: filename with leading dot (.) or underscore (_) would be ignored by Jekyll,
# which Github Pages depends on. So we use a normal filename here.
date > ${{ inputs.source-directory}}/publish_date.txt
git add --force ${{ inputs.source-directory }}
git commit -m "Automated publish"
- name: Push the build output to github pages
shell: bash
##if: ${{ inputs.source-directory == '.' }}
# Astonishedly, the "if" command does not work in an action shipped to marketplace,
# so that there is even a 3rd-party github action to do that
# (https://github.com/marketplace/actions/conditional-value-for-github-action)
# But that seems like an overkill. So, we'd use "if" in bash instead.
run: > # https://yaml-multiline.info/
if [ "${{ inputs.source-directory }}" == "." ]; then
git push -f origin HEAD:refs/heads/${{ inputs.target-branch }}
else
# Inspired from https://gist.github.com/cobyism/4730490#gistcomment-1374989
git push -f origin `git subtree split -P ${{ inputs.source-directory }}`:refs/heads/${{ inputs.target-branch }}
fi
branding:
icon: copy
color: green