Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workflow_dispatch to docs #6235

Merged
merged 1 commit into from
Dec 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 34 additions & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,52 @@ on:
push:
branches:
- stable
workflow_dispatch:
inputs:
ref:
description: 'Ref to deploy, defaults to `unstable`'
required: false
default: 'unstable'
type: string

jobs:
docs:
runs-on: buildjet-4vcpu-ubuntu-2204
env:
DEPLOY_REF: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.ref || 'stable' }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A little strange that the default here is 'stable' but above, its 'unstable'. I'd say pick one or the other

Copy link
Member Author

@matthewkeil matthewkeil Dec 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was so that its deploying stable if running push and defaulting to unstable in the manual deploy option with workflow_dispatch.

I wanted to maintain the original behavior of docs deploying when merged to stable and assumed we would most likely be manually deploying from unstable after a docs PR but between releases that auto deploy.

Do you want me to convert the hardcoded branch to || github.ref }} so that it will be more clear that its the value that push triggered the workflow?

The actions/checkout defaults the ref value to github.ref (or default branch if no github.ref is available) when one is not provided in the template.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, that makes sense! Looks good as is

steps:
# <common-build> - Uses YAML anchors in the future
# Validation step for workflow_dispatch ref input
- name: Validate Ref
if: github.event_name == 'workflow_dispatch'
run: |
if git rev-parse "${{ env.DEPLOY_REF }}" >/dev/null 2>&1; then
echo "Ref ${{ env.DEPLOY_REF }} is valid."
else
echo "Error: Ref ${{ env.DEPLOY_REF }} is not a valid branch, tag or commit." >&2
exit 1
fi

# Log out the ref being deployed
- name: Log Deployment Ref
if: github.event_name == 'workflow_dispatch'
run: |
echo "Deploying ref: $DEPLOY_REF"

# Checkout the correct ref being deployed
- uses: actions/checkout@v3
with:
ref: ${{ env.DEPLOY_REF }}

- uses: actions/setup-node@v3
with:
node-version: 20
check-latest: true
cache: yarn

- name: Node.js version
id: node
run: echo "v8CppApiVersion=$(node --print "process.versions.modules")" >> $GITHUB_OUTPUT

- name: Restore dependencies
uses: actions/cache@master
id: cache-deps
Expand All @@ -27,13 +58,14 @@ jobs:
node_modules
packages/*/node_modules
key: ${{ runner.os }}-${{ steps.node.outputs.v8CppApiVersion }}-${{ hashFiles('**/yarn.lock', '**/package.json') }}

- name: Install & build
if: steps.cache-deps.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile && yarn build

- name: Build
run: yarn build
if: steps.cache-deps.outputs.cache-hit == 'true'
# </common-build>

- name: Build and collect docs
run: yarn build:docs
Expand Down