Skip to content

Commit

Permalink
docs: test builds without deploying for PRs
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Goldstein <andy.goldstein@redhat.com>
  • Loading branch information
ncdc committed Mar 2, 2023
1 parent d600c0d commit cc7aa8a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/docs-gen-and-push.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
name: Generate and push docs

on:
# So we can trigger manually if needed
workflow_dispatch:
# To confirm any changes to docs build successfully, without deploying them
pull_request:
# Pushes to branches do the full build + deployment
push:
branches:
- main
Expand Down
31 changes: 20 additions & 11 deletions hack/deploy-docs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,24 @@ set -o xtrace
REPO_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cd "$REPO_ROOT/docs"

if [[ -n "${GITHUB_REF_NAME:-}" ]]; then
VERSION="${VERSION:-$GITHUB_REF_NAME}"
if [[ "${GITHUB_EVENT_NAME:-}" == "pull_request" ]]; then
# For PRs, we don't want to use GITHUB_REF_NAME, which will be something like merge/1234; instead, we want to use
# the branch the PR is targeting, such as main or release-0.11
VERSION=$GITHUB_BASE_REF
else
VERSION=${VERSION:-$(git rev-parse --abbrev-ref HEAD)}
if [[ -n "${GITHUB_REF_NAME:-}" ]]; then
VERSION="${VERSION:-$GITHUB_REF_NAME}"
else
VERSION=${VERSION:-$(git rev-parse --abbrev-ref HEAD)}
fi

if echo "$VERSION" | grep '^release-[0-9]'; then
VERSION=v$(echo "$VERSION" | cut -d - -f 2)
elif echo "$VERSION" | grep '^v[0-9]\+\.[0-9]\+'; then
VERSION=$(echo "$VERSION" | grep -o '^v[0-9]\+\.[0-9]\+')
fi
fi

if echo "$VERSION" | grep '^release-[0-9]'; then
VERSION=v$(echo "$VERSION" | cut -d - -f 2)
elif echo "$VERSION" | grep '^v[0-9]\+\.[0-9]\+'; then
VERSION=$(echo "$VERSION" | grep -o '^v[0-9]\+\.[0-9]\+')
fi

MIKE_OPTIONS=()

Expand All @@ -44,11 +51,13 @@ if [[ -n "${BRANCH:-}" ]]; then
MIKE_OPTIONS+=(--branch "$BRANCH")
fi

git config user.name kcp-docs-bot
git config user.email no-reply@kcp.io

if [[ -n "${CI:-}" ]]; then
# Only push to gh-pages if we're in GitHub Actions (CI is set) and we have a non-PR event.
if [[ -n "${CI:-}" && "${GITHUB_EVENT_NAME:-}" == "push" ]]; then
MIKE_OPTIONS+=(--push)
git config user.name kcp-docs-bot
git config user.email no-reply@kcp.io

fi

mike deploy "${MIKE_OPTIONS[@]}" "$VERSION"

0 comments on commit cc7aa8a

Please sign in to comment.