diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 000000000000..f3bcf1a16fd1 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,52 @@ +name: Deploy + +on: + push: + branches: + - master + - source + pull_request: + branches: + - master + - source + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Setup Ruby + uses: actions/setup-ruby@v1 + - name: Enable bundler cache + uses: actions/cache@v2 + with: + path: vendor/bundle + key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} + restore-keys: | + ${{ runner.os }}-gems- + - name: Install deps + run: | + gem install bundler + bundle config path vendor/bundle + bundle install --jobs 4 --retry 3 + - name: Setup deploy options + id: setup + run: | + git config --global user.name "GitHub Action" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + if [[ ${GITHUB_REF} = refs/pull/*/merge ]]; then # pull request + echo "::set-output name=SRC_BRANCH::${GITHUB_HEAD_REF}" + echo "::set-output name=DRY_RUN::--dry-run" + elif [[ ${GITHUB_REF} = refs/heads/* ]]; then # branch, e.g. master, source etc + echo "::set-output name=SRC_BRANCH::${GITHUB_REF#refs/heads/}" + fi + if [[ ${{ github.repository }} = *.github.io ]]; then # user/org repo + echo "::set-output name=DEPLOY_BRANCH::master" + else + echo "::set-output name=DEPLOY_BRANCH::gh-pages" + fi + - name: Deploy website + run: yes | bin/deploy --verbose ${{ steps.setup.outputs.DRY_RUN }} + --src ${{ steps.setup.outputs.SRC_BRANCH }} + --deploy ${{ steps.setup.outputs.DEPLOY_BRANCH }} diff --git a/bin/deploy b/bin/deploy index db83010ed476..2ee74f5002a5 100755 --- a/bin/deploy +++ b/bin/deploy @@ -7,7 +7,7 @@ SRC_BRANCH="master" DEPLOY_BRANCH="gh-pages" -USAGE_MSG="usage: deploy [-h|--help] [-u|--user] [-s|--src SRC_BRANCH] [-d|--deploy DEPLOY_BRANCH]" +USAGE_MSG="usage: deploy [-h|--help] [-u|--user] [-s|--src SRC_BRANCH] [-d|--deploy DEPLOY_BRANCH] [--verbose] [--dry-run]" while [[ $# > 0 ]]; do key="$1" @@ -20,7 +20,6 @@ while [[ $# > 0 ]]; do -u|--user) SRC_BRANCH="source" DEPLOY_BRANCH="master" - shift ;; -s|--src) SRC_BRANCH="$2" @@ -30,10 +29,16 @@ while [[ $# > 0 ]]; do DEPLOY_BRANCH="$2" shift ;; + --verbose) + set -x + ;; + --dry-run) + DRY_RUN="--dry-run" + ;; *) - echo "Option $1 is unknown." - echo $USAGE_MSG - exit 0 + echo "Option $1 is unknown." >&2 + echo $USAGE_MSG >&2 + exit 1 ;; esac shift @@ -88,7 +93,7 @@ rm -R _site/ # Push to DEPLOY_BRANCH git add -fA git commit --allow-empty -m "$(git log -1 --pretty=%B) [ci skip]" -git push -f -q origin $DEPLOY_BRANCH +git push ${DRY_RUN} -f -q origin $DEPLOY_BRANCH # Move back to SRC_BRANCH git checkout $SRC_BRANCH