Build technical documentation using GitHub App #43
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: | ||
config: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
has-secrets: ${{ steps.check.outputs.has-secrets }} | ||
steps: | ||
- name: Check for secrets | ||
id: check | ||
shell: bash | ||
run: | | ||
if [ -n "${{ (secrets.BUILD_TECHNICAL_DOCUMENTATION_APP_ID != '' && secrets.BUILD_TECHNICAL_DOCUMENTATION_APP_PEM != '') || '' }}" ]; then | ||
echo has-secrets=1 >> "${GITHUB_OUTPUT}" | ||
fi | ||
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: | ||
needs: config | ||
if: github.repository == 'grafana/grafana' && needs.config.outputs.has-secrets | ||
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.BUILD_TECHNICAL_DOCUMENTATION_APP_ID }} | ||
private_key: ${{ secrets.BUILD_TECHNICAL_DOCUMENTATION_APP_PEM }} | ||
- name: Sparse checkout website repository | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: grafana/website | ||
sparse-checkout: content/docs | ||
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/${TARGET}" | ||
env: | ||
TARGET: ${{ needs.docs-target.outputs.target }} | ||
doc-validator: | ||
needs: config | ||
if: github.repository == 'grafana/grafana' && needs.config.outputs.has-secrets | ||
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.BUILD_TECHNICAL_DOCUMENTATION_APP_ID }} | ||
private_key: ${{ secrets.BUILD_TECHNICAL_DOCUMENTATION_APP_PEM }} | ||
- name: Sparse checkout website repository | ||
uses: actions/checkout@v3 | ||
with: | ||
repository: grafana/website | ||
sparse-checkout: content/docs | ||
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 }} |