diff --git a/.github/workflows/update-wp-cli-commands b/.github/workflows/update-wp-cli-commands deleted file mode 100644 index 83e108f..0000000 --- a/.github/workflows/update-wp-cli-commands +++ /dev/null @@ -1,37 +0,0 @@ -name: Update WP-CLI Commands List -on: - workflow_dispatch: - schedule: - # Once a day at 6am - - cron: "0 6 * * *" -jobs: - wp-cli: - name: WP CLI Commands List - runs-on: ubuntu-latest - permissions: - contents: write - strategy: - fail-fast: true - steps: - - name: Check out source code - uses: actions/checkout@v3 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - tools: wp-cli - - - name: Generate WP-CLI Commands List - run: wp cli cmd-dump > ${{ github.workspace }}/cli/data/wpcli-commands.json - - - name: Get WP-CLI version - run: wp --version > ${{ github.workspace }}/cli/data/wpcli-version.txt - - - name: Commit any changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: 'Update WP-CLI Commands List' - commit_options: '--no-verify' - commit_user_name: 'GitHub Actions' - commit_user_email: 'github-actions[bot]@users.noreply.github.com' - commit_author: 'GitHub Actions ' diff --git a/.github/workflows/update-wp-cli-commands.yml b/.github/workflows/update-wp-cli-commands.yml new file mode 100644 index 0000000..065b3d5 --- /dev/null +++ b/.github/workflows/update-wp-cli-commands.yml @@ -0,0 +1,31 @@ +name: Update WP-CLI Commands List +on: + workflow_dispatch: + schedule: + # Once a day at 6am + - cron: "0 6 * * *" +jobs: + wp-cli: + name: WP CLI Commands List + runs-on: ubuntu-latest + permissions: + contents: write + strategy: + fail-fast: true + steps: + - name: Check out source code + uses: actions/checkout@v3 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + tools: wp-cli, composer + + - name: Generate WP-CLI Commands List + run: wp cli cmd-dump > ${{ runner.temp }}/wpcli-commands.json + + - name: Get WP-CLI version + run: wp --version > ${{ runner.temp }}/wpcli-version.txt + + - name: Ingest WP-CLI Commands List + run: cd cli && composer install && ./bin/docsdangit ingest --source=wp-cli --cli-dump-path=${{ runner.temp }}/wpcli-commands.json --cli-version-path=${{ runner.temp }}/wpcli-version.txt diff --git a/cli/src/Command/Ingest.php b/cli/src/Command/Ingest.php index 0ae415d..b092f13 100644 --- a/cli/src/Command/Ingest.php +++ b/cli/src/Command/Ingest.php @@ -31,7 +31,9 @@ protected function configure() ->setDescription("Ingest docs") ->setDefinition( new InputDefinition([ - new InputOption('source', 's', InputOption::VALUE_OPTIONAL, 'Docs source (wp-docs, php-docs, wp-cli, wp-dev). All sources by default.') + new InputOption('source', 's', InputOption::VALUE_OPTIONAL, 'Docs source (wp-docs, php-docs, wp-cli, wp-dev). All sources by default.'), + new InputOption('cli-dump-path', 'dp', InputOption::VALUE_OPTIONAL, 'WP CLI dump file path'), + new InputOption('cli-version-path', 'vp', InputOption::VALUE_OPTIONAL, 'WP CLI version file path') ]) ); } @@ -53,7 +55,9 @@ protected function execute(InputInterface $input, OutputInterface $output) } if( ! $source || 'wp-cli' === $source ) { $output->writeln('🚀 Ingesting WP CLI Docs...'); - $wp_docs = new WP_CLI(); + $cli_dump_path = $input->getOption('cli-dump-path'); + $cli_version_path = $input->getOption('cli-version-path'); + $wp_docs = new WP_CLI( $cli_dump_path, $cli_version_path ); $wp_docs->parse(); } if( ! $source || 'php-docs' === $source ) { diff --git a/cli/src/Parsers/WP_CLI.php b/cli/src/Parsers/WP_CLI.php index db6fcfe..5e874bf 100644 --- a/cli/src/Parsers/WP_CLI.php +++ b/cli/src/Parsers/WP_CLI.php @@ -13,21 +13,27 @@ class WP_CLI implements Parser { private $wp_cli_version; + private $dump_path = 'data/wpcli-commands.json'; + private $cli_version_path = 'data/wpcli-version.txt'; - public function __construct() { + public function __construct( $dump_path = null, $cli_version_path = null ) { $this->wp_cli_version = $this->get_source_version(); + if( $dump_path ) { + $this->dump_path = $dump_path; + } + if( $cli_version_path ) { + $this->cli_version_path = $cli_version_path; + } } public function parse() { - $file = 'data/wpcli-commands.json'; - $raw = file_get_contents( $file ); + $raw = file_get_contents( $this->dump_path ); $json = json_decode( $raw ); $this->process_subcommands( $json->subcommands, 'https://developer.wordpress.org/cli/commands/', [] ); } public function get_source_version() { - $file = 'data/wpcli-version.txt'; - $raw = file_get_contents( $file ); + $raw = file_get_contents( $this->cli_version_path ); return str_replace("WP-CLI ", "", $raw); }