diff --git a/composer.json b/composer.json index 56e1af2..414ce6e 100755 --- a/composer.json +++ b/composer.json @@ -1,5 +1,5 @@ { - "name": "moodlehq/moodle-plugin-ci", + "name": "brickfield/moodle-plugin-ci", "description": "Helps running Moodle plugins analysis checks and tests under various CI environments.", "keywords": ["moodle", "travis", "ci", "testing", "github", "actions"], "type": "project", diff --git a/docs/AddExtraPlugins.md b/docs/AddExtraPlugins.md index 52bdef2..c2fa85d 100644 --- a/docs/AddExtraPlugins.md +++ b/docs/AddExtraPlugins.md @@ -27,6 +27,19 @@ install: - moodle-plugin-ci install ``` +If you need to add a plugin contained within a private repo, you can use a [Github encrypted secret](https://docs.github.com/en/actions/reference/encrypted-secrets). +In the example below, the secret is named 'REPO_TOKEN'. The value of the secret should be a [Personal access token](https://docs.github.com/en/github/authenticating-to-github/keeping-your-account-and-data-secure/creating-a-personal-access-token) +that has access to the repository you are adding. +NOTE - This is a security risk, as the PAT will be sent to moodle-plugin-ci. The PAT could be captured at this point, and allow +unwanted users any access the PAT grants. Storing the secret makes it less visible, but it could still be captured in the transfer +or in the moodle-plugin-ci script. For this reason, you will probably want to use your own fork of the plugin-ci script. + +```yaml +install: + - moodle-plugin-ci add-plugin --branch main --token "${{ secrets.REPO_TOKEN }}" username/project + - moodle-plugin-ci install +``` + If you are not using GitHub and want to provide your own Git clone URL, then you can use the `--clone` (`-c`) option. Here is an example (Note, you can use the `--branch` option together with the `--clone` option if you need to): diff --git a/src/Command/AddPluginCommand.php b/src/Command/AddPluginCommand.php index 42fbfee..aca31e2 100644 --- a/src/Command/AddPluginCommand.php +++ b/src/Command/AddPluginCommand.php @@ -49,6 +49,7 @@ protected function configure() ->setDescription('Queue up an additional plugin to be installed in the test site') ->addArgument('project', InputArgument::OPTIONAL, 'GitHub project, EG: moodlehq/moodle-local_hub, can\'t be used with --clone option') ->addOption('branch', 'b', InputOption::VALUE_REQUIRED, 'The branch to checkout in plugin repo (if non-default)', null) + ->addOption('token', 't', InputOption::VALUE_REQUIRED, 'The PAT to login to the plugin repo (if non-default)', null) ->addOption('clone', 'c', InputOption::VALUE_REQUIRED, 'Git clone URL, can\'t be used with --project option') ->addOption('storage', null, InputOption::VALUE_REQUIRED, 'Plugin storage directory', 'moodle-plugin-ci-plugins'); } @@ -66,13 +67,14 @@ protected function execute(InputInterface $input, OutputInterface $output) $branch = $input->getOption('branch'); $clone = $input->getOption('clone'); $storage = $input->getOption('storage'); + $token = $input->getOption('token'); if (!empty($project) && !empty($clone)) { throw new \InvalidArgumentException('Cannot use both the project argument and the --clone option'); } if (!empty($project)) { /** @psalm-suppress PossiblyInvalidArgument */ - $cloneUrl = sprintf('https://github.com/%s.git', $project); + $cloneUrl = sprintf('https://%s@github.com/%s.git', $token, $project); } elseif (!empty($clone)) { $cloneUrl = $clone; } else {