DEV Community

Play Button Pause Button
Brian Douglas for GitHub

Posted on • Updated on

Build your own GitHub Action WITHOUT a Docker Container

GitHub shipped "composite run steps" for the action.yml. This allows developers to build Actions with bash scripts (and other languages too, but more on that at the end).

When GitHub Actions initially shipped in 2018, knowledge of Docker made building your actions more comfortable. By building GitHub Actions I learned Docker is a lot like a Makefile (don't @ me), but even if you don't understand Docker, you now only need to know enough to copy and paste bash from Stackoverflow into your action.yml.

I recently moved my bdougie/take-action to run out of the yml and not look back. Here is that PR.

name: contributor-takes-action
description: This is an action to assign yourself to an issue for a repo you are not a contributor to.
author: Brian Douglas
  icon: 'thumbs-up'
  color: 'white'

  using: "composite"
      run: |
        BODY="$(jq '.comment.body' $GITHUB_EVENT_PATH)"
        ISSUE_NUMBER="$(jq '.issue.number' $GITHUB_EVENT_PATH)"
        LOGIN="$(jq '.comment.user.login' $GITHUB_EVENT_PATH | tr -d \")"
        REPO="$(jq '.repository.full_name' $GITHUB_EVENT_PATH | tr -d \")"
        if [[ $BODY == *".take"* ]]; then
          echo "Assigning issue $ISSUE_NUMBER to $LOGIN"
          echo "Using the link:$REPO/issues/$ISSUE_NUMBER/assignees"
          curl -H "Authorization: token $GITHUB_TOKEN" -d '{"assignees":["'"$LOGIN"'"]}'$REPO/issues/$ISSUE_NUMBER/assignees
      shell: bash
Enter fullscreen mode Exit fullscreen mode

So now the action only needs an action.yml to run. The setup is similar to workflow yamls in repositories, which means you can also run ruby, node, or any other language scripts if you would like. In the steps, including the corresponding setup action. What the composite run steps do. It can now add steps similar to the way you add action steps in your workflows inside your repositories.

// example running a ruby script

  using: "composite"
    - uses: actions/checkout@v2
        ref: ${{ github.head_ref }}
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
        ruby-version: 2.6.5
    - name: Bundle install
      run: |
        bundle install --jobs 4 --retry 3
    - name: create-readme
      run: |
        bundle exec ruby create-readme.rb
      shell: bash
Enter fullscreen mode Exit fullscreen mode

The most significant difference is that this setup is not in my repo workflow but now in a re-usable format. I no longer need to rewrite the script every time I want to have this run in a new project. I also don't need the full-on maintenance required to maintain this batch script.

And I want to shout out crazy-max, who walked me through this on my previous trip Twitch stream. If you are interested in watching me build actions from scratch, I stream it for Tuesday and Friday, live on Twitch. And also, shout out to crazy-max, who is a prolific action creator. He's got quite a few different actions that I use every day, including deploying your site to GitHub pages.

This is part of my 28 days of Actions series. To get notified of more GitHub Action tips, follow the GitHub organization right here on Dev. Learn how to build action with Node.js

Top comments (0)