Create an action
For day 1 operations, HCP Waypoint lets you create templates to define common infrastructure patterns and add-ons to let users add modular components to their applications. After an application is deployed and running, users may need to perform day 2 operations to maintain their application, such as rotate secrets, rebuild a database index, or flush an application's cache.
HCP Waypoint actions let platform engineers standardize and expose day 2 operations to developers, so application developers can run these operations quickly and safely.
In this tutorial, you will create an HCP Waypoint action to merge a development branch in the main branch of your GitHub repository and deploy a new version of the static website.
Prerequisites
To complete this tutorial, you will need the following:
- A HashiCorp Cloud Platform (HCP) account with HCP Terraform Plus tier subscription.
- A GitHub account and a personal access token with
repo
anddelete_repo
permissions.
This tutorial builds on the Use a Waypoint template tutorial. You must complete it before you start this tutorial.
Create a Waypoint action
Log in to HCP and navigate to the Waypoint page. Click on the Actions option from the left navigation and then click on the Create an action button.
Enter the following information for the action:
Field | Value |
---|---|
Action name | Merge Branch |
Description | Merge the specific branch into the main branch |
Under Variables, create the follow variables:
Key | Value | Sensitive | Enable this value to be defined when the action is triggered |
---|---|---|---|
branch | dev | No | Yes |
gh_token | Your GitHub personal access token | Yes | No |
The Enable this value to be defined when the action is triggered option lets users define the branch
value when they run the action. It will default to dev
.
Set the Action type to Custom.
Under Action details, set the following values:
Field | Value |
---|---|
Method | POST |
Source URL | https://api.github.com/repos/${application.outputs.repo_name}/merges |
Body | {"base":"main","head":"${var.branch}","commit_message":"Merged from Waypoint"} |
Notice that the Source URL refers to the application.outputs.repo_name
variable. HCP Waypoint makes the outputs for the application the action is associated with available to you when you create the action. The Body refers to the var.branch
variable you created in this step, which the user can define when they run the action.
Under Headers, create the following headers for the request:
Key | Value |
---|---|
Accept | application/vnd.github+json |
Authorization | Bearer ${var.gh_token} |
X-GitHub-Api-Version | 2022-11-28 |
The Authorization
header refers to the gh_token
variable you created in this step.
To finish creating the action, click Create action.
Assign the action to the application
After you create the action, HCP Waypoint brings you back to the Actions page and shows all of the actions in your HCP project. Click the Merge Branch action name to navigate to the action overview page.
Click Assignments, then click Applications. This page shows all of the applications that have access to this action. To assign this action to your application, click Manage, then click Edit assignments.
HCP Waypoint shows you the list of all applications in your HCP project. Check the checkbox next to the mywebapp
application, then click Confirm. HCP Waypoint shows a summary of the assignment changes. Click Apply to assign the action to your application.
Update the website
Next, you will push some changes to a development branch of the GitHub repository you created in the Use a Waypoint template tutorial.
Create a new branch in your cloned mywebapp
that you will push your changes to.
Next, open the main.css
stylesheet and update the background-color
and color
attributes in the body
element to match what is below.
Commit your changes locally.
Then push your changes to the remote dev
branch.
Run the action
Now that you've made a new branch and committed changes to it, use the action to merge the changes to the main
branch. Once you merge the changes, GitHub will automatically deploy a new version of the static website.
- Navigate to the Applications page.
- Choose your
mywebapp
application. - Click the Actions dropdown.
- Click the Merge Branch action.
- Click Run.
HCP Waypoint prompts you to provide a value for the branch
variable. For this example, leave the default value of dev
you configured earlier. Since this action lets users define the variable when they run the action, they can merge any branch into main. This makes the action more flexible.
When you run the action, HCP Waypoint sends the HTTP POST request you configured earlier to GitHub to merge the dev
branch into the main
branch. Since your static website is based on the main
branch, GitHub automatically deploys the new version of the website.
Verify that the action merged the dev
branch into the main
branch by navigating to the GitHub repository. You will see that the latest commit to the main branch has the comment "Merged from waypoint" that you defined in the action definition.
Next, open the website that you deployed with Waypoint. You can find the website URL under the Outputs tab of your application overview. You will see the changes you made to the website.
Next steps
In this tutorial, you created an HCP Waypoint action to merge an arbitrary branch into the main
branch of your repository. Actions enable platform operators to automate and standardize common steps for application teams to perform day 2 operations. To learn more, refer to the following resources.
- HCP Waypoint concepts: actions
- Create and mange actions documentation
- Using HCP Waypoint as your Internal Developer Platform
Continue on to the next tutorial to learn how to clean up your Waypoint application and the infrastructure associated with it.