# The Life of a GitHub Action

DevFeed: [The Life of a GitHub Action](<https://devfeed.tech/articles/the-life-of-a-github-action-35207.md>)

Original publisher: [Read original article](<https://blog.jessfraz.com/post/the-life-of-a-github-action/>)

Published: 2019-01-13T15:09:26Z

Content type: tutorial

Language: en

Sources: [Jessie Frazelle](<https://devfeed.tech/sources/jessie-frazelle.md>)

Topics: [GitHub](<https://devfeed.tech/topics/github.md>), [Code](<https://devfeed.tech/topics/code.md>), [Pull Request](<https://devfeed.tech/topics/pull-request.md>)

Tags: [branch](<https://devfeed.tech/tags/branch.md>), [cleanup](<https://devfeed.tech/tags/cleanup.md>), [code](<https://devfeed.tech/tags/code.md>), [github](<https://devfeed.tech/tags/github.md>), [github-action](<https://devfeed.tech/tags/github-action.md>), [pull-request](<https://devfeed.tech/tags/pull-request.md>), [repository](<https://devfeed.tech/tags/repository.md>), [workflow](<https://devfeed.tech/tags/workflow.md>)

## AI overview

This tutorial explains what happens when a GitHub Action runs, using a workflow that deletes a repository branch after its pull request is merged. It introduces the workflow file, triggering pull request events, and the Action execution flow.

## Source excerpt

I thought it might be fun to write a blog post on "The Life of a GitHub Action." When you go through orientation at Google they walk you through "The Life of a Query" and it was one of my favorite things. So I am re-applying the same for a GitHub Action. For those unfamiliar Actions was a feature launched at GitHub's conference Universe last year. You can sign up for the beta here. The overall idea is scriptable GitHub but rather than do all that hand-wavy crap to try and explain I will take you through what happens when you run an Action. The Problem Here is a typical workflow: I create a pull request on a repository. The pull request is merged. The branch lingers around until the end of time and eats away at the part of my soul that likes everything to be clean. Let's focus on my pain of the lingering branches. This is totally a problem right? So let's solve it by creating an Action to delete branches after the pull request has been merged. All the code for this action lives here if you want to skip ahead. The Workflow File You can create actions from the UI or you can write the Workflow file yourself. In this post, I am just going to use a file. Here is what it ends up looking like and I will explain what everything means in comments on the file. This lives in .github/main.workflow in your repository. ## Workflow defines what we want to call a set of actions. workflow "on pull request merge, delete the branch" { ## On pull_request defines that whenever a pull request event is fired this ## workflow will be run. on = "pull_request" ## What is the ending action (or set of actions) that we are running. ## Since we can set what actions "need" in our definition of an action, ## we only care about the last actions run here. resolves = ["branch cleanup"] } ## This is our action, you can have more than one but we just have this one for ## our example. ## I named it branch cleanup, and since it is our last action run it matches ## the name in the resolves section above. a