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 shared workflow for doctum reference documentation generation #150

Merged
merged 28 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
8b6b552
feat: add doctum workflow
bshaffer Aug 20, 2024
1f6768e
add support for tag and version
bshaffer Aug 20, 2024
6e4b0b9
fix bash typos
bshaffer Aug 20, 2024
a56f631
add back EOF
bshaffer Aug 20, 2024
87d0b13
add --ignore-parse-errors flag
bshaffer Aug 20, 2024
5249aad
consistent folder naming
bshaffer Aug 20, 2024
f46fb4d
add redirect, remove strip version
bshaffer Aug 20, 2024
40e3c5b
allows tag to be null, allows excludes
bshaffer Aug 20, 2024
8701a61
fix conditional
bshaffer Aug 20, 2024
bfb87d8
fix exclude syntax
bshaffer Aug 20, 2024
12c981d
add exclude_file
bshaffer Aug 20, 2024
b166d8c
fix notName function
bshaffer Aug 20, 2024
d4753a1
name workflow step
bshaffer Aug 20, 2024
c05c16d
add version selector and other changes
bshaffer Aug 20, 2024
062a0e6
set fetch-depth: 0
bshaffer Aug 20, 2024
78b202d
add include_search input
bshaffer Aug 20, 2024
b8ec4ba
revert include_search option for now
bshaffer Aug 20, 2024
8927589
exclude base_url (which performs search) for now
bshaffer Aug 20, 2024
90dae16
preserve newlines, add dry_run
bshaffer Aug 21, 2024
0db176e
fix condition
bshaffer Aug 21, 2024
b40dd4b
add theme option
bshaffer Aug 21, 2024
f011d63
update some inputs
bshaffer Aug 21, 2024
cfc517e
code cleanup
bshaffer Aug 21, 2024
632e71c
add error for when docs don't generate
bshaffer Aug 22, 2024
5f8cd14
hopefully fix conditional
bshaffer Aug 22, 2024
6d98975
move output check to run step
bshaffer Aug 22, 2024
001dadd
add default_version
bshaffer Aug 23, 2024
5b6eb6c
add github.heaf_ref for PR triggers
bshaffer Aug 23, 2024
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
114 changes: 114 additions & 0 deletions .github/workflows/doctum.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
name: Generate Reference Documentation

on:
workflow_call:
inputs:
title:
type: string
default: "Reference Documentation"
required: true
theme:
type: string
description: "doctum theme"
default: default
default_version:
type: string
description: "The version tag to use as the latest version."
tag_pattern:
type: string
description: "tags to include in version selector"
default: "v1.*"
dry_run:
type: boolean
description: "do not deploy to gh-pages"
exclude_file:
type: string
description: "exclude a file from documentation"

permissions:
contents: write

jobs:
docs:
name: "Generate and Deploy Documentation"
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
- name: Download Doctum
run: |
curl -# https://doctum.long-term.support/releases/5.5/doctum.phar -o doctum.phar
curl -# https://doctum.long-term.support/releases/5.5/doctum.phar.sha256 -o doctum.phar.sha256
sha256sum --strict --check doctum.phar.sha256
- name: Generate Doctum Config
run: |
DOCTUM_CONFIG=$(cat <<'EOF'
<?php
Hectorhammett marked this conversation as resolved.
Show resolved Hide resolved
use Doctum\Doctum;
use Doctum\RemoteRepository\GitHubRemoteRepository;
use Doctum\Version\GitVersionCollection;
use Symfony\Component\Finder\Finder;

$defaultVersion = '${{ inputs.default_version }}';
$tagPattern = '${{ inputs.tag_pattern }}';

$iterator = Finder::create()
->files()
->name('*.php')
->notName('${{ inputs.exclude_file }}')
->exclude('GPBMetadata')
->in(__DIR__ . '/src');

$versions = GitVersionCollection::create(__DIR__);
if ($tagPattern) {
$versions->addFromTags($tagPattern);
}
if ($defaultVersion) {
$versions->add($defaultVersion, $defaultVersion);
}

return new Doctum($iterator, [
'title' => '${{ inputs.title }}',
'theme' => '${{ inputs.theme }}',
'versions' => $versions,
'build_dir' => __DIR__ . '/.build/%version%',
'cache_dir' => __DIR__ . '/.cache/%version%',
'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__),
'default_opened_level' => 2,
'template_dirs' => [__DIR__ . '/.github'],
]);
EOF
)
echo "$DOCTUM_CONFIG"; # for debugging
echo "$DOCTUM_CONFIG" > doctum-config.php;
- name: Run Doctum to Generate Documentation
run: |
php doctum.phar update doctum-config.php --ignore-parse-errors
if [ ! -d .build ]; then
echo "Action did not generate any documentation. Did you forget to provide a default_version or tag_pattern?";
exit 1;
fi
- if: inputs.default_version
name: Redirect Index to Latest Version
run: |
cat << EOF > .build/index.html
<meta http-equiv='refresh' content='0;url=/${{ github.event.repository.name }}/${{ inputs.default_version }}'>
EOF
- if: ${{ !inputs.dry_run }}
name: Move generated files into GitHub Pages branch
run: |
git submodule add -q -f -b gh-pages https://github.com/${{ github.repository }} .ghpages
rsync -aP .build/* .ghpages/
- if: ${{ !inputs.dry_run }}
name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@releases/v3
with:
ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: .ghpages
5 changes: 5 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ jobs:
static-analysis:
uses: ./.github/workflows/static-analysis.yml

build_docs:
uses: ./.github/workflows/doctum.yml
with:
title: "Google Cloud PHP Tools"
dry_run: true
Loading