loading...
Cover image for Github Action - Clean up resources

Github Action - Clean up resources

ngduc profile image Duc Ng ・1 min read

A typical CI workflow with Github Actions looks like this:

  • Check out git repo.
  • Build project.
  • Deploy to a Demo environment.
  • Clean up the Demo environment after a while.

The last step is what everybody usually forgets or doesn't have time to take care of it. Over time, that will lead to orphaned deployments and surprising bills from cloud providers.

Github Action - clean up resources

Use this Github Action to clean up resources after X minutes by triggering a URL endpoint.

Use cases

  • After deploying to a demo environment, 1 day later, we want it to clean up itself by triggering an API endpoint to remove that demo environment.
  • After running some steps, we want to trigger an endpoint to notify somebody, etc.

Usage

Add this to your Yaml file:

jobs:
  clean:
    runs-on: ubuntu-latest
    steps:
      - name: cleanup
        uses: ngduc/clean-up-action@master
        with:
          projectId: setYourProjectId # set your unique projectId, example: myProjectId1
          expiryMins: 1440 # after X minutes, invoke the below URL endpoint.
          method: 'POST' # one of these methods: GET, POST, PUT, PATCH, DELETE
          url: https://some.cleanup.api.endpoint # some URL endpoint to clean up resources.
          headers: '' # headers (JSON string).
          payload: '{ "someResourceId": 1234 }' # payload for url (JSON string).

I created this little project to help with that cleanup step. I hope you find it useful. Any feedback is appreciated.

Links

Posted on May 23 by:

ngduc profile

Duc Ng

@ngduc

JS enthusiast / 15y tinkering with screens & code.

Discussion

markdown guide