feat: Add TypeScript Action (#83)

cf. https://github.com/peaceiris/actions-github-pages
Close #54
This commit is contained in:
Shohei Ueda 2020-02-05 14:34:19 +09:00 committed by GitHub
parent 28b05fd3fa
commit 68b21c12af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 9269 additions and 241 deletions

View File

@ -1,10 +1,9 @@
version: 1
update_configs:
- package_manager: "docker"
- package_manager: "javascript"
directory: "/"
update_schedule: "daily"
default_labels:
- "dependencies"
- "docker"
commit_message:
prefix: "deps"

View File

@ -1,7 +1,2 @@
.git
.github
.hadolint.yaml
LICENSE
README.md
action.yml
images
.*
*

13
.editorconfig Normal file
View File

@ -0,0 +1,13 @@
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
trim_trailing_whitespace = true
[Makefile]
indent_size = 4
indent_style = tab

3
.envrc Normal file
View File

@ -0,0 +1,3 @@
nvmrc=~/.nvm/nvm.sh
source $nvmrc
nvm use

24
.eslintrc.json Normal file
View File

@ -0,0 +1,24 @@
{
"env": {
"commonjs": true,
"es6": true,
"node": true
},
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:jest/recommended"
],
"globals": {
"Atomics": "readonly",
"SharedArrayBuffer": "readonly"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2019
},
"rules": {
}
}

View File

@ -1,40 +0,0 @@
name: docker image ci
on:
pull_request:
types: [opened, synchronize]
paths-ignore:
- '**.md'
push:
paths-ignore:
- '**.md'
branches:
- master
jobs:
test:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: build
env:
DOCKER_IMAGE: docker.pkg.github.com/${{ github.repository }}/action:latest
run: |
docker build . --file Dockerfile --tag ${DOCKER_IMAGE}
shellcheck:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: shellcheck
run: shellcheck ./entrypoint.sh
hadolint:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: brew install hadolint
- run: hadolint ./Dockerfile

37
.github/workflows/release.yml vendored Normal file
View File

@ -0,0 +1,37 @@
name: Release
on:
push:
tags:
- 'v3.*.*'
jobs:
release:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "${GITHUB_CONTEXT}"
- name: Install github/hub
run: |
export HUB_VERSION="2.14.1"
curl -fsSL https://github.com/github/hub/raw/40e421edd2c63d57bb8daa4bb9bbdfa21e8becf9/script/get | bash -s "${HUB_VERSION}"
- name: Create release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG_NAME="${GITHUB_REF##refs/tags/}"
echo "See [CHANGELOG.md](https://github.com/${GITHUB_REPOSITORY}/blob/${TAG_NAME}/CHANGELOG.md) for more details." > ./release_notes.md
RELEASE_NAME="$(jq -r '.name' ./package.json)"
sed -i "1i${RELEASE_NAME} ${TAG_NAME}\n" ./release_notes.md
./bin/hub release create \
--draft \
--prerelease \
--file ./release_notes.md \
"${TAG_NAME}"

86
.github/workflows/test-action.yml vendored Normal file
View File

@ -0,0 +1,86 @@
name: Test Action
on:
push:
branches:
- master
paths-ignore:
- '*.md'
pull_request:
types:
- opened
- synchronize
paths-ignore:
- '*.md'
jobs:
skipci:
runs-on: ubuntu-18.04
steps:
- run: echo "[Skip CI] ${{ contains(github.event.head_commit.message, '[skip ci]') }}"
test:
runs-on: ${{ matrix.os }}
if: contains(github.event.head_commit.message, '[skip ci]') == false
strategy:
matrix:
os:
- 'ubuntu-18.04'
# - 'macos-latest'
# - 'windows-latest'
steps:
- uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "::set-output name=NVMRC::$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- run: npm ci
- run: npm run build
- name: Setup mdBook
uses: peaceiris/actions-mdbook@v1
with:
mdbook-version: '0.3.5'
- name: Build
working-directory: ./test_projects/mdbook
run: mdbook build
- name: Prepare tag
id: prepare_tag
if: startsWith(github.ref, 'refs/tags/')
run: |
TAG_NAME="${GITHUB_REF##refs/tags/}"
echo "::set-output name=tag_name::${TAG_NAME}"
echo "::set-output name=deploy_tag_name::deploy-${TAG_NAME}"
- name: Deploy
uses: ./
with:
deploy_key: ${{ secrets.ACTIONS_DEPLOY_KEY }}
# github_token: ${{ secrets.GITHUB_TOKEN }}
# publish_branch: master
publish_dir: ./test_projects/mdbook/book
# external_repository: ''
allow_empty_commit: true
# keep_files: true
force_orphan: true
# user_name: iris
# user_email: email@peaceiris.com
# commit_message: ${{ github.event.head_commit.message }}
# tag_name: ${{ steps.prepare_tag.outputs.deploy_tag_name }}
# tag_message: 'Deployment ${{ steps.prepare_tag.outputs.tag_name }}'
# - name: Deploy v2
# uses: peaceiris/actions-gh-pages@v2
# env:
# ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
# PUBLISH_BRANCH: gh-pages
# PUBLISH_DIR: ./test_projects/mdbook/book

64
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,64 @@
name: 'Test'
on:
push:
branches:
- master
paths-ignore:
- '*.md'
pull_request:
types:
- opened
- synchronize
paths-ignore:
- '*.md'
jobs:
skipci:
runs-on: ubuntu-18.04
steps:
- run: echo "[Skip CI] ${{ contains(github.event.head_commit.message, '[skip ci]') }}"
test:
runs-on: ${{ matrix.os }}
if: contains(github.event.head_commit.message, '[skip ci]') == false
strategy:
matrix:
os:
- 'ubuntu-18.04'
- 'macos-latest'
- 'windows-latest'
steps:
- uses: actions/checkout@v2
- name: Read .nvmrc
run: echo "::set-output name=NVMRC::$(cat .nvmrc)"
id: nvm
- name: Setup Node
uses: actions/setup-node@v1
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- run: npm ci
- name: Run prettier
if: startsWith(matrix.os, 'ubuntu')
run: npm run format:check
- name: Run eslint
if: startsWith(matrix.os, 'ubuntu')
run: npm run lint
- name: Run ncc
if: startsWith(matrix.os, 'ubuntu')
run: npm run build
- run: npm test
- name: Upload test coverage as artifact
uses: actions/upload-artifact@v1
with:
name: coverage
path: coverage

View File

@ -19,6 +19,5 @@ jobs:
git remote set-url origin "https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}.git"
export TAG_NAME="${GITHUB_REF##refs/tags/}"
export TAG_MAJOR="${TAG_NAME%%.*}"
git tag "${TAG_MAJOR}" -m "Release ${TAG_NAME}" || git tag -d "${TAG_MAJOR}" ; git push --delete origin "${TAG_MAJOR}"
git tag "${TAG_MAJOR}" -m "Release ${TAG_NAME}" || true
git push origin "${TAG_MAJOR}"
git tag --force -a "${TAG_MAJOR}" -m "Release ${TAG_NAME}"
git push --force origin "${TAG_MAJOR}"

5
.gitignore vendored
View File

@ -1 +1,6 @@
.DS_Store
coverage
.npm
.eslintcache
.env
node_modules

View File

@ -1,2 +0,0 @@
ignored:
- DL3018

1
.npmrc Normal file
View File

@ -0,0 +1 @@
engine-strict=true

1
.nvmrc Normal file
View File

@ -0,0 +1 @@
12.14.1

11
.prettierrc.json Normal file
View File

@ -0,0 +1,11 @@
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": true,
"singleQuote": true,
"trailingComma": "none",
"bracketSpacing": false,
"arrowParens": "avoid",
"parser": "typescript"
}

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"git.ignoreLimitWarning": true
}

283
CHANGELOG.md Normal file
View File

@ -0,0 +1,283 @@
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
## [3.1.12](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.11...v3.1.12) (2020-02-05)
### fix
* add new line, ssh-keyscan comment ([1333ef6](https://github.com/peaceiris/actions-gh-pages/commit/1333ef6f810edd7fd42a56b786be33553dcbb45a))
## [3.1.11](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.10...v3.1.11) (2020-02-05)
### fix
* ssh-agent ([4fce94b](https://github.com/peaceiris/actions-gh-pages/commit/4fce94b01d6ac5a2ad6f1599c32e4060ed8b5936))
## [3.1.10](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.9...v3.1.10) (2020-02-05)
### fix
* change writeFile to writeFileSync ([57d9579](https://github.com/peaceiris/actions-gh-pages/commit/57d9579cc71fe2a71e82a47ce2b7ad990db16406))
## [3.1.9](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.8...v3.1.9) (2020-02-05)
### fix
* Add chmod 600 known_hosts ([24a9ba2](https://github.com/peaceiris/actions-gh-pages/commit/24a9ba28d32d735d348f3c82914ac0f9216a8e12))
## [3.1.8](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.7...v3.1.8) (2020-02-04)
### fix
* add trim() ([7d8f676](https://github.com/peaceiris/actions-gh-pages/commit/7d8f676353dd2ed195b94ff31580ee91796e5214))
## [3.1.7](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.6...v3.1.7) (2020-02-04)
## [3.1.6](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.5...v3.1.6) (2020-02-04)
## [3.1.5](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.4...v3.1.5) (2020-02-04)
### fix
* 400 to 600 ([e2d8266](https://github.com/peaceiris/actions-gh-pages/commit/e2d8266ff7ce8f641ac66436e895b1b4d705a4cf))
## [3.1.4](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.3...v3.1.4) (2020-02-04)
### fix
* github ([4e0ba00](https://github.com/peaceiris/actions-gh-pages/commit/4e0ba002422edc2c4e61aefd3ac1e478d23afff7))
## [3.1.3](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.2...v3.1.3) (2020-02-04)
### fix
* add await ([8f3dfcb](https://github.com/peaceiris/actions-gh-pages/commit/8f3dfcbfc2b7294aed82f40ce3b8cd277b927a80))
* add await ([8a3c589](https://github.com/peaceiris/actions-gh-pages/commit/8a3c58984088ea08b176dd81eb35f8bd3895a146))
* add eval SSH_AUTH_SOCK=/var/folders/kq/plr51cwn7ql9dh5m035_2fsh0000gn/T//ssh-iXC8tDO67Brj/agent.73139; export SSH_AUTH_SOCK; ([06e73f4](https://github.com/peaceiris/actions-gh-pages/commit/06e73f4286867c4fe3e3b8d48b70db1d9d33f608))
* add sh -c 'eval SSH_AUTH_SOCK=/var/folders/kq/plr51cwn7ql9dh5m035_2fsh0000gn/T//ssh-BEHc8SfUWzKd/agent.74533; export SSH_AUTH_SOCK; ([114d174](https://github.com/peaceiris/actions-gh-pages/commit/114d17483f85fbf60a92972c969cd49d799abe59))
* add sh -c eval SSH_AUTH_SOCK=/var/folders/kq/plr51cwn7ql9dh5m035_2fsh0000gn/T//ssh-LTfBLKFbp39Z/agent.73455; export SSH_AUTH_SOCK; ([df63091](https://github.com/peaceiris/actions-gh-pages/commit/df630915f2c1a31ee3acb55420294ad5dd1e089e))
* add SSH_AUTH_SOCK ([fb0c9f1](https://github.com/peaceiris/actions-gh-pages/commit/fb0c9f1ebc41727c6205c50f667e907bbd824888))
* Add ssh-add ([c19aace](https://github.com/peaceiris/actions-gh-pages/commit/c19aace6828eaccbf0f2516053ad172704608b72))
* cpexec ([30e98db](https://github.com/peaceiris/actions-gh-pages/commit/30e98dba8efdbd38275f0a7ceb49d6e1449f2dca))
* cpexec ([63697ad](https://github.com/peaceiris/actions-gh-pages/commit/63697adefcc1762fcb07102a858a895b7e435fca))
* eval ([d696db2](https://github.com/peaceiris/actions-gh-pages/commit/d696db2c8d77159fcb9ef211abb489c757f3a85e))
* ssh-agent ([9406f9d](https://github.com/peaceiris/actions-gh-pages/commit/9406f9d108a44c5e0a90b41c5817f84ac9ba7006))
* ssh-agent ([db62914](https://github.com/peaceiris/actions-gh-pages/commit/db6291436b37e56847cee67374247477113d6c43))
## [3.1.2](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.1...v3.1.2) (2020-02-04)
### fix
* ssh config ([5d7baea](https://github.com/peaceiris/actions-gh-pages/commit/5d7baea212a39da311412fb263b5ae473025d80d))
## [3.1.1](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0...v3.1.1) (2020-02-04)
### fix
* externalRepository commit message ([3438ab5](https://github.com/peaceiris/actions-gh-pages/commit/3438ab53a11067fd38f0a0491ed0c67b61c1ecc1))
# [3.1.0](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0-2...v3.1.0) (2020-02-04)
### chore
* Add engines field ([f27f5d1](https://github.com/peaceiris/actions-gh-pages/commit/f27f5d17579b2cd9497bb90de673e5bf68683db3)), closes [#12](https://github.com/peaceiris/actions-gh-pages/issues/12)
* Add latest git (#14) ([cba55a7](https://github.com/peaceiris/actions-gh-pages/commit/cba55a7c9634dfaf3fa0f879f28481c775acd022)), closes [#14](https://github.com/peaceiris/actions-gh-pages/issues/14) [#6](https://github.com/peaceiris/actions-gh-pages/issues/6)
### deps
* bump @types/node from 13.5.0 to 13.5.1 (#13) ([0e5e067](https://github.com/peaceiris/actions-gh-pages/commit/0e5e0674725a6f230c077eb3d42ba9cd744f3f33)), closes [#13](https://github.com/peaceiris/actions-gh-pages/issues/13)
* update ([6b2b219](https://github.com/peaceiris/actions-gh-pages/commit/6b2b21931c7f2d3e6c8bb103d8911c7db5e1640c))
* update ([825291d](https://github.com/peaceiris/actions-gh-pages/commit/825291d6f44b996e6798a185649148d95c2113a0))
* update ([5f81e04](https://github.com/peaceiris/actions-gh-pages/commit/5f81e04c5392575d3b7a0e0c19dba9b6e12a1552))
### feat
* Add ForceOrphan ([72a38e1](https://github.com/peaceiris/actions-gh-pages/commit/72a38e1a66d6e92e1f5cc4e6517736302350769b))
* add tag ([cb0ae4b](https://github.com/peaceiris/actions-gh-pages/commit/cb0ae4b051357b3950eaad0694e5280685d02a65))
### fix
* action failure status (#15) ([5d770cf](https://github.com/peaceiris/actions-gh-pages/commit/5d770cf1a3f624f288aeb883120facd8bb9be0e3)), closes [#15](https://github.com/peaceiris/actions-gh-pages/issues/15)
* test 5 ([be72615](https://github.com/peaceiris/actions-gh-pages/commit/be726151a04188efc7817a2ea4a2fa6d5aab0f52))
* test 5 ([0c3cc92](https://github.com/peaceiris/actions-gh-pages/commit/0c3cc9261318d03f93ea9765c80416e02ac22850))
### test
* allowEmptyCommit ([dbe91b4](https://github.com/peaceiris/actions-gh-pages/commit/dbe91b4071cd17ef2e8ed2b15d7aa78ddc2fde31))
* fail (#17) ([102ec5a](https://github.com/peaceiris/actions-gh-pages/commit/102ec5a6faa411ded6dbd9dad2c9c90760b5f6aa)), closes [#17](https://github.com/peaceiris/actions-gh-pages/issues/17)
* name email ([4cfb699](https://github.com/peaceiris/actions-gh-pages/commit/4cfb6998408e2f5890ac8edfc2b2e21c6dff7ce3))
* name email ([699be58](https://github.com/peaceiris/actions-gh-pages/commit/699be586e2a51ecac66b0386d138977d96d0fb22))
* print context ([1f50fa1](https://github.com/peaceiris/actions-gh-pages/commit/1f50fa14ea101ba129d2df88456efbc8a1f44072))
* should fail ([b5ee9e2](https://github.com/peaceiris/actions-gh-pages/commit/b5ee9e26f781f5dd14ac31186394d6042a4007c6))
# [3.1.0-2](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0-1...v3.1.0-2) (2020-01-29)
### chore
* Change update_schedule from weekly to daily ([705453e](https://github.com/peaceiris/actions-gh-pages/commit/705453ed379218c67346fb7a506672399fa2168c))
* fix .gitconfig path ([b4f3632](https://github.com/peaceiris/actions-gh-pages/commit/b4f363240e949127f3303265cd8c9d4b93659edf))
* ignore failure ([752186a](https://github.com/peaceiris/actions-gh-pages/commit/752186ab23060558eec454cca240c52dc0297626))
* remove jest from lint-staged ([67b2175](https://github.com/peaceiris/actions-gh-pages/commit/67b2175154855954c45d229c3c24df74a7069f8c))
* update name ([5524237](https://github.com/peaceiris/actions-gh-pages/commit/55242376750e5aa63d6b37c2f1ede2f4574cdff1))
* update name ([8894b54](https://github.com/peaceiris/actions-gh-pages/commit/8894b541cf0ba48e94b0243c087c2ff6a5acded0))
### ci
* update [skip ci] ([1356241](https://github.com/peaceiris/actions-gh-pages/commit/1356241728f741769f594e16afb333cda1b5af3d))
### deps
* bump @types/jest from 24.9.1 to 25.1.0 (#8) ([a129668](https://github.com/peaceiris/actions-gh-pages/commit/a129668d5a9918c74c0fc61a7b23d650134b9d14)), closes [#8](https://github.com/peaceiris/actions-gh-pages/issues/8)
* bump @typescript-eslint/eslint-plugin from 2.17.0 to 2.18.0 (#11) ([aeac583](https://github.com/peaceiris/actions-gh-pages/commit/aeac583956c2d4905809b6586dc0587dfd39770d)), closes [#11](https://github.com/peaceiris/actions-gh-pages/issues/11)
* bump @typescript-eslint/parser from 2.17.0 to 2.18.0 (#9) ([6304225](https://github.com/peaceiris/actions-gh-pages/commit/6304225bde576cdf74f51c252500092fc3c76c30)), closes [#9](https://github.com/peaceiris/actions-gh-pages/issues/9)
* bump lint-staged from 10.0.2 to 10.0.3 (#10) ([fd432ae](https://github.com/peaceiris/actions-gh-pages/commit/fd432aed6ca65dc463e7a260a4d646a04aac68d8)), closes [#10](https://github.com/peaceiris/actions-gh-pages/issues/10)
* update ([ff7a4e6](https://github.com/peaceiris/actions-gh-pages/commit/ff7a4e686ef1fe7d116a19ba0e19fe663469636c))
* update ([b7effe0](https://github.com/peaceiris/actions-gh-pages/commit/b7effe0abf1b31a36b83c045f94a3791e02794dd))
* update ([b9c97f9](https://github.com/peaceiris/actions-gh-pages/commit/b9c97f9966632cd170952b776cdee0adb5cb3f14))
### feat
* Add git config gc.auto 0 ([f9abca9](https://github.com/peaceiris/actions-gh-pages/commit/f9abca9aadadb1054f154d339787f6b931aca308))
### fix
* git config ([d0589ad](https://github.com/peaceiris/actions-gh-pages/commit/d0589ad8c164019045661a2d3f8298637bf4c38b))
* remove readonly ([ee2570d](https://github.com/peaceiris/actions-gh-pages/commit/ee2570d0b58bf3a538a419422502044a4823965a))
* remove readonly ([01fba98](https://github.com/peaceiris/actions-gh-pages/commit/01fba9884211afc67d08805d18a3b5cd21283c3f))
* string ([edb9ee4](https://github.com/peaceiris/actions-gh-pages/commit/edb9ee4c963e6b7437c6dde39d392af68e205748))
* string ([b6270ce](https://github.com/peaceiris/actions-gh-pages/commit/b6270cec5adc6c91a5e7a9b716a34d176d68cd2d))
### refactor
* Add readonly ([6b1fffd](https://github.com/peaceiris/actions-gh-pages/commit/6b1fffd0be9f9218319f3973a93a1af0b51e85cd))
### test
* 3 ([2b76677](https://github.com/peaceiris/actions-gh-pages/commit/2b766776185f09bfd9ad34f4bfb07f6526a1f172))
# [3.1.0-1](https://github.com/peaceiris/actions-gh-pages/compare/v3.1.0-0...v3.1.0-1) (2020-01-19)
### docs
* Add link to deploy log ([0e0c184](https://github.com/peaceiris/actions-gh-pages/commit/0e0c184997116badf00f8624e0d04cc878783113))
### feat
* add [INFO] ([0187498](https://github.com/peaceiris/actions-gh-pages/commit/0187498430aafb5b45596e4ffb5fd0a392191edf))
* Add set-tokens ([91fa776](https://github.com/peaceiris/actions-gh-pages/commit/91fa77695d8aab239e82b2895232314a89c41dbc))
* Add setGitRepo() ([f8231fd](https://github.com/peaceiris/actions-gh-pages/commit/f8231fd0b4499fbf5557ce4e2d3845c61cfa5c8c))
### fix
* Add all process ([211e96c](https://github.com/peaceiris/actions-gh-pages/commit/211e96c1434130665ed5aa0573243bbebf6ea1bb))
* Add async ([6e386ad](https://github.com/peaceiris/actions-gh-pages/commit/6e386adb8066e50db1eb9ce961375bcc0c45d32d))
* Add await ([4b98a70](https://github.com/peaceiris/actions-gh-pages/commit/4b98a70318ea19803718f2e3edeced8add145838))
* Add createWorkDir() ([2aac9f0](https://github.com/peaceiris/actions-gh-pages/commit/2aac9f03a0ac6b0718c4f0a8071d1a9a97addaf2))
* Add GITHUB_WORKSPACE ([efe6506](https://github.com/peaceiris/actions-gh-pages/commit/efe6506cb90a49cf450734d506db5a3df7f51e59))
* Add ssh config ([a6d3d3e](https://github.com/peaceiris/actions-gh-pages/commit/a6d3d3e4e42821be48c08d1b2b51e22541218f58))
* Add String() ([b866328](https://github.com/peaceiris/actions-gh-pages/commit/b866328684445bbe1372fca34f3c41729b238348))
* default inputs ([d8f13a7](https://github.com/peaceiris/actions-gh-pages/commit/d8f13a7da3e38168db7d449af36da538b6317363))
* git remote add origin ([1fc54b7](https://github.com/peaceiris/actions-gh-pages/commit/1fc54b7b09d41769cd24be6860fabc13b3b74775))
* github_token ([682f359](https://github.com/peaceiris/actions-gh-pages/commit/682f35986da2437d9796e444193692051aefb957))
* known_hosts ([ba94b34](https://github.com/peaceiris/actions-gh-pages/commit/ba94b34d0c46dd02d05c132624dd3e8b1abe982c))
* known_hosts ([3d3740b](https://github.com/peaceiris/actions-gh-pages/commit/3d3740b76ddc79254803db70285bde6ea01818b1))
* known_hosts ([f0aff3b](https://github.com/peaceiris/actions-gh-pages/commit/f0aff3b9b5a1f3675a86581e4a3fd6e49f8b9937))
* known_hosts ([4b497e9](https://github.com/peaceiris/actions-gh-pages/commit/4b497e9bad639a684e924b8a6eb32bccb5a067c6))
* known_hosts ([38ac39e](https://github.com/peaceiris/actions-gh-pages/commit/38ac39e21706017c6922385d2965fda30d3cd630))
* known_hosts ([893792e](https://github.com/peaceiris/actions-gh-pages/commit/893792e38352754eb524ae47d4c452a1795265c6))
* known_hosts ([115a5c2](https://github.com/peaceiris/actions-gh-pages/commit/115a5c285a910b084a3d92e085b1d4e64b1b05e2))
* known_hosts ([19b48d9](https://github.com/peaceiris/actions-gh-pages/commit/19b48d9682e45da240d1fd2b7f427bd564561490))
* known_hosts ([304bf09](https://github.com/peaceiris/actions-gh-pages/commit/304bf09b95f89c149e2153f761c985af6d0f6922))
* known_hosts ([364d723](https://github.com/peaceiris/actions-gh-pages/commit/364d723459543f4d44374d85e750d41e225149c6))
* known_hosts ([949e934](https://github.com/peaceiris/actions-gh-pages/commit/949e93405eacf563eec9c7c6966ec545749563ae))
* known_hosts ([827d5ab](https://github.com/peaceiris/actions-gh-pages/commit/827d5ab6dd02137d659e104f066af63833c49664))
* log ([74780a7](https://github.com/peaceiris/actions-gh-pages/commit/74780a73cb8cb4128545616025d7160fbceecb38))
* log ([7ef7561](https://github.com/peaceiris/actions-gh-pages/commit/7ef75616138f3790ddad21479f80ee4ac62002ce))
* nothing to commit, working tree clean ([ba96387](https://github.com/peaceiris/actions-gh-pages/commit/ba963877e449ae0f01d68814625b2908546ca47f))
* nothing to commit, working tree clean ([2398872](https://github.com/peaceiris/actions-gh-pages/commit/23988721d63c6c138933b3e8395bf62b3a5d965b))
* print log ([b7acdc6](https://github.com/peaceiris/actions-gh-pages/commit/b7acdc6ed09daa1e90c1401ccef8ae062719d479))
* process.chdir workDir ([d9a7070](https://github.com/peaceiris/actions-gh-pages/commit/d9a707014eeffbd7aca63f7bc3b3744b88027b84))
* repo name ([b2e29d0](https://github.com/peaceiris/actions-gh-pages/commit/b2e29d00bdb276267fb6efb8945c3fd82d405fa8))
* ssh-agent ([9223cbb](https://github.com/peaceiris/actions-gh-pages/commit/9223cbbb24f4681add01cf67b49f76c918d69ba1))
* ssh-agent ([5f4184c](https://github.com/peaceiris/actions-gh-pages/commit/5f4184c4bedf628997d9726beb82bda5060ad620))
* ssh-agent ([09dd0ba](https://github.com/peaceiris/actions-gh-pages/commit/09dd0baa7842f85f7c15713d650421b3f7a791ce))
* ssh-agent ([8415fa0](https://github.com/peaceiris/actions-gh-pages/commit/8415fa096f53ed530ee1d0cb512159cf1bb81f8f))
* ssh-agent ([0764a18](https://github.com/peaceiris/actions-gh-pages/commit/0764a18fa15df76d7381b3f1b0ec3869b3d22939))
* ssh-agent ([7dcd208](https://github.com/peaceiris/actions-gh-pages/commit/7dcd2083831a0a1a5c57ebe7850114373c2806f9))
* ssh-agent ([a67fca3](https://github.com/peaceiris/actions-gh-pages/commit/a67fca3a04d8c2d19048b6d9b0180bea7f27cf43))
* ssh-agent ([643d9f1](https://github.com/peaceiris/actions-gh-pages/commit/643d9f13cc8f2e6fa9a75f5da3c0721da2caff7a))
* ssh-agent ([e6c82bb](https://github.com/peaceiris/actions-gh-pages/commit/e6c82bb3d6071d674e539c68ff0667cfd12784b6))
* ssh-agent ([6a06829](https://github.com/peaceiris/actions-gh-pages/commit/6a068296040d80f6f6ecf44357222a40392e0652))
* ssh-agent ([e669ac1](https://github.com/peaceiris/actions-gh-pages/commit/e669ac12f6613d1d2ad8514fff12b56b8d383242))
* Use child_process.exec for redirect ([5aa9ee0](https://github.com/peaceiris/actions-gh-pages/commit/5aa9ee04276459ab9d992d982913e97da3aabaec))
* workdir ([0ac4961](https://github.com/peaceiris/actions-gh-pages/commit/0ac496185112333ee0d09af6be9fc2dae715382b))
* write file ([c700df9](https://github.com/peaceiris/actions-gh-pages/commit/c700df9aed53a32ac8fa8c4521c767ca44d1a914))
### test
* 2 ([339a220](https://github.com/peaceiris/actions-gh-pages/commit/339a22020c35e097e0d5a0b1ac1410aac0b9baae))
* Add jest --detectOpenHandles ([ecb3731](https://github.com/peaceiris/actions-gh-pages/commit/ecb3731e33ddc7be05ecd9042c5d1d57b22c1bb3))
* Add mdbook build ([d614256](https://github.com/peaceiris/actions-gh-pages/commit/d614256de523aee4b24efb17b1f8cbd0f8dafd5c))
* Add mdbook test project ([e67298b](https://github.com/peaceiris/actions-gh-pages/commit/e67298b52fbb1f852337829c56c009e9910bcee2))
* github_token ([ac71046](https://github.com/peaceiris/actions-gh-pages/commit/ac71046bd26f10f8e3f375e97e326c2c9412349b))
* rename [skip ci] ([0a0d07f](https://github.com/peaceiris/actions-gh-pages/commit/0a0d07fece65e3748f99327243293abc034f7736))
* run ([f6502c1](https://github.com/peaceiris/actions-gh-pages/commit/f6502c151baf4edf6b3b745944b8d81cbe2364ac))
* v2 ([6123edd](https://github.com/peaceiris/actions-gh-pages/commit/6123edd7dfb9cbf8a0a6e6d356c9591cbf31bd8b))
* v3 ([b91823f](https://github.com/peaceiris/actions-gh-pages/commit/b91823f8862a7b6f65291ddcfada0c8b1850a374))
# [3.1.0-0](https://github.com/peaceiris/actions-gh-pages/compare/v3.0.0...v3.1.0-0) (2020-01-18)
### chore
* Add v3.0.0 ([234c7ca](https://github.com/peaceiris/actions-gh-pages/commit/234c7cab06f27ff81cad729c6ddf850362ffde7a))
# Changelog

View File

@ -1,10 +1,29 @@
FROM alpine:3.11.3
ARG NODE_VERSION
RUN apk add --no-cache \
bash \
git \
openssh-client \
ca-certificates
FROM node:${NODE_VERSION}-buster-slim
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT [ "/entrypoint.sh" ]
SHELL ["/bin/bash", "-l", "-c"]
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev autoconf \
ca-certificates \
wget \
ssh && \
rm -rf /var/lib/apt/lists/*
WORKDIR /git
ENV GIT_VERSION="2.25.0"
RUN wget -q "https://github.com/git/git/archive/v${GIT_VERSION}.tar.gz" && \
tar -zxf "./v${GIT_VERSION}.tar.gz" && \
rm "./v${GIT_VERSION}.tar.gz" && \
cd "./git-${GIT_VERSION}" && \
make configure && \
./configure --prefix=/usr && \
make all && \
make install
WORKDIR /repo
CMD [ "bash" ]

23
Makefile Normal file
View File

@ -0,0 +1,23 @@
cmd := "bash"
msg := ""
IMAGE_NAME := actions_github_pages_dev:latest
NODE_VERSION := $(shell cat ./.nvmrc)
DOCKER_BUILD := docker build . -t $(IMAGE_NAME) --build-arg NODE_VERSION=$(NODE_VERSION)
DOCKER_RUN := docker run --rm -i -t -v ${PWD}:/repo -v ~/.gitconfig:/root/.gitconfig $(IMAGE_NAME)
.PHONY: build
build:
$(DOCKER_BUILD)
.PHONY: run
run:
$(DOCKER_RUN) $(cmd)
.PHONY: test
test:
$(DOCKER_RUN) npm test
.PHONY: commit
commit:
$(DOCKER_RUN) git commit -m "$(msg)"

View File

@ -0,0 +1,94 @@
// import * as main from '../src/main';
import {Inputs} from '../src/interfaces';
import {getInputs} from '../src/get-inputs';
beforeEach(() => {
jest.resetModules();
});
afterEach(() => {
delete process.env['INPUT_DEPLOY_KEY'];
delete process.env['INPUT_GITHUB_TOKEN'];
delete process.env['INPUT_PERSONAL_TOKEN'];
delete process.env['INPUT_PUBLISH_BRANCH'];
delete process.env['INPUT_PUBLISH_DIR'];
delete process.env['INPUT_EXTERNAL_REPOSITORY'];
delete process.env['INPUT_ALLOW_EMPTY_COMMIT'];
delete process.env['INPUT_KEEP_FILES'];
delete process.env['INPUT_FORCE_ORPHAN'];
delete process.env['INPUT_USER_NAME'];
delete process.env['INPUT_USER_EMAIL'];
delete process.env['INPUT_COMMIT_MESSAGE'];
delete process.env['INPUT_TAG_NAME'];
delete process.env['INPUT_TAG_MESSAGE'];
});
describe('getInputs()', () => {
test('get default inputs', () => {
process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
// process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
// process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
process.env['INPUT_PUBLISH_BRANCH'] = 'gh-pages';
process.env['INPUT_PUBLISH_DIR'] = 'public';
// process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
// process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
// process.env['INPUT_KEEP_FILES'] = 'true';
// process.env['INPUT_FORCE_ORPHAN'] = 'true';
// process.env['INPUT_USER_NAME'] = 'username';
// process.env['INPUT_USER_EMAIL'] = 'github@github.com';
// process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
// process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
// process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
const inps: Inputs = getInputs();
expect(inps.DeployKey).toMatch('test_deploy_key');
expect(inps.GithubToken).toMatch('');
expect(inps.PersonalToken).toMatch('');
expect(inps.PublishBranch).toMatch('gh-pages');
expect(inps.PublishDir).toMatch('public');
expect(inps.ExternalRepository).toMatch('');
expect(inps.AllowEmptyCommit).toBe(false);
expect(inps.KeepFiles).toBe(false);
expect(inps.ForceOrphan).toBe(false);
expect(inps.UserName).toMatch('');
expect(inps.UserEmail).toMatch('');
expect(inps.CommitMessage).toMatch('');
expect(inps.TagName).toMatch('');
expect(inps.TagMessage).toMatch('');
});
test('get spec inputs', () => {
// process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
process.env['INPUT_GITHUB_TOKEN'] = 'test_github_token';
process.env['INPUT_PERSONAL_TOKEN'] = 'test_personal_token';
process.env['INPUT_PUBLISH_BRANCH'] = 'master';
process.env['INPUT_PUBLISH_DIR'] = 'out';
process.env['INPUT_EXTERNAL_REPOSITORY'] = 'user/repo';
process.env['INPUT_ALLOW_EMPTY_COMMIT'] = 'true';
process.env['INPUT_KEEP_FILES'] = 'true';
process.env['INPUT_FORCE_ORPHAN'] = 'true';
process.env['INPUT_USER_NAME'] = 'username';
process.env['INPUT_USER_EMAIL'] = 'github@github.com';
process.env['INPUT_COMMIT_MESSAGE'] = 'feat: Add new feature';
process.env['INPUT_TAG_NAME'] = 'deploy-v1.2.3';
process.env['INPUT_TAG_MESSAGE'] = 'Deployment v1.2.3';
const inps: Inputs = getInputs();
expect(inps.DeployKey).toMatch('');
expect(inps.GithubToken).toMatch('test_github_token');
expect(inps.PersonalToken).toMatch('test_personal_token');
expect(inps.PublishBranch).toMatch('master');
expect(inps.PublishDir).toMatch('out');
expect(inps.ExternalRepository).toMatch('user/repo');
expect(inps.AllowEmptyCommit).toBe(true);
expect(inps.KeepFiles).toBe(true);
expect(inps.ForceOrphan).toBe(true);
expect(inps.UserName).toMatch('username');
expect(inps.UserEmail).toMatch('github@github.com');
expect(inps.CommitMessage).toMatch('feat: Add new feature');
expect(inps.TagName).toMatch('deploy-v1.2.3');
expect(inps.TagMessage).toMatch('Deployment v1.2.3');
});
});

32
__tests__/main.test.ts Normal file
View File

@ -0,0 +1,32 @@
// import {run} from '../src/main';
beforeEach(() => {
jest.resetModules();
});
afterEach(() => {
delete process.env['INPUT_DEPLOY_KEY'];
delete process.env['INPUT_GITHUB_TOKEN'];
delete process.env['INPUT_PERSONAL_TOKEN'];
delete process.env['INPUT_PUBLISH_BRANCH'];
delete process.env['INPUT_PUBLISH_DIR'];
delete process.env['INPUT_EXTERNAL_REPOSITORY'];
delete process.env['INPUT_ALLOW_EMPTY_COMMIT'];
delete process.env['INPUT_KEEP_FILES'];
delete process.env['INPUT_FORCE_ORPHAN'];
delete process.env['INPUT_USER_NAME'];
delete process.env['INPUT_USER_EMAIL'];
delete process.env['INPUT_COMMIT_MESSAGE'];
delete process.env['INPUT_TAG_NAME'];
delete process.env['INPUT_TAG_MESSAGE'];
delete process.env['INPUT_TAG_OVERWRITE'];
});
describe('Integration testing run()', () => {
test('succeed in pushing using deploy key', async () => {
// process.env['INPUT_DEPLOY_KEY'] = 'test_deploy_key';
// process.env['GITHUB_REPOSITORY'] = 'owner/repo';
// const exitcode = await run();
expect(0).toBe(0);
});
});

View File

@ -1,41 +1,57 @@
name: 'GitHub Pages action'
name: 'GitHub Pages v3'
description: 'GitHub Actions for GitHub Pages 🚀 Deploy static files and publish your site easily. Static-Site-Generators-friendly.'
author: 'peaceiris'
runs:
using: 'docker'
image: 'Dockerfile'
using: 'node12'
main: 'lib/index.js'
branding:
icon: 'upload-cloud'
color: 'blue'
inputs:
emptyCommits:
deploy_key:
description: ''
required: false
github_token:
description: ''
required: false
personal_token:
description: ''
required: false
publish_branch:
description: ''
required: false
default: 'gh-pages'
publish_dir:
description: ''
required: false
default: 'public'
external_repository:
description: ''
required: false
allow_empty_commit:
description: 'If empty commits should be made to the publication branch'
required: false
default: 'true'
keepFiles:
default: 'false'
keep_files:
description: 'If existing files in the publish branch should be not removed before deploying'
required: false
default: 'false'
forceOrphan:
force_orphan:
description: 'Keep only the latest commit on a GitHub Pages branch'
required: false
default: 'false'
username:
user_name:
description: 'Set Git user.name'
required: false
useremail:
user_email:
description: 'Set Git user.email'
required: false
commitMessage:
commit_message:
description: 'Set custom commit message'
required: false
tagName:
tag_name:
description: 'Set tag name'
required: false
tagMessage:
tag_message:
description: 'Set tag message'
required: false
tagOverwrite:
description: 'Enable overwriting tag'
required: false
default: false

View File

@ -1,163 +0,0 @@
#!/bin/bash
set -e
# set -ex
function print_error() {
echo -e "\e[31mERROR: ${1}\e[m"
}
function print_info() {
echo -e "\e[36mINFO: ${1}\e[m"
}
function skip() {
print_info "No changes detected, skipping deployment"
exit 0
}
# check values
if [ -n "${EXTERNAL_REPOSITORY}" ]; then
PUBLISH_REPOSITORY=${EXTERNAL_REPOSITORY}
else
PUBLISH_REPOSITORY=${GITHUB_REPOSITORY}
fi
print_info "Deploy to ${PUBLISH_REPOSITORY}"
if [ -n "${ACTIONS_DEPLOY_KEY}" ]; then
print_info "setup with ACTIONS_DEPLOY_KEY"
if [ -n "${SCRIPT_MODE}" ]; then
print_info "run as SCRIPT_MODE"
SSH_DIR="${HOME}/.ssh"
else
SSH_DIR="/root/.ssh"
fi
mkdir "${SSH_DIR}"
ssh-keyscan -t rsa github.com > "${SSH_DIR}/known_hosts"
echo "${ACTIONS_DEPLOY_KEY}" > "${SSH_DIR}/id_rsa"
chmod 400 "${SSH_DIR}/id_rsa"
remote_repo="git@github.com:${PUBLISH_REPOSITORY}.git"
elif [ -n "${PERSONAL_TOKEN}" ]; then
print_info "setup with PERSONAL_TOKEN"
remote_repo="https://x-access-token:${PERSONAL_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
elif [ -n "${GITHUB_TOKEN}" ]; then
print_info "setup with GITHUB_TOKEN"
print_error "GITHUB_TOKEN works only private repo, See #9"
if [ -n "${EXTERNAL_REPOSITORY}" ]; then
print_error "can not use GITHUB_TOKEN to deploy to an external repository"
exit 1
fi
remote_repo="https://x-access-token:${GITHUB_TOKEN}@github.com/${PUBLISH_REPOSITORY}.git"
else
print_error "not found ACTIONS_DEPLOY_KEY, PERSONAL_TOKEN, or GITHUB_TOKEN"
exit 1
fi
if [ -z "${PUBLISH_BRANCH}" ]; then
print_error "not found PUBLISH_BRANCH"
exit 1
fi
if [ -z "${PUBLISH_DIR}" ]; then
print_error "not found PUBLISH_DIR"
exit 1
fi
remote_branch="${PUBLISH_BRANCH}"
local_dir="${HOME}/ghpages_${RANDOM}"
if [[ "${INPUT_FORCEORPHAN}" == "true" ]]; then
print_info "force ophan: ${INPUT_FORCEORPHAN}"
cd "${PUBLISH_DIR}"
git init
git checkout --orphan "${remote_branch}"
elif git clone --depth=1 --single-branch --branch "${remote_branch}" "${remote_repo}" "${local_dir}"; then
cd "${local_dir}"
if [[ ${INPUT_KEEPFILES} == "true" ]]; then
print_info "Keeping existing files: ${INPUT_KEEPFILES}"
else
git rm -r --ignore-unmatch '*'
fi
find "${GITHUB_WORKSPACE}/${PUBLISH_DIR}" -maxdepth 1 -not -name ".git" -not -name ".github" | \
tail -n +2 | \
xargs -I % cp -rf % "${local_dir}/"
else
cd "${PUBLISH_DIR}"
git init
git checkout --orphan "${remote_branch}"
fi
# push to publishing branch
if [[ -n "${INPUT_USERNAME}" ]]; then
git config user.name "${INPUT_USERNAME}"
else
git config user.name "${GITHUB_ACTOR}"
fi
if [[ -n "${INPUT_USEREMAIL}" ]]; then
git config user.email "${INPUT_USEREMAIL}"
else
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
fi
git remote rm origin || true
git remote add origin "${remote_repo}"
git add --all
print_info "Allowing empty commits: ${INPUT_EMPTYCOMMITS}"
if [ -n "${INPUT_COMMITMESSAGE}" ]; then
BASE_COMMIT_MESSAGE="${INPUT_COMMITMESSAGE}"
else
BASE_COMMIT_MESSAGE="Automated deployment: $(date -u)"
fi
if [ -n "${EXTERNAL_REPOSITORY}" ]; then
COMMIT_MESSAGE="${BASE_COMMIT_MESSAGE} ${GITHUB_REPOSITORY}@${GITHUB_SHA}"
else
COMMIT_MESSAGE="${BASE_COMMIT_MESSAGE} ${GITHUB_SHA}"
fi
if [[ ${INPUT_EMPTYCOMMITS} == "false" ]]; then
git commit -m "${COMMIT_MESSAGE}" || skip
else
git commit --allow-empty -m "${COMMIT_MESSAGE}"
fi
if [[ ${INPUT_FORCEORPHAN} == "true" ]]; then
git push origin --force "${remote_branch}"
else
git push origin "${remote_branch}"
fi
if [[ -n "${INPUT_TAGNAME}" ]]; then
print_info "Tag name: ${INPUT_TAGNAME}"
print_info "Tag message: ${INPUT_TAGMESSAGE}"
print_info "Tag overwrite: ${INPUT_TAGOVERWRITE}"
if [[ -n "${INPUT_TAGMESSAGE}" ]]; then
GIT_TAG_MESSAGE="${INPUT_TAGMESSAGE}"
else
GIT_TAG_MESSAGE="Deployment ${INPUT_TAGNAME}"
fi
if [[ "${INPUT_TAGOVERWRITE}" == "true" ]]; then
GIT_TAG_OPTION="--force"
else
GIT_TAG_OPTION=""
fi
git tag "${GIT_TAG_OPTION}" -a "${INPUT_TAGNAME}" -m "${GIT_TAG_MESSAGE}"
git push "${GIT_TAG_OPTION}" origin "${INPUT_TAGNAME}"
fi
print_info "${GITHUB_SHA} was successfully deployed"

11
jest.config.js Normal file
View File

@ -0,0 +1,11 @@
module.exports = {
clearMocks: true,
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true
}

7865
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

76
package.json Normal file
View File

@ -0,0 +1,76 @@
{
"name": "actions-github-pages",
"version": "3.0.0-0",
"description": "GitHub Actions for GitHub Pages",
"main": "lib/index.js",
"engines": {
"node": ">=12.14.1",
"npm": ">=6.13.7"
},
"scripts": {
"lint": "eslint ./{src,__tests__}/**/*.ts",
"lint:fix": "eslint --fix ./{src,__tests__}/**/*.ts",
"test": "jest --coverage --verbose --detectOpenHandles",
"build": "ncc build ./src/index.ts -o lib",
"tsc": "tsc",
"format": "prettier --write **/*.ts",
"format:check": "prettier --check **/*.ts",
"release": "standard-version",
"update-deps": "(git diff 'HEAD@{1}' --name-only | grep 'package-lock.json' > /dev/null) && npm ci || :"
},
"husky": {
"skipCI": true,
"hooks": {
"pre-commit": "lint-staged",
"post-merge": "npm run update-deps; git remote prune origin"
}
},
"lint-staged": {
"src/**/*.ts": [
"prettier --check",
"eslint"
]
},
"repository": {
"type": "git",
"url": "git+https://github.com/peaceiris/actions-gh-pages.git"
},
"keywords": [
"GitHub Actions",
"Actions",
"JavaScript Action",
"TypeScript Action",
"GitHub Pages",
"gh-pages"
],
"author": "peaceiris",
"license": "MIT",
"bugs": {
"url": "https://github.com/peaceiris/actions-gh-pages/issues"
},
"homepage": "https://github.com/peaceiris/actions-gh-pages#readme",
"dependencies": {
"@actions/core": "^1.2.2",
"@actions/exec": "^1.0.3",
"@actions/github": "^2.1.0",
"@actions/glob": "^0.1.0",
"@actions/io": "^1.0.2"
},
"devDependencies": {
"@types/jest": "^25.1.1",
"@types/node": "^13.7.0",
"@typescript-eslint/eslint-plugin": "^2.19.0",
"@typescript-eslint/parser": "^2.19.0",
"@zeit/ncc": "^0.21.0",
"eslint": "^6.8.0",
"eslint-plugin-jest": "^23.6.0",
"husky": "^4.2.1",
"jest": "^25.1.0",
"jest-circus": "^25.1.0",
"lint-staged": "^10.0.7",
"prettier": "1.19.1",
"standard-version": "^7.1.0",
"ts-jest": "^25.2.0",
"typescript": "^3.7.5"
}
}

48
release.sh Executable file
View File

@ -0,0 +1,48 @@
#!/usr/bin/env bash
# fail on unset variables and command errors
set -eu -o pipefail # -x: is for debugging
if [ "$(git branch --show-current)" != "master" ]; then
echo "$0: Current branch is not master" 1>&2
exit 1
fi
RELEASE_TYPE_LIST="prerelease prepatch patch preminor minor major premajor"
if command -v fzf; then
RELEASE_TYPE=$(echo "${RELEASE_TYPE_LIST}" | tr ' ' '\n' | fzf --layout=reverse)
else
select sel in ${RELEASE_TYPE_LIST}; do
RELEASE_TYPE="${sel}"
break
done
fi
echo "$0: Create ${RELEASE_TYPE} release, continue? (y/n)"
read -r res
if [ "${res}" = "n" ]; then
echo "$0: Stop script"
exit 0
fi
git fetch origin
git pull origin master
git tag -d v3 || true
git pull origin --tags
npm ci
mkdir ./lib
npm run build
git add ./lib/index.js
git commit -m "chore(release): Add build assets"
npm run release -- --release-as "${RELEASE_TYPE}" --preset eslint
git rm ./lib/index.js
rm -rf ./lib
git commit -m "chore(release): Remove build assets [skip ci]"
TAG_NAME="v$(jq -r '.version' ./package.json)"
git push origin master
git push origin "${TAG_NAME}"

50
src/get-inputs.ts Normal file
View File

@ -0,0 +1,50 @@
import * as core from '@actions/core';
import {Inputs} from './interfaces';
function showInputs(inps: Inputs): void {
if (inps.DeployKey) {
core.info(`[INFO] DeployKey: true`);
} else if (inps.GithubToken) {
core.info(`[INFO] GithubToken: true`);
} else if (inps.PersonalToken) {
core.info(`[INFO] PersonalToken: true`);
}
core.info(`[INFO] PublishBranch: ${inps.PublishBranch}`);
core.info(`[INFO] PublishDir: ${inps.PublishDir}`);
core.info(`[INFO] ExternalRepository: ${inps.ExternalRepository}`);
core.info(`[INFO] AllowEmptyCommit: ${inps.AllowEmptyCommit}`);
core.info(`[INFO] KeepFiles: ${inps.KeepFiles}`);
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
core.info(`[INFO] UserEmail: ${inps.UserEmail}`);
core.info(`[INFO] UserEmail: ${inps.UserEmail}`);
core.info(`[INFO] CommitMessage: ${inps.CommitMessage}`);
core.info(`[INFO] TagName: ${inps.TagName}`);
core.info(`[INFO] TagMessage: ${inps.TagMessage}`);
}
export function getInputs(): Inputs {
const inps: Inputs = {
DeployKey: core.getInput('deploy_key'),
GithubToken: core.getInput('github_token'),
PersonalToken: core.getInput('personal_token'),
PublishBranch: core.getInput('publish_branch'),
PublishDir: core.getInput('publish_dir'),
ExternalRepository: core.getInput('external_repository'),
AllowEmptyCommit:
(core.getInput('allow_empty_commit') || 'false').toUpperCase() === 'TRUE',
KeepFiles:
(core.getInput('keep_files') || 'false').toUpperCase() === 'TRUE',
ForceOrphan:
(core.getInput('force_orphan') || 'false').toUpperCase() === 'TRUE',
UserName: core.getInput('user_name'),
UserEmail: core.getInput('user_email'),
CommitMessage: core.getInput('commit_message'),
TagName: core.getInput('tag_name'),
TagMessage: core.getInput('tag_message')
};
showInputs(inps);
return inps;
}

187
src/git-utils.ts Normal file
View File

@ -0,0 +1,187 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as github from '@actions/github';
import * as io from '@actions/io';
import * as glob from '@actions/glob';
import path from 'path';
import {Inputs, CmdResult} from './interfaces';
import {getHomeDir} from './utils';
export async function createWorkDir(workDirName: string): Promise<void> {
await io.mkdirP(workDirName);
core.debug(`workDir was created: ${workDirName}`);
return;
}
export async function createBranchForce(branch: string): Promise<void> {
await exec.exec('git', ['init']);
await exec.exec('git', ['checkout', '--orphan', branch]);
return;
}
export async function copyAssets(
publishDir: string,
workDir: string
): Promise<void> {
const copyOpts = {recursive: true, force: false};
const globber = await glob.create(`${publishDir}/*`);
for await (const file of globber.globGenerator()) {
if (file.endsWith('.git') || file.endsWith('.github')) {
continue;
}
await io.cp(file, `${workDir}/`, copyOpts);
core.info(`[INFO] copy ${file}`);
}
return;
}
export async function setRepo(inps: Inputs, remoteURL: string): Promise<void> {
const workDir = path.join(getHomeDir(), 'actions_github_pages');
const publishDir = path.join(
`${process.env.GITHUB_WORKSPACE}`,
inps.PublishDir
);
core.info(`[INFO] ForceOrphan: ${inps.ForceOrphan}`);
if (inps.ForceOrphan) {
await createWorkDir(workDir);
process.chdir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
return;
}
const result: CmdResult = {
exitcode: 0,
output: ''
};
const options = {
listeners: {
stdout: (data: Buffer): void => {
result.output += data.toString();
}
}
};
result.exitcode = await exec.exec(
'git',
[
'clone',
'--depth=1',
'--single-branch',
'--branch',
inps.PublishBranch,
remoteURL,
workDir
],
options
);
process.chdir(workDir);
if (result.exitcode === 0) {
if (inps.KeepFiles) {
core.info('[INFO] Keep existing files');
} else {
await exec.exec('git', ['rm', '-r', '--ignore-unmatch', '*']);
}
await copyAssets(publishDir, workDir);
return;
} else {
core.info(
`[INFO] first deployment, create new branch ${inps.PublishBranch}`
);
await createWorkDir(workDir);
await createBranchForce(inps.PublishBranch);
await copyAssets(publishDir, workDir);
return;
}
}
export async function setConfig(
userName: string,
userEmail: string
): Promise<void> {
await exec.exec('git', ['config', '--global', 'gc.auto', '0']);
let name = '';
if (userName) {
name = userName;
} else {
name = `${process.env.GITHUB_ACTOR}`;
}
await exec.exec('git', ['config', '--global', 'user.name', name]);
let email = '';
if (userName !== '' && userEmail !== '') {
email = userEmail;
} else {
email = `${process.env.GITHUB_ACTOR}@users.noreply.github.com`;
}
await exec.exec('git', ['config', '--global', 'user.email', email]);
return;
}
export async function commit(
allowEmptyCommit: boolean,
externalRepository: string,
message: string
): Promise<void> {
let msg = '';
if (message) {
msg = message;
} else {
msg = 'deploy:';
}
const hash = `${process.env.GITHUB_SHA}`;
const baseRepo = `${github.context.repo.owner}/${github.context.repo.repo}`;
if (externalRepository) {
msg = `${msg} ${baseRepo}@${hash}`;
} else {
msg = `${msg} ${hash}`;
}
try {
if (allowEmptyCommit) {
await exec.exec('git', ['commit', '--allow-empty', '-m', `${msg}`]);
} else {
await exec.exec('git', ['commit', '-m', `${msg}`]);
}
} catch (e) {
core.info('[INFO] skip commit');
core.debug(`[INFO] skip commit ${e}`);
}
}
export async function push(
branch: string,
forceOrphan: boolean
): Promise<void> {
if (forceOrphan) {
await exec.exec('git', ['push', 'origin', '--force', branch]);
} else {
await exec.exec('git', ['push', 'origin', branch]);
}
}
export async function pushTag(
tagName: string,
tagMessage: string
): Promise<void> {
if (tagName === '') {
return;
}
let msg = '';
if (tagMessage) {
msg = tagMessage;
} else {
msg = `Deployment ${tagName}`;
}
await exec.exec('git', ['tag', '-a', `${tagName}`, '-m', `${msg}`]);
await exec.exec('git', ['push', 'origin', `${tagName}`]);
}

10
src/index.ts Normal file
View File

@ -0,0 +1,10 @@
import * as core from '@actions/core';
import * as main from './main';
(async (): Promise<void> => {
try {
await main.run();
} catch (e) {
core.setFailed(`Action failed with "${e}"`);
}
})();

21
src/interfaces.ts Normal file
View File

@ -0,0 +1,21 @@
export interface Inputs {
readonly DeployKey: string;
readonly GithubToken: string;
readonly PersonalToken: string;
readonly PublishBranch: string;
readonly PublishDir: string;
readonly ExternalRepository: string;
readonly AllowEmptyCommit: boolean;
readonly KeepFiles: boolean;
readonly ForceOrphan: boolean;
readonly UserName: string;
readonly UserEmail: string;
readonly CommitMessage: string;
readonly TagName: string;
readonly TagMessage: string;
}
export interface CmdResult {
exitcode: number;
output: string;
}

40
src/main.ts Normal file
View File

@ -0,0 +1,40 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import {Inputs} from './interfaces';
import {getInputs} from './get-inputs';
import {setTokens} from './set-tokens';
import * as git from './git-utils';
export async function run(): Promise<void> {
try {
const inps: Inputs = getInputs();
await git.setConfig(inps.UserName, inps.UserEmail);
const remoteURL = await setTokens(inps);
core.info(`[INFO] remoteURL: ${remoteURL}`); // TODO: remove
await git.setRepo(inps, remoteURL);
try {
await exec.exec('git', ['remote', 'rm', 'origin']);
} catch (e) {
core.info(`[INFO] e`);
}
await exec.exec('git', ['remote', 'add', 'origin', remoteURL]);
await exec.exec('git', ['add', '--all']);
await git.commit(
inps.AllowEmptyCommit,
inps.ExternalRepository,
inps.CommitMessage
);
await git.push(inps.PublishBranch, inps.ForceOrphan);
await git.pushTag(inps.TagName, inps.TagMessage);
core.info('[INFO] successfully deployed');
return;
} catch (e) {
throw new Error(e);
}
}

124
src/set-tokens.ts Normal file
View File

@ -0,0 +1,124 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as github from '@actions/github';
import * as io from '@actions/io';
import path from 'path';
import fs from 'fs';
const cpexec = require('child_process').execFileSync;
import {Inputs} from './interfaces';
export function setPublishRepo(insp: Inputs): string {
if (insp.ExternalRepository) {
return insp.ExternalRepository;
}
return `${github.context.repo.owner}/${github.context.repo.repo}`;
}
export async function setSSHKey(
inps: Inputs,
publishRepo: string
): Promise<string> {
core.info('[INFO] setup SSH deploy key');
const sshDir = path.join(`${process.env.HOME}`, '.ssh');
await io.mkdirP(sshDir);
await exec.exec('chmod', ['700', sshDir]);
const knownHosts = path.join(sshDir, 'known_hosts');
// ssh-keyscan -t rsa github.com >> ~/.ssh/known_hosts on Ubuntu
const cmdSSHkeyscanOutput = `\
# github.com:22 SSH-2.0-babeld-1f0633a6
github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==
`;
fs.writeFileSync(knownHosts, cmdSSHkeyscanOutput + '\n');
core.info(`[INFO] wrote ${knownHosts}`);
await exec.exec('chmod', ['600', knownHosts]);
const idRSA = path.join(sshDir, 'github');
fs.writeFileSync(idRSA, inps.DeployKey + '\n');
core.info(`[INFO] wrote ${idRSA}`);
await exec.exec('chmod', ['600', idRSA]);
const sshConfigPath = path.join(sshDir, 'config');
const sshConfigContent = `\
Host github
HostName github.com
IdentityFile ~/.ssh/github
User git
`;
fs.writeFileSync(sshConfigPath, sshConfigContent + '\n');
core.info(`[INFO] wrote ${sshConfigPath}`);
await exec.exec('chmod', ['600', sshConfigPath]);
await cpexec('ssh-agent', ['-a', '/tmp/ssh-auth.sock']);
core.exportVariable('SSH_AUTH_SOCK', '/tmp/ssh-auth.sock');
await exec.exec('ssh-add', [idRSA]);
return `git@github.com:${publishRepo}.git`;
}
export async function setGithubToken(
inps: Inputs,
publishRepo: string
): Promise<string> {
core.info('[INFO] setup GITHUB_TOKEN');
const context = github.context;
const payload = github.context.payload;
core.debug(`ref: ${context.ref}`);
core.debug(`eventName: ${context.eventName}`);
core.debug(`private: ${payload.repository?.private}`);
let isProhibitedBranch = false;
const ref = context.ref;
if (context.eventName === 'push') {
isProhibitedBranch = ref.includes(`refs/heads/${inps.PublishBranch}`);
if (isProhibitedBranch) {
throw new Error(
`You deploy from ${inps.PublishBranch} to ${inps.PublishBranch}`
);
}
} else if (context.eventName === 'pull_request') {
// TODO: support pull_request event
throw new Error('This action does not support pull_request event now.');
}
const isPrivateRepository = payload.repository?.private;
if (inps.ExternalRepository) {
throw new Error(
'GITHUB_TOKEN does not support to push to an external repository'
);
}
if (isPrivateRepository === false) {
core.warning(
'GITHUB_TOKEN does not support to trigger the GitHub Pages build event on a public repository'
);
}
return `https://x-access-token:${inps.GithubToken}@github.com/${publishRepo}.git`;
}
export async function setPersonalToken(
inps: Inputs,
publishRepo: string
): Promise<string> {
core.info('[INFO] setup personal access token');
return `https://x-access-token:${inps.PersonalToken}@github.com/${publishRepo}.git`;
}
export async function setTokens(inps: Inputs): Promise<string> {
try {
const publishRepo = setPublishRepo(inps);
if (inps.DeployKey) {
return setSSHKey(inps, publishRepo);
} else if (inps.GithubToken) {
return setGithubToken(inps, publishRepo);
} else if (inps.PersonalToken) {
return setPersonalToken(inps, publishRepo);
} else {
throw new Error('not found deploy key or tokens');
}
} catch (e) {
throw new Error(e);
}
}

15
src/utils.ts Normal file
View File

@ -0,0 +1,15 @@
import * as core from '@actions/core';
export function getHomeDir(): string {
let homedir = '';
if (process.platform === 'win32') {
homedir = process.env['USERPROFILE'] || 'C:\\';
} else {
homedir = `${process.env.HOME}`;
}
core.debug(`homeDir: ${homedir}`);
return homedir;
}

1
test_projects/mdbook/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
book

View File

@ -0,0 +1,6 @@
[book]
authors = ["peaceiris"]
language = "en"
multilingual = false
src = "src"
title = "GitHub Actions for GitHub Pages"

View File

@ -0,0 +1,3 @@
# Summary
- [Chapter 1](./chapter_1.md)

View File

@ -0,0 +1,3 @@
# Chapter 1
test 7

65
tsconfig.json Normal file
View File

@ -0,0 +1,65 @@
{
"compilerOptions": {
/* Basic Options */
// "incremental": true, /* Enable incremental compilation */
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
// "allowJs": true, /* Allow javascript files to be compiled. */
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */
// "declaration": true, /* Generates corresponding '.d.ts' file. */
// "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */
"sourceMap": true, /* Generates corresponding '.map' file. */
// "outFile": "./", /* Concatenate and emit output to single file. */
"outDir": "./lib", /* Redirect output structure to the directory. */
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "composite": true, /* Enable project compilation */
// "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */
"removeComments": true, /* Do not emit comments to output. */
// "noEmit": true, /* Do not emit outputs. */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
// "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */
// "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */
/* Strict Type-Checking Options */
"strict": true, /* Enable all strict type-checking options. */
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */
/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */
/* Module Resolution Options */
// "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
/* Source Map Options */
// "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */
/* Experimental Options */
// "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */
// "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */
"resolveJsonModule": true
},
"exclude": ["node_modules", "**/*.test.ts"]
}