From 8b6b552aa1da51ce23410a931f794fa2a357f11c Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 11:42:38 -0700 Subject: [PATCH 01/28] feat: add doctum workflow --- .github/workflows/doctum.yml | 89 ++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 .github/workflows/doctum.yml diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml new file mode 100644 index 0000000..0e24271 --- /dev/null +++ b/.github/workflows/doctum.yml @@ -0,0 +1,89 @@ +name: Generate Reference Documentation + +on: + workflow_call: + inputs: + title: + type: string + default: "Reference Documentation" + required: true + version: + type: string + required: true + path: + type: string + default: "." + +permissions: + contents: write + +jobs: + docs: + name: "Generate and Deploy Documentation" + runs-on: ubuntu-latest + steps: + # - name: Checkout + # uses: actions/checkout@v4 + # - id: getTag + # name: Get Tag + # run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} + # - name: Setup PHP + # uses: shivammathur/setup-php@v2 + # with: + # php-version: 8.1 + # - name: Strip "v" from Version + # id: strip_v + # run: | + # # Remove "v" from start of string if it exists + # TAG=${{ steps.getTag.outputs.tag }} + # if [[ ${TAG::1} == "v" ]]; then + # TAG="${TAG:1}" + # fi + # echo "tag=$TAG" >> $GITHUB_OUTPUT + - 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 + files() + ->name('*.php') + ->exclude('GPBMetadata') + ->in("__DIR__/src"); + + return new Doctum(\$iterator, [ + 'title' => '${{ inputs.title }}', + 'version' => '${{ inputs.version }}', + 'build_dir' => __DIR__ . "/.build/%version%", + 'cache_dir' => __DIR__ . "/.cache/%version%", + 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), + 'default_opened_level' => 1, + ]); + EOF + ) + echo $DOCTUM_CONFIG; // for debugging + echo $DOCTUM_CONFIG > doctum-config.php; + - name: Generate Documentation + run: | + php doctum.phar update doctum-config.php -v + - run: | + git submodule add -q -f -b gh-pages https://github.com/${{github.repository}} ghpages + rsync -aP build/* ghpages/ + - name: Deploy 🚀 + uses: JamesIves/github-pages-deploy-action@releases/v3 + with: + ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} + BRANCH: gh-pages + FOLDER: ghpages \ No newline at end of file From 1f6768e5d1218ef6a37614c501cba57a18fb5c11 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 11:50:05 -0700 Subject: [PATCH 02/28] add support for tag and version --- .github/workflows/doctum.yml | 42 +++++++++++++++++------------------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 0e24271..ad27081 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -9,10 +9,8 @@ on: required: true version: type: string - required: true - path: + tag: type: string - default: "." permissions: contents: write @@ -22,24 +20,24 @@ jobs: name: "Generate and Deploy Documentation" runs-on: ubuntu-latest steps: - # - name: Checkout - # uses: actions/checkout@v4 - # - id: getTag - # name: Get Tag - # run: echo ::set-output name=tag::${GITHUB_REF#refs/*/} - # - name: Setup PHP - # uses: shivammathur/setup-php@v2 - # with: - # php-version: 8.1 - # - name: Strip "v" from Version - # id: strip_v - # run: | - # # Remove "v" from start of string if it exists - # TAG=${{ steps.getTag.outputs.tag }} - # if [[ ${TAG::1} == "v" ]]; then - # TAG="${TAG:1}" - # fi - # echo "tag=$TAG" >> $GITHUB_OUTPUT + - name: Checkout + uses: actions/checkout@v4 + - if: ${{ !inputs.tag && !inputs.version }} + run: echo "Either a tag or version must be provided"; exit 1; + - if: inputs.tag + id: getTag + name: Get Tag + run: echo ::set-output name=tag::${{ inputs.tag }} + - if: ${{ inputs.tag }} + name: Strip "v" from Version + id: strip_v + run: | + # Remove "v" from start of string if it exists + TAG=${{ steps.getTag.outputs.tag }} + if [[ ${TAG::1} == "v" ]]; then + TAG="${TAG:1}" + fi + echo "tag=$TAG" >> $GITHUB_OUTPUT - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -65,7 +63,7 @@ jobs: return new Doctum(\$iterator, [ 'title' => '${{ inputs.title }}', - 'version' => '${{ inputs.version }}', + 'version' => '${{ inputs.version || steps.strip_v.outputs.tag }}', 'build_dir' => __DIR__ . "/.build/%version%", 'cache_dir' => __DIR__ . "/.cache/%version%", 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), From 6e4b0b90671060e9b420e7efd2f4e3cb9523f54e Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 12:21:24 -0700 Subject: [PATCH 03/28] fix bash typos --- .github/workflows/doctum.yml | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index ad27081..908ea9c 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -1,16 +1,16 @@ name: Generate Reference Documentation on: - workflow_call: - inputs: - title: - type: string - default: "Reference Documentation" - required: true - version: - type: string - tag: - type: string + workflow_call: + inputs: + title: + type: string + default: "Reference Documentation" + required: true + version: + type: string + tag: + type: string permissions: contents: write @@ -59,25 +59,24 @@ jobs: ->files() ->name('*.php') ->exclude('GPBMetadata') - ->in("__DIR__/src"); + ->in(__DIR__ . '/src'); return new Doctum(\$iterator, [ 'title' => '${{ inputs.title }}', 'version' => '${{ inputs.version || steps.strip_v.outputs.tag }}', - 'build_dir' => __DIR__ . "/.build/%version%", - 'cache_dir' => __DIR__ . "/.cache/%version%", + 'build_dir' => __DIR__ . '/.build/%version%', + 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), 'default_opened_level' => 1, ]); - EOF ) - echo $DOCTUM_CONFIG; // for debugging + echo $DOCTUM_CONFIG; # for debugging echo $DOCTUM_CONFIG > doctum-config.php; - name: Generate Documentation run: | php doctum.phar update doctum-config.php -v - run: | - git submodule add -q -f -b gh-pages https://github.com/${{github.repository}} ghpages + git submodule add -q -f -b gh-pages https://github.com/${{ github.repository }} ghpages rsync -aP build/* ghpages/ - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@releases/v3 From a56f631c274a04fb092b306393b501cf6c894706 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 12:24:27 -0700 Subject: [PATCH 04/28] add back EOF --- .github/workflows/doctum.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 908ea9c..4a7f078 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -49,7 +49,7 @@ jobs: sha256sum --strict --check doctum.phar.sha256 - name: Generate Doctum Config run: | - DOCTUM_CONFIG=$(cat <<-EOF + DOCTUM_CONFIG=$(cat < new GitHubRemoteRepository('${{ github.repository }}', __DIR__), 'default_opened_level' => 1, ]); + EOF ) echo $DOCTUM_CONFIG; # for debugging echo $DOCTUM_CONFIG > doctum-config.php; From 87d0b132b15bce5551334ee57a10d09324415748 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 12:30:08 -0700 Subject: [PATCH 05/28] add --ignore-parse-errors flag --- .github/workflows/doctum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 4a7f078..892159b 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -75,7 +75,7 @@ jobs: echo $DOCTUM_CONFIG > doctum-config.php; - name: Generate Documentation run: | - php doctum.phar update doctum-config.php -v + php doctum.phar update doctum-config.php -v --ignore-parse-errors - run: | git submodule add -q -f -b gh-pages https://github.com/${{ github.repository }} ghpages rsync -aP build/* ghpages/ From 5249aad5cb34a7cdd3f2a66aaacbb565522a967b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 12:33:41 -0700 Subject: [PATCH 06/28] consistent folder naming --- .github/workflows/doctum.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 892159b..59304dd 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -77,11 +77,11 @@ jobs: run: | php doctum.phar update doctum-config.php -v --ignore-parse-errors - run: | - git submodule add -q -f -b gh-pages https://github.com/${{ github.repository }} ghpages - rsync -aP build/* ghpages/ + git submodule add -q -f -b gh-pages https://github.com/${{ github.repository }} .ghpages + rsync -aP .build/* .ghpages/ - name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@releases/v3 with: ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH: gh-pages - FOLDER: ghpages \ No newline at end of file + FOLDER: .ghpages \ No newline at end of file From f46fb4dea9e38b382ce2549866221d2181108f2b Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 12:53:13 -0700 Subject: [PATCH 07/28] add redirect, remove strip version --- .github/workflows/doctum.yml | 34 +++++++++++----------------------- 1 file changed, 11 insertions(+), 23 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 59304dd..b1ffeb2 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -7,8 +7,6 @@ on: type: string default: "Reference Documentation" required: true - version: - type: string tag: type: string @@ -22,22 +20,6 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 - - if: ${{ !inputs.tag && !inputs.version }} - run: echo "Either a tag or version must be provided"; exit 1; - - if: inputs.tag - id: getTag - name: Get Tag - run: echo ::set-output name=tag::${{ inputs.tag }} - - if: ${{ inputs.tag }} - name: Strip "v" from Version - id: strip_v - run: | - # Remove "v" from start of string if it exists - TAG=${{ steps.getTag.outputs.tag }} - if [[ ${TAG::1} == "v" ]]; then - TAG="${TAG:1}" - fi - echo "tag=$TAG" >> $GITHUB_OUTPUT - name: Setup PHP uses: shivammathur/setup-php@v2 with: @@ -49,21 +31,21 @@ jobs: sha256sum --strict --check doctum.phar.sha256 - name: Generate Doctum Config run: | - DOCTUM_CONFIG=$(cat <files() ->name('*.php') ->exclude('GPBMetadata') ->in(__DIR__ . '/src'); - return new Doctum(\$iterator, [ + return new Doctum($iterator, [ 'title' => '${{ inputs.title }}', - 'version' => '${{ inputs.version || steps.strip_v.outputs.tag }}', + 'version' => '${{ inputs.tag }}', 'build_dir' => __DIR__ . '/.build/%version%', 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), @@ -73,9 +55,15 @@ jobs: ) echo $DOCTUM_CONFIG; # for debugging echo $DOCTUM_CONFIG > doctum-config.php; - - name: Generate Documentation + - name: Run Doctum to Generate Documentation run: | php doctum.phar update doctum-config.php -v --ignore-parse-errors + - name: Redirect Index to Latest Version + run: | + cat << EOF > .build/index.html + + EOF + - run: | git submodule add -q -f -b gh-pages https://github.com/${{ github.repository }} .ghpages rsync -aP .build/* .ghpages/ From 40e3c5b9306328aee1dd230e7ac8d256ec574391 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 14:07:22 -0700 Subject: [PATCH 08/28] allows tag to be null, allows excludes --- .github/workflows/doctum.yml | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index b1ffeb2..c7dc3d7 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -9,6 +9,10 @@ on: required: true tag: type: string + description: "The version tag to use for the documentation. Uses current tag if empty." + exclude: + type: string + description: "JSON array of directories to exclude from documentation" permissions: contents: write @@ -24,6 +28,16 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.1 + - if: !inputs.tag + id: getTag + name: Get Tag + run: | + TAG=${GITHUB_REF#refs/*/} + if [ -z "$TAG" ]; then + echo "No tag found" + exit 1 + fi + echo ::set-output name=tag::$TAG - name: Download Doctum run: | curl -# https://doctum.long-term.support/releases/5.5/doctum.phar -o doctum.phar @@ -41,11 +55,12 @@ jobs: ->files() ->name('*.php') ->exclude('GPBMetadata') + ->exclude(json_decode(${{ inputs.exclude || '[]' }}. true)) ->in(__DIR__ . '/src'); return new Doctum($iterator, [ 'title' => '${{ inputs.title }}', - 'version' => '${{ inputs.tag }}', + 'version' => '${{ inputs.tag || steps.getTag.outputs.tag }}', 'build_dir' => __DIR__ . '/.build/%version%', 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), @@ -61,7 +76,7 @@ jobs: - name: Redirect Index to Latest Version run: | cat << EOF > .build/index.html - + EOF - run: | @@ -72,4 +87,4 @@ jobs: with: ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH: gh-pages - FOLDER: .ghpages \ No newline at end of file + FOLDER: .ghpages From 8701a6173953de0316f804b6959bf1b3723bb565 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 14:13:38 -0700 Subject: [PATCH 09/28] fix conditional --- .github/workflows/doctum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index c7dc3d7..3c0ee35 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -28,7 +28,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.1 - - if: !inputs.tag + - if: inputs.tag == '' id: getTag name: Get Tag run: | From bfb87d85e851cf82d733756ffc8839079c63e0dc Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 14:15:11 -0700 Subject: [PATCH 10/28] fix exclude syntax --- .github/workflows/doctum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 3c0ee35..b389fd8 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -55,7 +55,7 @@ jobs: ->files() ->name('*.php') ->exclude('GPBMetadata') - ->exclude(json_decode(${{ inputs.exclude || '[]' }}. true)) + ->exclude(json_decode('{{ inputs.exclude }}', true) ?: '${{ inputs.exclude }}') ->in(__DIR__ . '/src'); return new Doctum($iterator, [ From 12c981d72cb30d8215d50bc60615f75eba18c601 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 14:26:26 -0700 Subject: [PATCH 11/28] add exclude_file --- .github/workflows/doctum.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index b389fd8..c68b426 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -13,6 +13,9 @@ on: exclude: type: string description: "JSON array of directories to exclude from documentation" + exclude_file: + type: string + description: "exclude a file from documentation" permissions: contents: write @@ -54,8 +57,9 @@ jobs: $iterator = Finder::create() ->files() ->name('*.php') + ->notFile("${{ inputs.exclude_file }}") ->exclude('GPBMetadata') - ->exclude(json_decode('{{ inputs.exclude }}', true) ?: '${{ inputs.exclude }}') + ->exclude(json_decode('${{ inputs.exclude }}', true) ?: '${{ inputs.exclude }}') ->in(__DIR__ . '/src'); return new Doctum($iterator, [ From b166d8ca4f869d302387c7f34e5279a65460b8d0 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 14:28:29 -0700 Subject: [PATCH 12/28] fix notName function --- .github/workflows/doctum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index c68b426..d7644d5 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -57,7 +57,7 @@ jobs: $iterator = Finder::create() ->files() ->name('*.php') - ->notFile("${{ inputs.exclude_file }}") + ->notName("${{ inputs.exclude_file }}") ->exclude('GPBMetadata') ->exclude(json_decode('${{ inputs.exclude }}', true) ?: '${{ inputs.exclude }}') ->in(__DIR__ . '/src'); From d4753a13381236d362b147f9a1894a6ba28fe6f8 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 14:42:35 -0700 Subject: [PATCH 13/28] name workflow step --- .github/workflows/doctum.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index d7644d5..37f3dab 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -82,8 +82,8 @@ jobs: cat << EOF > .build/index.html EOF - - - 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/ - name: Deploy 🚀 From c05c16d4137c5aa6b4b783e52b9eac04805e6d9a Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 15:43:52 -0700 Subject: [PATCH 14/28] add version selector and other changes --- .github/workflows/doctum.yml | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 37f3dab..cbbbd4c 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -7,15 +7,16 @@ on: type: string default: "Reference Documentation" required: true - tag: + default_tag: type: string - description: "The version tag to use for the documentation. Uses current tag if empty." - exclude: - type: string - description: "JSON array of directories to exclude from documentation" + description: "The version tag to use as the latest version." exclude_file: type: string description: "exclude a file from documentation" + tag_pattern: + type: string + description: "tags to include in version selector" + default: "v1.*" permissions: contents: write @@ -31,16 +32,6 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: 8.1 - - if: inputs.tag == '' - id: getTag - name: Get Tag - run: | - TAG=${GITHUB_REF#refs/*/} - if [ -z "$TAG" ]; then - echo "No tag found" - exit 1 - fi - echo ::set-output name=tag::$TAG - name: Download Doctum run: | curl -# https://doctum.long-term.support/releases/5.5/doctum.phar -o doctum.phar @@ -51,24 +42,32 @@ jobs: DOCTUM_CONFIG=$(cat <<'EOF' files() ->name('*.php') - ->notName("${{ inputs.exclude_file }}") + ->notName('${{ inputs.exclude_file }}') ->exclude('GPBMetadata') - ->exclude(json_decode('${{ inputs.exclude }}', true) ?: '${{ inputs.exclude }}') ->in(__DIR__ . '/src'); + $versions = GitVersionCollection::create(__DIR__); + if ('${{ inputs.tag_pattern }}') { + $versions->addFromTags('${{ inputs.tag_pattern }}'); + } else { + $versions->add('main', 'main'); + } + return new Doctum($iterator, [ 'title' => '${{ inputs.title }}', - 'version' => '${{ inputs.tag || steps.getTag.outputs.tag }}', + 'versions' => $versions, 'build_dir' => __DIR__ . '/.build/%version%', 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), - 'default_opened_level' => 1, + 'default_opened_level' => 2, + 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', ]); EOF ) @@ -76,11 +75,12 @@ jobs: echo $DOCTUM_CONFIG > doctum-config.php; - name: Run Doctum to Generate Documentation run: | - php doctum.phar update doctum-config.php -v --ignore-parse-errors - - name: Redirect Index to Latest Version + php doctum.phar update doctum-config.php --ignore-parse-errors + - if: inputs.default_tag + name: Redirect Index to Latest Version run: | cat << EOF > .build/index.html - + EOF - name: Move generated files into GitHub Pages branch run: | From 062a0e6c92ef2937f7154dd91913e02e2c8694b6 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 16:00:33 -0700 Subject: [PATCH 15/28] set fetch-depth: 0 --- .github/workflows/doctum.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index cbbbd4c..e9b5bce 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -28,6 +28,8 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: 0 - name: Setup PHP uses: shivammathur/setup-php@v2 with: From 78b202d16c0c8ecf36a1cdcfee0e8909d34480cb Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 16:17:24 -0700 Subject: [PATCH 16/28] add include_search input --- .github/workflows/doctum.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index e9b5bce..9218dd1 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -17,6 +17,10 @@ on: type: string description: "tags to include in version selector" default: "v1.*" + include_search: + type: boolean + description: whether or not to include search + default: true permissions: contents: write @@ -69,7 +73,7 @@ jobs: 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), 'default_opened_level' => 2, - 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', + 'base_url' => ${{ inputs.include_search }} ? 'https://googleapis.github.io/${{ github.event.repository.name }}' : null, ]); EOF ) From b8ec4ba53bacfe8277fac27e5fa478dafad6f194 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 16:20:29 -0700 Subject: [PATCH 17/28] revert include_search option for now --- .github/workflows/doctum.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 9218dd1..e9b5bce 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -17,10 +17,6 @@ on: type: string description: "tags to include in version selector" default: "v1.*" - include_search: - type: boolean - description: whether or not to include search - default: true permissions: contents: write @@ -73,7 +69,7 @@ jobs: 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), 'default_opened_level' => 2, - 'base_url' => ${{ inputs.include_search }} ? 'https://googleapis.github.io/${{ github.event.repository.name }}' : null, + 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', ]); EOF ) From 89275891a2eb315c5c6654ce523c08c67b3e8983 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Tue, 20 Aug 2024 16:23:26 -0700 Subject: [PATCH 18/28] exclude base_url (which performs search) for now --- .github/workflows/doctum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index e9b5bce..d6e405b 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -69,7 +69,7 @@ jobs: 'cache_dir' => __DIR__ . '/.cache/%version%', 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), 'default_opened_level' => 2, - 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', + // 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', ]); EOF ) From 90dae1694d4f814ed3ff9f034530845c99469a18 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Aug 2024 09:49:14 -0700 Subject: [PATCH 19/28] preserve newlines, add dry_run --- .github/workflows/doctum.yml | 63 +++++++++++++++++++----------------- .github/workflows/tests.yml | 5 +++ 2 files changed, 38 insertions(+), 30 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index d6e405b..f80a07a 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -17,6 +17,9 @@ on: type: string description: "tags to include in version selector" default: "v1.*" + dry_run: + type: boolean + description: "do not deploy to gh-pages" permissions: contents: write @@ -42,39 +45,37 @@ jobs: - name: Generate Doctum Config run: | DOCTUM_CONFIG=$(cat <<'EOF' - files() - ->name('*.php') - ->notName('${{ inputs.exclude_file }}') - ->exclude('GPBMetadata') - ->in(__DIR__ . '/src'); + $iterator = Finder::create() + ->files() + ->name('*.php') + ->notName('${{ inputs.exclude_file }}') + ->exclude('GPBMetadata') + ->in(__DIR__ . '/src'); - $versions = GitVersionCollection::create(__DIR__); - if ('${{ inputs.tag_pattern }}') { - $versions->addFromTags('${{ inputs.tag_pattern }}'); - } else { - $versions->add('main', 'main'); - } + $versions = GitVersionCollection::create(__DIR__); + empty('${{ inputs.tag_pattern }}') + ? $versions->add('main', 'main') + : $versions->addFromTags('${{ inputs.tag_pattern }}'); - return new Doctum($iterator, [ - 'title' => '${{ inputs.title }}', - 'versions' => $versions, - 'build_dir' => __DIR__ . '/.build/%version%', - 'cache_dir' => __DIR__ . '/.cache/%version%', - 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), - 'default_opened_level' => 2, - // 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', - ]); + return new Doctum($iterator, [ + 'title' => '${{ inputs.title }}', + 'versions' => $versions, + 'build_dir' => __DIR__ . '/.build/%version%', + 'cache_dir' => __DIR__ . '/.cache/%version%', + 'remote_repository' => new GitHubRemoteRepository('${{ github.repository }}', __DIR__), + 'default_opened_level' => 2, + // 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', + ]); EOF ) - echo $DOCTUM_CONFIG; # for debugging - echo $DOCTUM_CONFIG > doctum-config.php; + 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 @@ -84,11 +85,13 @@ jobs: cat << EOF > .build/index.html EOF - - name: Move generated files into GitHub Pages branch + - 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/ - - name: Deploy 🚀 + - if: !inputs.dry_run + name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@releases/v3 with: ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8243c8c..335d5bf 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 From 0db176e05db9950132f24c8b9342a013024105ab Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Aug 2024 09:55:20 -0700 Subject: [PATCH 20/28] fix condition --- .github/workflows/doctum.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index f80a07a..18f29b6 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -85,12 +85,12 @@ jobs: cat << EOF > .build/index.html EOF - - if: !inputs.dry_run + - 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 + - if: ${{ !inputs.dry_run }} name: Deploy 🚀 uses: JamesIves/github-pages-deploy-action@releases/v3 with: From b40dd4b941807d2c03d8bf96f3b39c8b2cb361c0 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Aug 2024 11:27:28 -0700 Subject: [PATCH 21/28] add theme option --- .github/workflows/doctum.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 18f29b6..12119c2 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -20,6 +20,10 @@ on: dry_run: type: boolean description: "do not deploy to gh-pages" + theme: + type: string + description: "doctum theme" + default: default permissions: contents: write @@ -65,12 +69,13 @@ jobs: 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, - // 'base_url' => 'https://googleapis.github.io/${{ github.event.repository.name }}', + 'template_dirs' => [__DIR__ . '/.github'], ]); EOF ) From f011d63bb9ca5faba605eabfdfac3940c5a0a36c Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Aug 2024 13:58:02 -0700 Subject: [PATCH 22/28] update some inputs --- .github/workflows/doctum.yml | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 12119c2..adbfa91 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -7,12 +7,13 @@ on: type: string default: "Reference Documentation" required: true - default_tag: + theme: type: string - description: "The version tag to use as the latest version." - exclude_file: + description: "doctum theme" + default: default + default_version: type: string - description: "exclude a file from documentation" + description: "The version tag to use as the latest version." tag_pattern: type: string description: "tags to include in version selector" @@ -20,10 +21,9 @@ on: dry_run: type: boolean description: "do not deploy to gh-pages" - theme: - type: string - description: "doctum theme" - default: default + exclude_file: + type: string + description: "exclude a file from documentation" permissions: contents: write @@ -63,9 +63,12 @@ jobs: ->in(__DIR__ . '/src'); $versions = GitVersionCollection::create(__DIR__); - empty('${{ inputs.tag_pattern }}') - ? $versions->add('main', 'main') - : $versions->addFromTags('${{ inputs.tag_pattern }}'); + if ('${{ inputs.tag_pattern }}') { + $versions->addFromTags('${{ inputs.tag_pattern }}'); + } + if ('${{ inputs.default_version }}') { + $versions->add('${{ inputs.default_version }}', '${{ inputs.default_version }}'); + } return new Doctum($iterator, [ 'title' => '${{ inputs.title }}', @@ -84,11 +87,11 @@ jobs: - name: Run Doctum to Generate Documentation run: | php doctum.phar update doctum-config.php --ignore-parse-errors - - if: inputs.default_tag + - if: inputs.default_version name: Redirect Index to Latest Version run: | cat << EOF > .build/index.html - + EOF - if: ${{ !inputs.dry_run }} name: Move generated files into GitHub Pages branch From cfc517e74ea8d56b4612873ec2c29fb9b30eda7c Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Wed, 21 Aug 2024 14:08:23 -0700 Subject: [PATCH 23/28] code cleanup --- .github/workflows/doctum.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index adbfa91..efbc68c 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -55,6 +55,9 @@ jobs: use Doctum\Version\GitVersionCollection; use Symfony\Component\Finder\Finder; + $defaultVersion = '${{ inputs.default_version }}'; + $tagPattern = '${{ inputs.tag_pattern }}'; + $iterator = Finder::create() ->files() ->name('*.php') @@ -63,11 +66,11 @@ jobs: ->in(__DIR__ . '/src'); $versions = GitVersionCollection::create(__DIR__); - if ('${{ inputs.tag_pattern }}') { - $versions->addFromTags('${{ inputs.tag_pattern }}'); + if ($tagPattern) { + $versions->addFromTags($tagPattern); } - if ('${{ inputs.default_version }}') { - $versions->add('${{ inputs.default_version }}', '${{ inputs.default_version }}'); + if ($defaultVersion) { + $versions->add($defaultVersion, $defaultVersion); } return new Doctum($iterator, [ From 632e71c47c5ffa26e7510f967e501504f76462bc Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 22 Aug 2024 10:04:50 -0700 Subject: [PATCH 24/28] add error for when docs don't generate --- .github/workflows/doctum.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index efbc68c..32ecf44 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -93,6 +93,10 @@ jobs: - if: inputs.default_version name: Redirect Index to Latest Version run: | + if [ ! -f .build/index.html ]; then + echo "Action did not generate any documentation. Did you forget to provide a default_version or tag_pattern?"; + exit 1; + fi cat << EOF > .build/index.html EOF From 5f8cd145825be7307974f5cd76d8264e1856c226 Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 22 Aug 2024 10:17:41 -0700 Subject: [PATCH 25/28] hopefully fix conditional --- .github/workflows/doctum.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 32ecf44..6090a92 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -93,7 +93,7 @@ jobs: - if: inputs.default_version name: Redirect Index to Latest Version run: | - if [ ! -f .build/index.html ]; then + 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 From 6d989750138a9bb9212b8251b52ec1fd65c8cfbf Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Thu, 22 Aug 2024 15:15:40 -0700 Subject: [PATCH 26/28] move output check to run step --- .github/workflows/doctum.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/doctum.yml b/.github/workflows/doctum.yml index 6090a92..5c153c1 100644 --- a/.github/workflows/doctum.yml +++ b/.github/workflows/doctum.yml @@ -90,13 +90,13 @@ jobs: - name: Run Doctum to Generate Documentation run: | php doctum.phar update doctum-config.php --ignore-parse-errors - - if: inputs.default_version - name: Redirect Index to Latest Version - run: | 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 EOF From 001dadd14c5fd9b8e4de483ed0bf715f61adfbbf Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 23 Aug 2024 09:44:54 -0700 Subject: [PATCH 27/28] add default_version --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 335d5bf..1dce607 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,4 +43,5 @@ jobs: uses: ./.github/workflows/doctum.yml with: title: "Google Cloud PHP Tools" + default_version: ${{ github.ref_name }} dry_run: true From 5b6eb6cc47f710a089f0792cf39238a83f8e49ed Mon Sep 17 00:00:00 2001 From: Brent Shaffer Date: Fri, 23 Aug 2024 09:55:07 -0700 Subject: [PATCH 28/28] add github.heaf_ref for PR triggers --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 1dce607..653999d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -43,5 +43,5 @@ jobs: uses: ./.github/workflows/doctum.yml with: title: "Google Cloud PHP Tools" - default_version: ${{ github.ref_name }} + default_version: ${{ github.head_ref || github.ref_name }} dry_run: true