Add this `.yml` file to your repo to give it a GitHub Actions-based shell
Tags: actionshackathon, github, opensource
Published: 2020-08-19 19:50:39

---
title: Add this `.yml` file to your repo to give it a GitHub Actions-based shell
published: true
description: My submission to the GitHub Actions x DEV Hackathon!
tags: actionshackathon, github, opensource
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/xlkrnwg29qdunqq2ivx5.png
---

### My Workflow
[Note]: # (Make sure to include the name of your GitHub Action and share where it's being used!)

**tl;dr:** Adding this `.yml` file to your repository and you’ll get a GitHub Actions-based shell where you can run arbitrary commands from your browser.

![Screenshot](https://dev-to-uploads.s3.amazonaws.com/i/xlkrnwg29qdunqq2ivx5.png)

**Background:** I occasionally find myself making large-scale automated codebase changes. For example, changing ESLint config or upgrading Prettier version, affecting hundreds of files.

For a large project, merge conflicts are bound to happen, as many engineers work on it simultaneously and merge their branches several times per day.

Because of this, when I work on PRs with automated codebase changes, I like to also put the script I use into the PR description. I would write something like this:

> To re-generate the contents of this PR based on the latest master branch, run this script:
>
> ```
> git fetch && \
>   git checkout origin/master && \
>   yarn add --dev --exact -W prettier && \
>   yarn prettier --write . && \
>   git add -A && \
>   git commit -n -m 'Upgrade to latest prettier' && \
>   git push -f origin HEAD:refs/heads/dtinth/prettier-upgrade
> ```

But even with this automated script, I still find it a bit inconvenient whenever I want to update this PR, because I might be working on something else. I would have to stash my changes, run the script, and switch back to my original branch. A context switching cost right there.

With the recently-announced [support for manually triggered workflows](https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/), I can now ask GitHub Actions to do it for me, so I can continue working on my feature branch.

All I have to do is put this `.yml` file in the repository.

### Submission Category: 

Wacky Wildcards


### Yaml File or Link to Code

`.github/workflows/shell.yml`

```yml
name: "GitHub Actions Shell"
on:
  workflow_dispatch:
    inputs:
      command:
        description: 'The command to run'
        required: true
jobs:
  run:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - run: ${{ github.event.inputs.command }}
    env:
      GIT_COMMITTER_NAME: GitHub Actions Shell
      GIT_AUTHOR_NAME: GitHub Actions Shell
      EMAIL: github-actions[bot]@users.noreply.github.com
```

### Additional Resources / Info

When you add the `.yml` file to your repository, you will see a new workflow appear in the **Actions** tab:

![Screenshot](https://dev-to-uploads.s3.amazonaws.com/i/cpzpr5uw1g4wtx7oye3n.png)

You can then click on the **Run workflow** button and type in the command that you want to run.

![Screenshot](https://dev-to-uploads.s3.amazonaws.com/i/94a2n3qr2qzpvxwjuc6q.png)

Here, GitHub Actions formatted the README file using Prettier and pushed it to the repository.

![Screenshot](https://dev-to-uploads.s3.amazonaws.com/i/wvyuv5p3bvvpywqmtb5z.png)

Other use cases include:

- Running other manual maintenance tasks, e.g. updating website screenshots, batch-optimizing images, etc.

- Manually publishing packages, e.g. `npm publish`

- Prototyping new actions by manually running them on GitHub Actions before writing the actual workflow file. (If you find yourself having to make many changes to your workflow file before getting it to work, having a shell might help!)

- Running ad-hoc tasks on the default branch (such as `yarn audit`), while working on something else locally. 

That’s it, Thanks for reading!