Articles on: Deployments

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:

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:

EventsDescription
pull_requestThe 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@mainOur GitHub Action is live on the marketplace for you to use in the workflows.
GITHUB_TOKENThis is automatically populated by GitHub during workflow runs.
INSTAWP_TOKENYou will need to copy and paste an API Token to your GitHub environment variable.
INSTAWP_TEMPLATE_SLUGSlug of your InstaWP template.
REPO_IDThis is the ID for your InstaWP-connected repository.
INSTAWP_ACTIONAs the name suggests, you can customize which action you want to trigger. Currently, we support two actions - create-site-template and destroy-site.


Step 6: Once you've saved, navigate to your GitHub repository and select the file that you want to make changes.



Step 7: Click on the Edit button and make changes.



Step 8: Click on the Commit Changes, create a new branch and propose changes.



Step 9: Click on the Create pull request to create a new pull request.



This will create new PR and a new site with your PR contents will be deployed. 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'





Edit Template
Using Template

Updated on: 14/02/2024

Was this article helpful?

Share your feedback

Cancel

Thank you!