From dc4140d3bd01bce52e612d613692f06e880992cb Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Mon, 28 Aug 2023 17:08:25 -0400 Subject: [PATCH 1/2] First stab at installation of composer dependencies via issue ops --- .../ISSUE_TEMPLATE/wordpress-dependency.yml | 70 ++++++++++++++++ .github/actions/composer/action.yml | 81 +++++++++++++++++++ .github/workflows/composer-dependency.yml | 46 +++++++++++ .../examples/dryrun-production.yml | 0 .../examples/dryrun-staging.yml | 0 .../examples/eject-production.yml | 0 .../examples/sage10-build-test.yml | 0 7 files changed, 197 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/wordpress-dependency.yml create mode 100644 .github/actions/composer/action.yml create mode 100644 .github/workflows/composer-dependency.yml rename .github/{ => workflows}/examples/dryrun-production.yml (100%) rename .github/{ => workflows}/examples/dryrun-staging.yml (100%) rename .github/{ => workflows}/examples/eject-production.yml (100%) rename .github/{ => workflows}/examples/sage10-build-test.yml (100%) diff --git a/.github/ISSUE_TEMPLATE/wordpress-dependency.yml b/.github/ISSUE_TEMPLATE/wordpress-dependency.yml new file mode 100644 index 0000000..c49d209 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/wordpress-dependency.yml @@ -0,0 +1,70 @@ +name: Add or remove a WordPress theme or plugin +description: Make a pull request to add or remove a WordPress theme or plugin. +labels: ["dependencies"] + +title: "[package-name]" + +body: +- type: dropdown + id: action + attributes: + label: Action + description: | + The action to perform. + options: + - require + - remove + default: 0 + validations: + required: true + +- type: dropdown + id: repository + attributes: + label: Type of dependency + description: | + The repository to use. + options: + - wpackagist-plugin + - wpackagist-theme + default: 0 + validations: + required: true +- type: input + id: package + attributes: + label: Package Slug + placeholder: my-package + validations: + required: true +- type: input + id: version + attributes: + label: Version + placeholder: 1.0.0 + validations: + required: true +- type: dropdown + id: constraint + attributes: + label: Version Constraint + description: | + The constraint to use when installing the plugin. See [Composer documentation](https://getcomposer.org/doc/articles/versions.md#versions-and-constraints) for more information. + options: + - "^" + - "=" + - ">=" + - "<=" + - "*" + default: 0 + validations: + required: true +- type: checkboxes + id: changedTitle + attributes: + label: Have you changed the title of this issue? + description: | + If you have changed the title of this issue to include the plugin name, please check this box. + options: + - label: I promise I changed the title of this issue to include the plugin name. + required: true diff --git a/.github/actions/composer/action.yml b/.github/actions/composer/action.yml new file mode 100644 index 0000000..ea011d0 --- /dev/null +++ b/.github/actions/composer/action.yml @@ -0,0 +1,81 @@ +name: '🐘 WordPress Packagist action' +description: 'Manipulate a WordPress Packagist dependency' + +inputs: + # The action to take + action: + description: 'The action to take' + required: true + default: 'require' + + # The repository to use + repository: + description: 'The repository to use' + required: true + default: '""' + + # The package to install + package: + description: 'The package to install' + required: true + default: '""' + + # The version to install + version: + description: 'The version to install' + required: true + default: '""' + + # The version constraint to set + constraint: + description: 'The version constraint to set' + required: true + default: '""' + + # The path to the composer.json file + composer_json_path: + description: 'The path to the composer.json file' + required: true + default: '""' + + # The actor + actor: + description: 'The actor' + required: true + default: '""' + + # Issue number + issue_number: + description: 'The issue number' + required: true + default: '""' + + # GitHub token + github_token: + description: 'The GitHub token to use' + required: true + +runs: + using: 'composite' + steps: + + # Perform the composer action + - name: Perform the composer action + uses: php-actions/composer@v6 + with: + command: | + ${{ inputs.action }} ${{ inputs.repository }}/${{ inputs.package }}:${{ inputs.constraint }}${{ inputs.version }} + args: --no-interaction --no-progress --working-dir=site + + # Create a pull request from the new branch to the branch specified in env + - name: Create pull request + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ inputs.github_token }} + add-paths: ./site/composer.json, ./site/composer.lock + commit-message: 'Plugin request from ${{ inputs.actor }}: ${{ inputs.action }} ${{ inputs.repository }}/${{ inputs.package }} ${{ inputs.version }}' + title: 'Plugin request from ${{ inputs.actor }}: ${{ inputs.action }} ${{ inputs.repository }}/${{ inputs.package }} ${{ inputs.version }}' + body: 'Closes #${{ inputs.issue_number }}' + branch: ${{ inputs.repository }}-${{ inputs.package }}-${{ inputs.version }} + base: ${{ env.environment }} + labels: 'composer, ${{ inputs.action }}, ${{ inputs.repository }}, ${{ inputs.package }}' diff --git a/.github/workflows/composer-dependency.yml b/.github/workflows/composer-dependency.yml new file mode 100644 index 0000000..c78805a --- /dev/null +++ b/.github/workflows/composer-dependency.yml @@ -0,0 +1,46 @@ +# .github/workflows/composer-dependency.yml +## +# Add and remove WordPress themes or plugins using Composer. +## + +name: 🐘 Composer Dependency +run-name: composer-dependency + +# Run when a new issue is opened +on: + issues: + types: [opened] + +env: + environment: staging + +jobs: + composer-plugin: + if: ${{ github.event.label.name == 'dependencies' }} + runs-on: ubuntu-latest + steps: + # Checkout the repo's staging branch. + - uses: actions/checkout@v3 + with: + ref: ${{ env.environment }} + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo + + # Parse the issue + - uses: stefanbuck/github-issue-parser@v3 + id: issue-parser + with: + template-path: ./.github/ISSUE_TEMPLATE/plugin.yml + + # Install or remove WordPress plugins using Composer + - uses: ./.github/actions/composer + name: Composer Action + with: + action: ${{ steps.issue-parser.outputs.issueparser_action }} + repository: ${{ steps.issue-parser.outputs.issueparser_repository }} + package: ${{ steps.issue-parser.outputs.issueparser_package }} + version: ${{ steps.issue-parser.outputs.issueparser_version }} + constraint: ${{ steps.issue-parser.outputs.issueparser_constraint }} + composer_json_path: ./site/composer.json + actor: ${{ github.actor }} + issue_number: ${{ github.event.issue.number }} + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/examples/dryrun-production.yml b/.github/workflows/examples/dryrun-production.yml similarity index 100% rename from .github/examples/dryrun-production.yml rename to .github/workflows/examples/dryrun-production.yml diff --git a/.github/examples/dryrun-staging.yml b/.github/workflows/examples/dryrun-staging.yml similarity index 100% rename from .github/examples/dryrun-staging.yml rename to .github/workflows/examples/dryrun-staging.yml diff --git a/.github/examples/eject-production.yml b/.github/workflows/examples/eject-production.yml similarity index 100% rename from .github/examples/eject-production.yml rename to .github/workflows/examples/eject-production.yml diff --git a/.github/examples/sage10-build-test.yml b/.github/workflows/examples/sage10-build-test.yml similarity index 100% rename from .github/examples/sage10-build-test.yml rename to .github/workflows/examples/sage10-build-test.yml From f4e9b129b308473ee6dfba4dfaa77bdf3a3282d2 Mon Sep 17 00:00:00 2001 From: MWDelaney Date: Mon, 28 Aug 2023 17:14:39 -0400 Subject: [PATCH 2/2] Update README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 95183d5..b387836 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ Automatically deploy your [Trellis](https://roots.io/trellis/)-based WordPress s - 🔑 **Re-set deployment keys on-demand** when you need to change who has access to `staging` or `production`. - 📦 **WordPress plugin, core, and theme updates** managed with [Dependabot](https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates). - 📝 **Optionally generates README.md** with deployment status badges and setup instructions. +- 🚩 **Manage WordPress Dependencies** with issue-ops. Install or remove plugins and themes by submitting a GitHub issue. ### Optional Additional Workflows @@ -114,6 +115,15 @@ This action replaces the current deploy keys with keys with keys defined in one Updates the README.md with the current deployment status badges. This action can be run manually from the "Actions" tab in GitHub. +
+🐘 Composer Dependency + +```md +.github/workflows/composer-dependency.yml +``` + +Generates a pull request against the `staging` branch to install a WordPress theme or plugin via composer. This action runs when a new ticket is submitted that uses the "wordpress-dependency.yml" template. +
### Optional Workflows