A poor man's way to execute Terminus commands via a Web API, using Github Repository Dispatches and Github Actions.
*This does not require any of the code from the repository the Github Action workflow is associated with.
- Terminus Machine Toke (
TERMINUS_MACHINE_TOKEN
) - SSH Key in PEM format (
PRIVATE_SSH_KEY
)
You will also need a personal Github Token to trigger the repository dispatch.
Use the following steps to configure your workflow environment.
Generate a new SSH key that will be used to authenticate the Github Action container with Pantheon.
ssh-keygen -m PEM -f ~/.ssh/github_action
You need to copy the private key into your repository secrets, and the public key into your Pantheon account. If on a Mac, you can use the pbcopy
command to copy to your clipboard.
pbcopy < ~/.ssh/github_action
- In your Github repo, name the variable
SSH_KEY
and paste in the value. - In your Pantheon account dashboard, paste your public key (
github_action.pub
) into the text field. Consider adjusting the string label at the end of the key to something more descriptive, like Github Action.
- In your Pantheon account dashboard, generate a new Machine Token.
- Copy the value from the browser.
- Open your repository secrets, and create a new variable called
TERMINUS_MACHINE_TOKEN
. - Paste in the machine token and click save.
- Go to your Github tokens
- Click "Generate New Token"
- Give the token a name, and check
workflow
as the only permission (@todo
confirm this) - Click "Generate Token"
- Save the token to use in the next section.
Generate a new request using the following information, but a few important things to note:
- The API path requires the repo owner and name as part of the path (
:repo_owner/:repo_name
) - The authorization is a bearer token and is your Github access token
- If using the provided workflow template, the
event_type
is specific to this workflow. DO NOT CHANGE.
curl --location --request POST 'https://api.github.com/repos/:repo_owner/:repo_name/dispatches' \
--header 'Accept: application/vnd.github.everest-preview+json' \
--header 'Authorization: Bearer <ACCESS TOKEN>' \
--header 'Content-Type: application/json' \
--data-raw '{
"event_type": "remote-terminus",
"client_payload": {
"command": "drush dunder-mifflin-sales.dev -- cr"
}
}'
- Trigger on repository dispatch using the
remote-terminus
event_type key. - Install private SSH key from secrets to authenticate with Terminus user
- Install Terminus and authenticate with machine token from secrets
- Run Terminus command from API payload.