The current version of RSQKit is a work in progress. Any content should not be considered final at this stage.
Skip to content Skip to footer

Your tasks: Task automation using GitHub Actions

Step-by-step guide that covers workflow creation, using pre-built actions from the GitHub Marketplace, and automating testing with GitHub Actions.

Task automation using GitHub Actions

Description

GitHub Actions is a powerful automation tool (continuous integration (CI) and continuous delivery (CD) platform) that allows you to define workflows (called actions) for your repository that help automate tasks such as building, testing and deploying code. GitHub Actions enable you to streamline development processes and improve efficiency.

Considerations

  • Ensure your repository has a .github/workflows/ directory where workflow files will be stored.
  • Workflows are defined using YAML files (.yml or .yaml).
  • Actions can be triggered by various GitHub events, such as push, pull_request, or scheduled times.
  • GitHub provides a marketplace with reusable actions that can be integrated into workflows.
  • Understanding basic YAML syntax is essential for configuring GitHub Actions correctly.
  • The workflow execution environment supports different operating systems, including Ubuntu, Windows, and macOS.
  • Review the repository’s security settings to control access to sensitive information, such as API keys and credentials, stored as secrets.

Solutions

  • Creating a basic GitHub Action workflow

    Setting up a GitHub Action workflow allows you to automate tasks like testing and deployment. By defining a workflow file, you can specify triggers and actions to execute when specific events occur.

    To create a basic workflow follow these steps:

    • Navigate to your GitHub repository and create a .github/workflows/ directory if it doesn’t exist.
    • Create a new YAML file (e.g., first-action.yml) inside this directory.
    • Define a basic workflow that runs on push events:
      name: First GitHub Action
      on: [push]
      jobs:
        build:
          runs-on: ubuntu-latest
          steps:
            - name: Checkout repository
              uses: actions/checkout@v4
            - name: Run a simple command
              run: echo "Hello, GitHub Actions!"
      
    • Commit and push this file to your repository.
    • Go to the Actions tab in your GitHub repository to see the workflow run. The real-time visualization graph displayed here provides a clear sequence of executed jobs, making it easier to track progress and identify potential issues. Click on individual jobs to expand the steps, where you’ll find detailed logs and error messages to help with troubleshooting and debugging efficiently.

      Visualization of a finished workflow run in the github interface

      Detail of steps completed in a workflow run in the github interface

  • Using pre-built actions from the GitHub Marketplace

    The GitHub Marketplace provides pre-built actions that can be easily integrated into workflows to automate tasks. To use an action from the Marketplace, follow these steps:

    • Search for a relevant action in the Marketplace and open its page.

    • Copy the code provided under the “Use latest version” section and add it to your workflow file.

    • For example, you could decide to use the pre-built Python setup action to ensure the correct Python version is available for running scripts, tests, or installations. Copy the following step into your workflow file:

      - name: Setup Python
        uses: actions/setup-python@v4
        with:
          python-version: '3.10'
      
  • Automating testing with GitHub Actions

    • Use actions to run tests automatically after each push.

    • Example: Running unit tests for a Python project using pytest:

        jobs:
          test:
            runs-on: ubuntu-latest
            steps:
              - name: Checkout repository
                uses: actions/checkout@v4
              - name: Setup Python
                uses: actions/setup-python@v4
                with:
                  python-version: '3.10'
              - name: Install dependencies
                run: |
                  python -m pip install --upgrade pip
                  pip install -r requirements.txt
              - name: Run tests
                run: pytest
      

Further guidance

References

The official GitHub Actions documentation was consulted for accuracy and best practices.

Related pages

Skip tool table

Tools and resources on this page

Tool or resource Description Related pages Registry
GitHub Actions GitHub's infrastructure for continuous integration, deployment and delivery Documenting software u... Testing software
Contributors

How to cite this page

Eva Martín del Pico, "Task automation using GitHub Actions". everse.software. http://everse.software/RSQKit/task_automation_github_actions .