Skip to content

Repository files navigation

Action to manage GitHub deployments

Features:

  • create a deployment (and invalidate all previous deployments)
  • delete all deployments in specific environment
  • delete a deployment by id

Usage

create

Inputs:

parameterdescription
tokenRequired token to authorize calls to GitHub API, can be ${{github.token}} to create a deployment for the same repo
typeRequired type of an action. Should be create to create a deployment
logsurl to the deployment logs
environmentenvironment to create a deployments in, default to $context.ref without prefixes ('refs/heads/', 'deploy-'), i.e. branch name
environment_urllink to the deployed application
descriptionoptional description, defaults to "deployed by $context.actor"
job_statuspass ${{job.status}} to set the deployment completion status post script accordingly
slack_tokenoptional token of slack integration to post messages with deployment results
slack_channeloptional slack channel name (both slack_token and slack_channel are required to post a message)

Outputs:

outputdescription
deployment_idThe id of the created deployment

Example usage

- name: create a deploymentuses: npm/action-deploy@v2with:
type: createtoken: ${{github.token}}logs: https://your-app.com/deployment_logsenvironment: stagingenvironment_url: https://staging.your-app.comjob_status: ${{job.status}} # use this to track success of the deployment in post script

delete-all

Allows deleting all deployments for a specific environment

Inputs:

parameterdescription
tokenRequired token to authorize calls to GitHub API, can be ${{github.token}} to create a deployment for the same repo
typeRequired type of an action. Should be delete-all
environmentenvironment to delete all deployments in

Outputs: none

Example usage

- name: delete all deployments in staginguses: npm/action-deploy@v2with:
type: delete-alltoken: ${{github.token}}environment: staging

delete

Given in one of the previous steps you created a deployment, with delete you can delete it by id

Inputs:

parameterdescription
tokenRequired token to authorize calls to GitHub API, can be ${{github.token}} to create a deployment for the same repo
typeRequired type of an action. Should be delete
deployment_idRequired the id of the a deployment to delete

Outputs: none

Example usage

- name: create a deploymentuses: npm/action-deploy@v2id: create-deploymentwith:
type: createtoken: ${{github.token}}logs: https://your-app.com/deployment_logsenvironment: stagingenvironment_url: https://staging.your-app.comjob_status: ${{job.status}}# add your deployment steps here
- name: placeholder for actual deploymentrun: sleep 10s
- name: delete deploymentuses: npm/action-deploy@v2with:
type: deletetoken: ${{github.token}}deployment_id: ${{steps.create-deployment.outputs.deployment_id}}

Development

Prerequisites

Install the dependencies

$ npm install

Build the typescript and package it for distribution

$ npm run build && npm run pack

Run the tests ✔️

$ npm run build && npm test

Update action.yml

The action.yml contains defines the inputs and output for your action.

Update the action.yml with description, inputs and outputs for your action.

See the documentation

Change the Code

Most toolkit and CI/CD operations involve async operations so the action is run in an async function.

import*ascorefrom'@actions/core';
...
asyncfunctionrun(){try{
...
}catch(error){core.setFailed(error.message);}}run()

See the toolkit documentation for the various packages.

Publish to a distribution branch

Actions are run from GitHub repos so we will checkin the packed dist folder.

Then run ncc and push the results:

$ npm run pack
$ git add dist
$ git commit -a -m "prod dependencies"
$ git push origin releases/v1

Your action is now published! 🚀

See the versioning documentation

Validate

You can now validate the action by referencing ./ in a workflow in your repo (see test.yml])

- uses: ./name: Delete all deploymentswith:
token: ${{github.token}}type: delete-all

See the actions tab for runs of this action! 🚀

Deploy

After testing you can create a v1 tag to reference the stable and latest V1 action

About

Action to manage GitHub deployments

Topics

Resources

Stars

13 stars

Watchers

7 watching

Forks

Releases

Used by

Contributors

Languages