├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── test.yml ├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Files to exclude when creating archive 2 | .github\workflows\test.yml export-ignore 3 | 4 | # Auto detect text files and perform LF normalization 5 | * text=auto 6 | -------------------------------------------------------------------------------- /.github/workflows/test.yml: -------------------------------------------------------------------------------- 1 | name: test 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | 8 | jobs: 9 | build-and-deploy: 10 | runs-on: ubuntu-latest 11 | 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v3 15 | 16 | - name: Build 17 | run: | 18 | mkdir -p www/_site 19 | cat > www/_site/index.html < 21 | 22 | 23 | GH Pages deploy 24 | 25 | 26 |

GitHub Pages with ${{ github.sha }} commit ID has been deployed through GH Pages deploy.

27 | 28 | 29 | EOL 30 | 31 | - name: Deploy 32 | id: deploy 33 | if: success() 34 | uses: ./ 35 | env: 36 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 37 | with: 38 | email: arnaud@ligny.org 39 | build_dir: www/_site/ 40 | 41 | - name: Deploy result 42 | run: echo ${{ steps.deploy.outputs.result }} 43 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM alpine/git:latest 2 | 3 | ADD entrypoint.sh / 4 | RUN chmod +x /entrypoint.sh 5 | ENTRYPOINT ["/entrypoint.sh"] 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Arnaud Ligny 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 | # GitHub Pages deploy 2 | 3 | This Action deploys a static site on GitHub Pages. 4 | 5 | [![test](https://github.com/Cecilapp/GitHub-Pages-deploy/workflows/test/badge.svg)](https://github.com/Cecilapp/GitHub-Pages-deploy/actions?query=workflow%3Atest) 6 | 7 | ## Usage 8 | 9 | See [action.yml](action.yml). 10 | 11 | ```yml 12 | - name: Deploy to GitHub Pages 13 | uses: Cecilapp/GitHub-Pages-deploy@v3 14 | env: 15 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 16 | with: 17 | email: username@domain.tld 18 | build_dir: _site # optional 19 | branch: website # optional 20 | cname: domain.tld # optional 21 | jekyll: no # optional 22 | commit_message: custom message # optional 23 | ``` 24 | 25 | ### v2 VS v3 26 | 27 | > _GitHub Pages deploy_ v3 use the [`secrets.GITHUB_TOKEN`](https://docs.github.com/en/free-pro-team@latest/actions/reference/authentication-in-a-workflow) instead of a [personal access token](https://docs.github.com/en/free-pro-team@latest/github/authenticating-to-github/creating-a-personal-access-token) (PAT), and [inputs parameters](https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-syntax-for-github-actions#jobsjob_idstepswith) instead of environment variables. 28 | > If you want to continue using the previous release (with environment variables) you must set the version: [`Cecilapp/GitHub-Pages-deploy@v2`](https://github.com/marketplace/actions/gh-pages-deploy?version=2.0.1). 29 | 30 | ### Workflow example 31 | 32 | ```yml 33 | name: GitHub Pages deploy 34 | on: 35 | push: 36 | branches: 37 | - master 38 | 39 | jobs: 40 | build-and-deploy: 41 | runs-on: ubuntu-latest 42 | 43 | steps: 44 | - name: Checkout 45 | uses: actions/checkout@v3 46 | 47 | - name: Build 48 | uses: # build your static site 49 | 50 | - name: Deploy to GitHub Pages 51 | uses: Cecilapp/GitHub-Pages-deploy@v3 52 | env: 53 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 54 | with: 55 | email: username@domain.tld 56 | build_dir: _site 57 | ``` 58 | 59 | ## About _user_ and _organization_ sites 60 | 61 | > The default publishing source for user and organization sites is the root of the default branch for the repository. 62 | 63 | See [documentation](https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages/about-github-pages#publishing-sources-for-github-pages-sites). 64 | 65 | ## License 66 | 67 | _GitHub Pages deploy_ is a free software distributed under the terms of the MIT license. 68 | 69 | © [Arnaud Ligny](https://arnaudligny.fr) 70 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'GH Pages deploy' 2 | description: 'This deploys a static site on GitHub Pages.' 3 | author: 'Arnaud Ligny' 4 | inputs: 5 | email: 6 | description: 'A verified email.' 7 | required: true 8 | build_dir: 9 | description: 'Where static files are.' 10 | required: false 11 | default: '_site' 12 | branch: 13 | description: 'Which branch to push files.' 14 | required: false 15 | cname: 16 | description: 'The custom domain name.' 17 | required: false 18 | jekyll: 19 | description: '`yes` in case of a Jekyll site.' 20 | required: false 21 | default: 'no' 22 | commit_message: 23 | description: 'A custom commit message.' 24 | required: false 25 | outputs: 26 | result: 27 | description: 'The deploy result' 28 | branding: 29 | icon: 'upload-cloud' 30 | color: 'black' 31 | runs: 32 | using: 'docker' 33 | image: 'Dockerfile' 34 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | set -e 3 | 4 | # Which branch? 5 | REPONAME="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 2)" 6 | OWNER="$(echo $GITHUB_REPOSITORY| cut -d'/' -f 1)" 7 | GHIO="${OWNER}.github.io" 8 | if [[ "$REPONAME" == "$GHIO" ]]; then 9 | TARGET_BRANCH="master" 10 | else 11 | TARGET_BRANCH="gh-pages" 12 | fi 13 | # Custom branch 14 | if [ ! -z "$INPUT_BRANCH" ]; then 15 | TARGET_BRANCH=$INPUT_BRANCH 16 | fi 17 | 18 | echo "Starting deploy to $GITHUB_REPOSITORY/$TARGET_BRANCH" 19 | 20 | echo "Configuration:" 21 | echo "- email: $INPUT_EMAIL" 22 | echo "- build_dir: $INPUT_BUILD_DIR" 23 | echo "- cname: $INPUT_CNAME" 24 | echo "- Jekyll: $INPUT_JEKYLL" 25 | 26 | # Prepare build_dir 27 | BUILD_DIR=$INPUT_BUILD_DIR 28 | BUILD_DIR=${BUILD_DIR%/} # remove the ending slash if exists 29 | mkdir -p $HOME/build/$BUILD_DIR 30 | cp -R $BUILD_DIR/* $HOME/build/$BUILD_DIR/ 31 | 32 | # Create or clone the gh-pages repo 33 | mkdir -p $HOME/branch/ 34 | cd $HOME/branch/ 35 | git config --global user.name "$GITHUB_ACTOR" 36 | git config --global user.email "$INPUT_EMAIL" 37 | if [ -z "$(git ls-remote --heads https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git ${TARGET_BRANCH})" ]; then 38 | echo "Create branch '${TARGET_BRANCH}'" 39 | git clone --quiet https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git $TARGET_BRANCH > /dev/null 40 | cd $TARGET_BRANCH 41 | git checkout --orphan $TARGET_BRANCH 42 | git rm -rf . 43 | echo "$REPONAME" > README.md 44 | git add README.md 45 | git commit -a -m "Create '$TARGET_BRANCH' branch" 46 | git push origin $TARGET_BRANCH 47 | cd .. 48 | else 49 | echo "Clone branch '${TARGET_BRANCH}'" 50 | git clone --quiet --branch=$TARGET_BRANCH https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git $TARGET_BRANCH > /dev/null 51 | fi 52 | 53 | # Sync repository with build_dir 54 | cp -R $TARGET_BRANCH/.git $HOME/build/$BUILD_DIR/.git 55 | rm -rf $TARGET_BRANCH/* 56 | cp -R $HOME/build/$BUILD_DIR/.git $TARGET_BRANCH/.git 57 | # Copy files 58 | cd $TARGET_BRANCH 59 | cp -Rf $HOME/build/$BUILD_DIR/* . 60 | 61 | # Custom domain 62 | if [ ! -z "$INPUT_CNAME" ]; then 63 | echo "$INPUT_CNAME" > CNAME 64 | fi 65 | 66 | # Custom commit message 67 | if [ -z "$INPUT_COMMIT_MESSAGE" ] 68 | then 69 | INPUT_COMMIT_MESSAGE="$GITHUB_ACTOR published a site update" 70 | fi 71 | 72 | # .nojekyll 73 | if [ "$INPUT_JEKYLL" != "yes" ]; then 74 | touch .nojekyll 75 | fi 76 | 77 | # Deploy/Push (or not?) 78 | if [ -z "$(git status --porcelain)" ]; then 79 | result="Nothing to deploy" 80 | else 81 | git add -Af . 82 | git commit -m "$INPUT_COMMIT_MESSAGE" 83 | git push -fq origin $TARGET_BRANCH > /dev/null 84 | # push is OK? 85 | if [ $? = 0 ] 86 | then 87 | result="Deploy succeeded" 88 | else 89 | result="Deploy failed" 90 | fi 91 | fi 92 | 93 | # Set output 94 | echo $result 95 | echo "result=$result" >> $GITHUB_OUTPUT 96 | --------------------------------------------------------------------------------