-
Notifications
You must be signed in to change notification settings - Fork 384
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
base: develop
Are you sure you want to change the base?
Automate docs generation #6188
Changes from 31 commits
79aa308
3fb8d39
9e3a404
236da02
af434bb
407964e
5c9f7cd
a2b88bf
606e236
9672a9e
ca050f9
1790607
77d6c77
2361d5f
66c4e98
ae71054
1c1eb5d
5ccc6ce
4aa0396
d1a17e8
3d62de6
181735d
5755184
b949a4b
3bad88a
515e32a
cf09327
14aa516
cc1f3cb
4cd77d6
8b04983
68eb9ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" | ||
|
||
- 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
]; | ||
|
||
if ( ! empty( $file->uses ) ) { | ||
|
There was a problem hiding this comment.
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.