DEV Community

Cover image for Github Action - Clean up resources
Duc Ng
Duc Ng

Posted on

2 1

Github Action - Clean up resources

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).
Enter fullscreen mode Exit fullscreen mode

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

Links

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay