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

Automate docs generation #6188

Open
wants to merge 32 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
79aa308
Add workflow to automate docs generation
pierlon May 8, 2021
3fb8d39
Create branch when checking out
pierlon May 8, 2021
9e3a404
Pass `GITHUB_TOKEN` to step that use GH CLI
pierlon May 8, 2021
236da02
Add step to setup WordPress
pierlon May 9, 2021
af434bb
Note what's going on
pierlon May 9, 2021
407964e
Disable TTY allocation
pierlon May 9, 2021
5c9f7cd
[skip ci] Wait until DB is ready
pierlon May 9, 2021
a2b88bf
[skip ci] Quote env var
pierlon May 9, 2021
606e236
[skip ci] Create file in correct dir
pierlon May 9, 2021
9672a9e
[skip ci] Set user to generate docs without permission errors
pierlon May 9, 2021
ca050f9
[skip ci] Fix logic
pierlon May 9, 2021
1790607
[skip ci] Configure git user
pierlon May 9, 2021
77d6c77
[skip ci] Push branch
pierlon May 9, 2021
2361d5f
[skip ci] Check if remote branch already exists
pierlon May 9, 2021
66c4e98
[skip ci] Fail if no changes
pierlon May 10, 2021
ae71054
[skip ci] Set PHP version
pierlon May 10, 2021
1c1eb5d
[skip ci] Fix logic
pierlon May 10, 2021
5ccc6ce
[skip ci] Make workflow successful even if no changes
pierlon May 10, 2021
4aa0396
[skip ci] Checkout before making changes
pierlon May 10, 2021
d1a17e8
[skip ci] Merge changes from base branch
pierlon May 10, 2021
3d62de6
[skip ci] Only create PR if branch doesn't exist
pierlon May 10, 2021
181735d
[skip ci] Merge from origin
pierlon May 10, 2021
5755184
[skip ci] Fetch all commits
pierlon May 10, 2021
b949a4b
[skip ci] Configure git user before committing
pierlon May 10, 2021
3bad88a
[skip ci] Remove `root` key from each file object
pierlon May 10, 2021
515e32a
[skip ci] Determine branch names
pierlon May 10, 2021
cf09327
[skip ci] Fix syntax error
pierlon May 10, 2021
14aa516
[skip ci] Fix env var
pierlon May 10, 2021
cc1f3cb
[skip ci] Escape branch name
pierlon May 10, 2021
4cd77d6
[skip ci] Group some log lines
pierlon May 10, 2021
8b04983
Merge branch 'develop' into enhancement/5520-docs-generation
pierlon Jun 14, 2021
68eb9ed
Merge branch 'develop' into enhancement/5520-docs-generation
thelovekesh Nov 28, 2022
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
128 changes: 128 additions & 0 deletions .github/workflows/generate-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
name: Plugin Documentation

on:
workflow_dispatch:

jobs:
generate_docs:
name: 'Generate documentation'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
# Fetch history for all branches and tags to allow for successful merge of base branch if needed.
fetch-depth: 0

- name: Determine branch names
id: branches
run: |
BASE_BRANCH=${GITHUB_REF#refs/heads/}
echo "::set-output name=base::$(echo "$BASE_BRANCH")"
echo "::set-output name=head::$(echo "update/docs-$BASE_BRANCH")"

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'

- name: Get Composer Cache Directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Configure Composer cache
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-

- name: Install Composer dependencies
run: composer install --prefer-dist --optimize-autoloader --no-progress --no-interaction

- name: Setup WordPress
run: |
docker-compose up -d

echo "::group::Get environment vars from containers"
MYSQL_PWD=$(docker-compose exec -T mysql printenv MYSQL_ROOT_PASSWORD)
WORDPRESS_DB_NAME=$(docker-compose exec -T wordpress printenv WORDPRESS_DB_NAME)
HOST_PORT=$(docker-compose port wordpress 80 | awk -F : '{printf $2}')
echo "::endgroup::"

echo "::group::Wait for database container to be ready"
echo -en "Waiting for database connection..."
until $(docker-compose exec -T wordpress bash -c "echo -n > /dev/tcp/mysql/3306" >/dev/null 2>&1); do
echo -n '.'
sleep 5
done
echo ''
echo "::endgroup::"

echo "::group::Installing WordPress"
docker-compose exec -T -e MYSQL_PWD="$MYSQL_PWD" mysql mysql -e "CREATE DATABASE IF NOT EXISTS $WORDPRESS_DB_NAME"
docker-compose exec -T cli wp core install \
--title="Docs" --admin_user=admin --admin_password=password [email protected] --skip-email --url=http://localhost:$HOST_PORT
echo "::endgroup::"

echo "::group::Activate AMP plugin"
# Building the JS assets is required for the plugin to activate successfully, but since we're only generating
# the docs we simply create the file being checked for to save some time.
touch ../../assets/js/amp-block-editor.js
docker-compose exec -T cli wp plugin activate amp
echo "::endgroup::"
working-directory: bin/local-env

- name: Configure git user
run: |
git config user.email "[email protected]"
git config user.name "Pierre Gordon"
Comment on lines +79 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The github-actions bot isn't on the CLA allowlist so I'm using myself for now to make commits.


- name: Check if remote branch exists
id: remote-branch
run: echo ::set-output name=exists::$([[ -z $(git ls-remote --heads origin "$HEAD_BRANCH" ) ]] && echo "0" || echo "1")
env:
HEAD_BRANCH: ${{ steps.branches.outputs.head }}

- name: Create branch to base pull request on
if: steps.remote-branch.outputs.exists == 0
run: git checkout -b "$HEAD_BRANCH"
env:
HEAD_BRANCH: ${{ steps.branches.outputs.head }}

- name: Fetch existing branch to add commits to
if: steps.remote-branch.outputs.exists == 1
run: |
git checkout "$HEAD_BRANCH"
git merge --no-edit "$BASE_BRANCH"
env:
BASE_BRANCH: ${{ steps.branches.outputs.base }}
HEAD_BRANCH: ${{ steps.branches.outputs.head }}

- name: Generate plugin documentation
run: docker-compose exec -T -u $(id --user) cli wp amp docs generate
working-directory: bin/local-env

- name: Check if there are changes
id: changes
run: echo ::set-output name=changed::$([[ -z $(git status --porcelain) ]] && echo "0" || echo "1")

- name: Commit and push changes
if: steps.changes.outputs.changed == 1
run: |
git add --all .
git commit -m "Update documentation"
git push origin "$HEAD_BRANCH"
env:
HEAD_BRANCH: ${{ steps.branches.outputs.head }}

- name: Create pull request
if: steps.changes.outputs.changed == 1 && steps.remote-branch.outputs.exists == 0
run: |
git push -u origin "$HEAD_BRANCH"
gh pr create --base "$BASE_BRANCH" --title "Update documentation for \`$BASE_BRANCH\` branch" --body "" --label Documentation
Copy link
Member

Choose a reason for hiding this comment

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

Do the backticks not get evaluated? I guess not as seen in pierlon#12.

Copy link
Contributor Author

@pierlon pierlon Jun 16, 2021

Choose a reason for hiding this comment

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

Yes.

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BASE_BRANCH: ${{ steps.branches.outputs.base }}
HEAD_BRANCH: ${{ steps.branches.outputs.head }}
1 change: 0 additions & 1 deletion docs/src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ public function parse_files( $files, $root ) {
$out = [
'file' => $this->export_docblock( $file ),
'path' => str_replace( DIRECTORY_SEPARATOR, '/', $file->getFilename() ),
'root' => $root,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure if this key is used anywhere.

With this change the the root key for each file object in the generated JSON file would no longer exist, preventing any unnecessary change to the JSON if it were generated in a different environment from where the docs command was previously run.

];

if ( ! empty( $file->uses ) ) {
Expand Down