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

Add action for Hook Documentation Generation #2060

Merged
merged 11 commits into from
Aug 18, 2023
57 changes: 57 additions & 0 deletions .github/workflows/php-hook-documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: PHP Hook Documentation Generator

on:
Copy link
Contributor

Choose a reason for hiding this comment

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

The push and pull_request (with the PHP filter), look fine to me. But I was wondering if it would do any harm to also allow us to run this manually, like here. It's not going to effect our automated flows, and will make it easier if we ever want to run it manually.

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 implemented this suggestions

push:
branches:
- "release/**"
paths:
- "**.php"
- .github/workflows/php-hook-documentation.yml
pull_request:
types:
- opened
branches:
- "release/**"
paths:
- "**.php"
- .github/workflows/php-hook-documentation.yml

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
HookDocumentation:
name: Hook Documentation Generator
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
with:
# Checks out a branch instead of a commit in detached HEAD state
ref: ${{ github.head_ref }}

# This generates the documentation string. The `id` property is used to reference the output in the next step.
- name: Generate hook documentation
id: generate-hook-docs
uses: woocommerce/grow/hook-documentation@actions-v1
with:
debug-output: yes
source-directories: src/,views/
Copy link
Contributor

Choose a reason for hiding this comment

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

What about the main plugin file google-listings-and-ads.php? Is this strictly a list of directories or does it support single files as well?

It so happens we don't have any hooks there now, but considering we want to use it for other extensions the script should be flexible enough to include the main plugin file. If that's not possible then can we log an issue in the Grow repo that this should be fixed?

Copy link
Contributor Author

@puntope puntope Aug 18, 2023

Choose a reason for hiding this comment

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

Seems like its possible as internally it uses Finder()->path()

You can see it here in a test when I added gla_test_action inside the main plugin file.

Screenshot 2023-08-18 at 17 03 01

https://github.com/woocommerce/google-listings-and-ads/actions/runs/5902917550/job/16011805311


- name: Commit hook documentation
shell: bash
# Use the github-actions bot account to commit.
# https://api.github.com/users/github-actions%5Bbot%5D
run: |
git config user.name github-actions[bot]
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
echo "${{ steps.generate-hook-docs.outputs.hook-docs }}" > src/Hooks/README.md
git add src/Hooks/README.md
if git diff --cached --quiet; then
echo "*No documentation changes to commit.*" >> $GITHUB_STEP_SUMMARY
else
echo "*Committing documentation changes.*" >> $GITHUB_STEP_SUMMARY
git commit -q -m "Update hooks documentation from ${{ github.head_ref }} branch."
git push
fi
Loading