Github Actions
GitHub Actions is a popular continuous integration and delivery platform for automating your build, test, and deployment workflow. InstaWP allows you to auto-create new instances (and destroy them, optionally) when creating a new Pull Request (PR) on your GitHub repository.
In this documentation, we will explore the steps to trigger GitHub Workflow on Pull Request.
Let’s get started 🚀
Step 1: Create a site and save it as a template. For more information, you can refer to the Create template document.
Step 2: After the template is created, you need to add a deployment and connect it to the template. For more information, please refer to the Connect to Template document.
Step 3: Click on the Deployment icon corresponding to the template for which you want to enable the GitHub actions.

Step 4: Click on the Actions yml File button to copy the GitHub Action yml.

Step 5: Paste this actions yml file contents to your GitHub workflow folder.
For example, here used “`.github/workflows/instawp.yml`”. The contents of this yml file will look similar to this:
Let us look at the yml file contents in detail:
Once you've saved and committed this file to your GitHub repository, whenever a new PR is created, a new site with your PR contents will be deployed, and the GitHub issue will be commented on with details about the new site.

Once the pull request is closed, you can destroy the site as it may longer be required. Modify the yml file and append the following contents:
You may notice that all details except INSTAWP_ACTION, types: [opened, closed, merged] and an extra if statement is added, which plays a vital role.
Edit Template
Using Template
In this documentation, we will explore the steps to trigger GitHub Workflow on Pull Request.
Let’s get started 🚀
Step 1: Create a site and save it as a template. For more information, you can refer to the Create template document.
Step 2: After the template is created, you need to add a deployment and connect it to the template. For more information, please refer to the Connect to Template document.
Step 3: Click on the Deployment icon corresponding to the template for which you want to enable the GitHub actions.

Step 4: Click on the Actions yml File button to copy the GitHub Action yml.

Step 5: Paste this actions yml file contents to your GitHub workflow folder.
For example, here used “`.github/workflows/instawp.yml`”. The contents of this yml file will look similar to this:
name: InstaWP WordPress Testing on: pull_request: types: [opened] jobs: create-wp-for-testing: runs-on: ubuntu-latest steps: - uses: instawp/wordpress-testing-automation@main with: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} INSTAWP_TOKEN: ${{secrets.INSTAWP_TOKEN}} INSTAWP_TEMPLATE_SLUG: anothertemplate2 REPO_ID: 48 INSTAWP_ACTION: create-site-template
Let us look at the yml file contents in detail:
Events | Description |
---|---|
pull_request | The workflow will trigger based on Pull Requests (PR). |
types: [opened] | In this case, it will trigger only when a new PR is opened. |
uses: instawp/wordpress-testing-automation@main | Our GitHub Action is live on the marketplace for you to use in the workflows. |
GITHUB_TOKEN | This is automatically populated by GitHub during workflow runs. |
INSTAWP_TOKEN | You will need to copy and paste an API Token to your GitHub environment variable. |
INSTAWP_TEMPLATE_SLUG | Slug of your InstaWP template. |
REPO_ID | This is the ID for your InstaWP-connected repository. |
INSTAWP_ACTION | As the name suggests, you can customize which action you want to trigger. Currently, we support two actions - create-site-template and destroy-site. |
Once you've saved and committed this file to your GitHub repository, whenever a new PR is created, a new site with your PR contents will be deployed, and the GitHub issue will be commented on with details about the new site.

Once the pull request is closed, you can destroy the site as it may longer be required. Modify the yml file and append the following contents:
action.yml name: InstaWP WordPress Testing on: pull_request: types: [opened, closed, merged] jobs: create-wp-for-testing: [...] destroy-wp-after-testing: runs-on: ubuntu-latest steps: - uses: instawp/wordpress-testing-automation@main if: github.event.action == 'closed' || github.event.action == 'merged' id: destroy-wp with: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} INSTAWP_TOKEN: ${{secrets.INSTAWP_TOKEN}} INSTAWP_DOMAIN: ${{secrets.INSTAWP_DOMAIN}} INSTAWP_TEMPLATE_SLUG: gutenawithkit REPO_ID: 22 INSTAWP_ACTION: destroy-site
You may notice that all details except INSTAWP_ACTION, types: [opened, closed, merged] and an extra if statement is added, which plays a vital role.
action.yml if: github.event.action == 'closed' || github.event.action == 'merged'
Related Articles
Edit Template
Using Template
Updated on: 20/09/2023
Thank you!