Skip to main content

Guide: Unraveling GitHub Actions - Spend Less, Do More

How Can We Save Money & Increase Efficiency?

To achieve this, we must find answers to specific questions. One challenge I faced was improving our test and lint workflows even further: "Although I have already enhanced the speed of our test and lint workflows, can I accelerate them more or reduce the costs associated with running them?" The answer came from a project I discovered during my R&D phase—nektos/act. This tool aims to perfectly mimic GitHub Actions, allowing you to make frequent updates and commits without needing to push each change to check if your tests or lints pass.

Installing act

I regularly use Ubuntu 22.04 on WSL2, and your setup might be different. Thus, this guide might not perfectly fit everyone's needs. For more detailed support, please visit the act homepage.

  1. First, install nektos/act using this command:
  2. curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash
  3. Add it to your PATH:
  4. nano ~/.bashrc
  5. At the end of the file, add the following line:
  6. export PATH="$HOME/bin:$PATH"
  7. Apply the changes by running:
  8. source ~/.bashrc

Act is Installed, Now What?

With act installed, you can now run commands from any directory on your machine. Verify its installation by checking its version with this command:

act --version

Useful act Commands to Remember

Here’s how to list all your workflows:

act -l

This command displays various details about your workflows, like the stage, job ID, job name, and associated files. Here’s an example of what you might see:

Stage | Job ID | Job name | Workflow name | Workflow file | Events
0     | lint   | Lint     | Lint and Test | lint.yml      | push
0     | test   | Test PHP | Test Suite    | test.yml      | push

To run a specific job, use the job ID with the following command:

act -j <Job ID>

By selecting a workflow job ID, you can execute individual tasks efficiently without running the entire workflow. This is a great way to save time and resources during development.

Comments

Popular posts from this blog

Guide: Unraveling GitHub Actions - Detecting Changes Between Commits

While working at  Hire Dragons , I was assigned the task of creating a GitHub Action workflow. This workflow was designed to use Laravel Pint to check for any changes in the codebase. On our local and off-site development machines, this task would take just a few moments. However, on GitHub, it would take 5-6 minutes to complete. Although you get many free Action minutes, we didn’t want to waste these credits on every commit. Therefore, I began exploring ways to speed up this process. During my research and development, I considered making a list of changes between commit hashes. This turned out to be the quickest method. Let's start off with the code used name: Lint on: push jobs: lint: name: Lint runs-on: ubuntu-latest steps: - name: Checkout uses: actions/checkout@v2 - name: Setup PHP uses: shivammathur/setup-php@v2 with: php-version: '8.2' tools: phplint, laravel/pint - name: Get list of cha...

Open source: Simplifying the Ramp API

Why I Started This Project While working at Hire Dragons , I encountered a big challenge. There was a task that needed to be automated completely. Every day, someone would log into Ramp.com to handle routine tasks like checking upcoming shifts on our website and pre-filling a card using the Ramp service. This was their whole job because we have over 1,000 Dragons (users) possibly working shifts each day. How I Solved the Problem Initially, I looked into integrating a solution directly into our existing codebase. However, it seemed too complex and I thought, "Why not make this an open-source project?" Since the Ramp API is accessible to anyone with an account, I decided to share the fun with everyone! I created a project called "ramp-api" on GitHub to make using the Ramp API as easy as possible for developers. Getting Started with the Ramp API Package To use this package, first, you need to set up your configuration file. You can do this...