Skip to content

Commit

Permalink
ci: refactor docs pipeline (backport #28852) (#28868)
Browse files Browse the repository at this point in the history
* ci: refactor docs pipeline (#28852)

* use git diff + grep to get affected files

* combine check and combine steps

* separate jobs

* fix condition

(cherry picked from commit cbf224a)

# Conflicts:
#	.github/workflows/docs.yml

* fix conflicts

Co-authored-by: Yihau Chen <[email protected]>
Co-authored-by: yihau <[email protected]>
  • Loading branch information
3 people authored Nov 18, 2022
1 parent 582638b commit 6ee0963
Showing 1 changed file with 55 additions and 30 deletions.
85 changes: 55 additions & 30 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,64 +13,89 @@ on:
- v[0-9]+.[0-9]+

jobs:
docs-build:
check:
outputs:
continue: ${{ steps.check.outputs.need_to_build }}
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Get commit range (push)
if: ${{ github.event_name == 'push' }}
run: |
echo "COMMIT_RANGE=$GIHTUB_SHA" >> $GITHUB_ENV
- name: Get commit range (pull_request)
if: ${{ github.event_name == 'pull_request' }}
run: |
echo "COMMIT_RANGE=${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" >> $GITHUB_ENV
- name: Get file status
run: |
set +e
git diff --name-only $COMMIT_RANGE | grep \
-e '.github/workflows/docs.yml' \
-e 'docs/**'
echo "FILE_CHANGED=$?" >> $GITHUB_ENV
- name: Check
id: check
shell: bash
run: |
source ci/env.sh
echo "::set-output name=tag::$CI_TAG"
eval "$(ci/channel-info.sh)"
echo "::set-output name=channel::$CHANNEL"
TAG=$CI_TAG
- name: Get specific changed files
id: changed-files-specific
uses: tj-actions/changed-files@v34
with:
files: |
.github/workflows/docs.yml
docs/**
echo "TAG: $TAG"
echo "CHANNEL: $CHANNEL"
echo "FILE_CHANGED: $FILE_CHANGED"
- name: Pre Build
id: prebuild
run: |
echo "tag: ${{ steps.check.outputs.tag }}"
echo "channel: ${{ steps.check.outputs.channel }}"
echo "any changes: ${{ steps.changed-files-specific.outputs.any_changed }}"
echo "::set-output name=need_to_build::${{
steps.check.outputs.tag != ''
||
(
(steps.check.outputs.channel == 'edge' || steps.check.outputs.channel == 'beta')
&&
steps.changed-files-specific.outputs.any_changed != ''
)
}}"
shell: bash
echo need_to_build="$(
if [ "$TAG" != '' ]
then
echo 1
elif [ $FILE_CHANGED = 0 ] && ( [ "$CHANNEL" = "beta" ] || [ "$CHANNEL" = "edge" ] )
then
echo 1
else
echo 0
fi
)" >> $GITHUB_OUTPUT
build_and_deploy:
needs:
- check
if: ${{ needs.check.outputs.continue == 1 }}
name: build & deploy
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Node
if: ${{ steps.prebuild.outputs.need_to_build == 'true' }}
uses: actions/setup-node@v3
with:
node-version: 14
node-version: 16

- name: Build
if: ${{ steps.prebuild.outputs.need_to_build == 'true' }}
working-directory: docs
run: |
npm install
./build.sh
env:
VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}

notification:
if: failure()
runs-on: ubuntu-20.04
needs:
- check
- build_and_deploy
steps:
- name: Send Slack notifiaction
if: failure()
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_NOTIFICATIONS_BOT_TOKEN }}
uses: voxmedia/github-action-slack-notify-build@v1
Expand Down

0 comments on commit 6ee0963

Please sign in to comment.