├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | Thumbs.db 3 | db.json 4 | *.log 5 | node_modules/ 6 | public/ 7 | .deploy*/ 8 | yarn.lock 9 | package-lock.json 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | 23 | # misc 24 | /.sass-cache 25 | /connect.lock 26 | /coverage 27 | /libpeerconnection.log 28 | npm-debug.log 29 | testem.log 30 | /typings 31 | 32 | # e2e 33 | /e2e/src/*.js 34 | /e2e/src/*.map 35 | /cypress/screenshots 36 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Use Node.js container image 2 | FROM node:16 3 | 4 | # Install Git 5 | RUN apt-get update && apt-get install -y git 6 | 7 | # Copies your code file from your action repository to the filesystem path `/` of the container 8 | COPY entrypoint.sh /entrypoint.sh 9 | 10 | RUN chmod +x /entrypoint.sh 11 | 12 | # Code file to execute when the docker container starts up (`entrypoint.sh`) 13 | ENTRYPOINT ["/entrypoint.sh"] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 XPoet 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hexo Deploy GitHub Pages Action 2 | 3 | This GitHub action for building and deploying Hexo project to GitHub pages. 4 | 5 | ## Getting Started 6 | 7 | You can view an example of this below. 8 | 9 | ```yml 10 | name: Hexo Deploy GitHub Pages 11 | on: 12 | push: 13 | branches: 14 | - master 15 | jobs: 16 | build-and-deploy: 17 | runs-on: ubuntu-latest 18 | 19 | steps: 20 | - name: Checkout 21 | uses: actions/checkout@v3 22 | with: 23 | fetch-depth: 0 24 | 25 | - name: Build and Deploy 26 | uses: theme-keep/hexo-deploy-github-pages-action@master 27 | env: 28 | # Your GitHub Token 29 | PERSONAL_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | 31 | # The repository the action should deploy to 32 | PUBLISH_REPOSITORY: theme-keep/site 33 | ``` 34 | 35 | ## Configuration item 36 | 37 | The `env` portion of the workflow **must** be configured before the action will work. You can add these in the `env` section found in the examples above. Any `secrets` must be referenced using the bracket syntax and stored in the GitHub repositories `Settings / Secrets and variables / Actions` menu. You can learn more about setting environment variables with GitHub actions [here](https://help.github.com/en/articles/workflow-syntax-for-github-actions#jobsjob_idstepsenv). 38 | 39 | Below you'll find a description of what each option does. 40 | 41 | | Key | Value Information | Type | Default | Required | 42 | |----------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ------------- |---------| ------------- | 43 | | `PERSONAL_TOKEN` | Depending on the repository permissions you need to provide the action with a GitHub Personal Access Token in order to deploy. You can [learn more about how to generate one here](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line). **This should be stored as a secret**. | `secrets` | | **Yes** | 44 | | `PUBLISH_REPOSITORY` | The repository the action should deploy to. for example `theme-keep/site` | `env` | | **Yes** | 45 | | `BRANCH` | The branch the action should deploy to. for example `master` | `env` | `gh-pages` | No | 46 | | `PUBLISH_DIR` | The folder the action should deploy. for example `./public` | `env` | `./public` | No | 47 | | `CNAME` | The domain name of your GitHub Page specified in a CNAME | `env` | | No | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Hexo Deploy GitHub Pages Action' 2 | description: 'This GitHub action for building and deploying a Hexo project to GitHub pages.' 3 | author: 'XPoet' 4 | runs: 5 | using: 'docker' 6 | image: 'Dockerfile' 7 | branding: 8 | icon: 'git-commit' 9 | color: 'blue' 10 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -l 2 | 3 | set -e 4 | 5 | # Check values 6 | 7 | if [ -n "${PUBLISH_REPOSITORY}" ]; then 8 | TARGET_REPOSITORY=${PUBLISH_REPOSITORY} 9 | else 10 | TARGET_REPOSITORY=${GITHUB_REPOSITORY} 11 | fi 12 | 13 | if [ -n "${BRANCH}" ]; then 14 | TARGET_BRANCH=${BRANCH} 15 | else 16 | TARGET_BRANCH="gh-pages" 17 | fi 18 | 19 | if [ -n "${PUBLISH_DIR}" ]; then 20 | TARGET_PUBLISH_DIR=${PUBLISH_DIR} 21 | else 22 | TARGET_PUBLISH_DIR="./public" 23 | fi 24 | 25 | if [ -z "$PERSONAL_TOKEN" ] 26 | then 27 | echo "You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy." 28 | exit 1 29 | fi 30 | 31 | REPOSITORY_PATH="https://x-access-token:${PERSONAL_TOKEN}@github.com/${TARGET_REPOSITORY}.git" 32 | 33 | 34 | # Start deploy 35 | 36 | echo ">_ Start deploy to ${TARGET_REPOSITORY}" 37 | 38 | git config --global core.quotepath false 39 | git config --global --add safe.directory /github/workspace 40 | 41 | cd "${GITHUB_WORKSPACE}" 42 | 43 | 44 | # Set post's update date to the timestamp of the most recent Git commit 45 | 46 | find source/_posts -name "*.md" | while read file; do 47 | timestamp=$(git log -1 --format="%ct" "$file") 48 | formatted_timestamp=$(date -u -d "@$timestamp" "+%Y%m%d%H%M.%S") 49 | touch -t "$formatted_timestamp" "$file" 50 | done 51 | 52 | 53 | echo ">_ Install NPM dependencies ..." 54 | npm install 55 | 56 | echo ">_ Clean cache files ..." 57 | npx hexo clean 58 | 59 | echo ">_ Generate file ..." 60 | npx hexo generate 61 | 62 | cd "${TARGET_PUBLISH_DIR}" 63 | 64 | CURRENT_DIR=$(pwd) 65 | 66 | if [ -n "${CNAME}" ]; then 67 | echo ${CNAME} > CNAME 68 | fi 69 | 70 | # Configures Git 71 | 72 | echo ">_ Config git ..." 73 | 74 | git init 75 | git config --global user.name "${GITHUB_ACTOR}" 76 | git config --global user.email "${GITHUB_ACTOR}@users.noreply.github.com" 77 | git config --global --add safe.directory "${CURRENT_DIR}" 78 | 79 | git remote add origin "${REPOSITORY_PATH}" 80 | git checkout --orphan "${TARGET_BRANCH}" 81 | 82 | git add . 83 | 84 | echo '>_ Start Commit ...' 85 | git commit --allow-empty -m "Build and Deploy from Github Actions" 86 | 87 | echo '>_ Start Push ...' 88 | git push -u origin "${TARGET_BRANCH}" --force 89 | 90 | echo ">_ Deployment successful" --------------------------------------------------------------------------------