Add workflow to build technical documentation using full website #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build technical documentation | |
on: | |
pull_request: | |
paths: ["docs/sources/**"] | |
workflow_dispatch: | |
jobs: | |
docs-target: | |
runs-on: ubuntu-latest | |
outputs: | |
target: ${{ steps.target.outputs.target }} | |
steps: | |
- name: Checkout Actions library | |
uses: actions/checkout@v3 | |
with: | |
repository: grafana/grafana-github-actions | |
path: ./actions | |
- name: Install Actions from library | |
run: npm install --production --prefix ./actions | |
- name: Determine technical documentation version | |
uses: ./actions/docs-target | |
id: target | |
with: | |
ref_name: ${{ github.base_ref }} | |
with-hugo: | |
runs-on: ubuntu-latest | |
container: | |
image: grafana/docs-base:latest | |
needs: | |
- docs-target | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Generate GitHub token | |
id: generate-token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.GRAFANA_DELIVERY_BOT_APP_ID }} | |
private_key: ${{ secrets.GRAFANA_DELIVERY_BOT_APP_PEM }} | |
- name: Sparse clone website repository | |
run: | | |
git clone --filter=blob:none --no-checkout --sparse --depth 1 "https://x-access-token:${TOKEN}@github.com/grafana/website.git" website | |
git -C website sparse-checkout set content/docs | |
git -C website checkout master | |
env: | |
TOKEN: ${{ steps.generate-token.outputs.token }} | |
- name: Build website | |
# Note that busybox `ln` does not have the `-F` option. | |
run: | | |
rm -rf /hugo/content/docs | |
ln -sn "$(pwd)/website/content/docs" /hugo/content/docs | |
rm -rf "/hugo/content/docs/grafana/${TARGET}" | |
ln -sn "$(pwd)/docs/sources" "/hugo/content/docs/grafana/${TARGET}" | |
cd /hugo | |
unset WEBSITE_SKIP_MOUNTS | |
make hugo HUGO_ENV=docs | grep docs/grafana/ | |
env: | |
TARGET: ${{ needs.docs-target.outputs.target }} | |
doc-validator: | |
runs-on: ubuntu-latest | |
container: | |
image: grafana/doc-validator:v3.2.1 | |
needs: | |
- docs-target | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Generate GitHub token | |
id: generate-token | |
uses: tibdex/github-app-token@v1 | |
with: | |
app_id: ${{ secrets.GRAFANA_DELIVERY_BOT_APP_ID }} | |
private_key: ${{ secrets.GRAFANA_DELIVERY_BOT_APP_PEM }} | |
- name: Sparse clone website repository | |
run: | | |
git clone --filter=blob:none --no-checkout --sparse --depth 1 "https://x-access-token:${TOKEN}@github.com/grafana/website.git" website | |
git -C website sparse-checkout set content/docs | |
git -C website checkout master | |
env: | |
TOKEN: ${{ steps.generate-token.outputs.token }} | |
- name: Run doc-validator tool | |
# Only run doc-validator on specific directories. | |
# doc-validator doesn't support walking symlinks yet. | |
run: | | |
rm -rf "$(pwd)/website/content/docs/grafana/${TARGET}" | |
mv "$(pwd)/docs/sources" "$(pwd)/website/content/docs/grafana/${TARGET}" | |
doc-validator \ | |
"--include=^$(pwd)/website/content/docs/grafana/${TARGET}/${DOC_VALIDATOR_INCLUDE}" \ | |
"--skip-checks=${DOC_VALIDATOR_SKIP_CHECKS}" \ | |
"$(pwd)/website/content/docs/grafana/${TARGET}" \ | |
/docs/grafana/latest \ | |
| sed "s,$(pwd)/website/content/docs/grafana/${TARGET},docs/sources,g" \ | |
| reviewdog \ | |
-f=rdjsonl \ | |
--filter-mode=nofilter \ | |
--name=doc-validator \ | |
--reporter=github-pr-review | |
env: | |
DOC_VALIDATOR_INCLUDE: (?:alerting|fundamentals|getting-started|introduction|setup-grafana|upgrade-guide|whatsnew/whats-new-in-v(?:9|10))/.+\.md$ | |
DOC_VALIDATOR_SKIP_CHECKS: ^(?:image.+|canonical-does-not-match-pretty-URL)$ | |
REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
TARGET: ${{ needs.docs-target.outputs.target }} |