Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

Test GitHub projects with GitHub Actions and Testing Farm

March 9, 2022
Petr Hracek Zuzana Miklankova
Related topics:
AutomationDevOpsGitOpsLinux
Related products:
Red Hat Enterprise Linux

    Every project on GitHub that's destined for Red Hat Enterprise Linux (RHEL), Fedora, or CentOS should be tested before its changes are synced into a Git distribution repository (dist-git). It's important to catch problems before delivering software to customers, and help quality assurance teams catch errors.

    Testing Farm is an open source testing system offered as a service. Testing Farm’s idea is similar to Compile Farms, but with a focus on executing automated tests. Its mission is to provide a reliable and scalable service for executing automated tests from various users, such as Fedora CI, RHEL CI, Packit, and others. The entry point for our users is an HTTP-based API. Testing Farm scales across various infrastructures, including private and public clouds.

    The Red Hat Software Collections team has developed a way that you can use our Testing Farm in upstream GitHub repositories. Keep reading to learn how to use Testing Farm to improve your project with internal tests and catch errors before products are delivered to customers.

    Note: This article assumes you are familiar with using GitHub Actions.

    Get started with Testing Farm and GitHub Actions

    Testing Farm has an HTTP-based API that you use to manage testing jobs. Connecting to the Testing Farm API requires two (on demand) artifacts:

    • A Testing Farm API key, either for public or private clouds or both
    • A URL for Testing Farm requests

    To get the API key and request URL, see the Testing Farm onboarding document. Once you've acquired these artifacts, save them to your GitHub repository's secrets so they can be used correctly within GitHub Actions.

    The minimal steps for configuring a GitHub Action for running tests in Testing Farm are as follows:

    1. Write a Test Management Tool/Flexible Metadata Format (TMT/FMF) testing plan for working with Testing Farm
    2. Write a GitHub Action that:
      • Specifies when to run
      • Creates user request for Testing Farm
      • Gets the test results

    Writing TMT/FMF plans

    Testing Farm requires TMT/FMF plans for executing its tests. You will need to provide information about the provisioned machine and prepare that machine before running the tests.

    The TMT plan will be uploaded to the Testing Farm machine during the process of the GitHub Action and then be executed directly from it. The plan will prepare a proper test environment and call the specific command for starting the tests. Here's an example of a TMT plan:

    
    summary: TMT/TFT plan for running tests on CentOS 7
    description: |
        Run tests on CentOS-7
    discover:
        how: shell
        tests:
        - name: Run tests on CentOS-7
            framework: shell
            test: cd /tmp/$REPO_NAME && <call test suite>
            duration: 3h
    prepare:
        how: shell
        script: |
              # TODO install packages needed for tests
              git clone $REPO_URL /tmp/$REPO_NAME
              cd /tmp/$REPO_NAME
              git fetch origin +refs/pull/*:refs/remotes/origin/pr/*
              git checkout origin/pr/$PR_NUMBER/head
              git submodule update --init
    execute:
        how: tmt
        

    Environment variables used in the TMT plan will be explicitly delivered to the Testing Farm later in the GitHub Action.

    You can find more details on how to write TMT plans in the official documentation. The Software Collections team's source file repository contains illustrative examples of TMT/FMF testing plans for CentOS 7, Fedora, and CentOS Stream 9.

    Write the GitHub Action

    As noted, the TMT plan executes tests in the Testing Farm environment. However, you still need a way to let Testing Farm know specifically when a test should be run. For this, you need to send an HTTP POST request to Testing Farm’s API; the request can be supplied directly from within the GitHub Action.

    A GitHub Action used in this way maintains continuity of its execution with the user’s activity in the GitHub repository—a pull request, commit, or branch merging, for instance.

    Run tests on explicit user request

    This approach triggers tests at Testing Farm by commenting with specific text on a pull request. In this example, the text is the string [test]. Only upstream project owners or members are authorized to trigger the tests:

    
    name: upstream tests at Testing Farm
    on:
        issue_comment:
          types:
            -created
    
    jobs:
        build:
          name: A job run on explicit user request
          run-ons: ubuntu-20.04
          if: |
            github.event.issue.pull_request
            && contains(github.event.comment.body, '[test]')
            && contains(fromJson('["OWNER", "MEMBER"]'),
            github.event.comment.author_association)
            

    Triggering a test

    Testing Farm expects POST HTTP JSON requests as input. To handle this in a GitHub Action, install the curl utility on the machine where the action will execute, along with the jq utility for parsing JSON responses:

    
    - name: Schedule a test on Testing Farm
      id: sched_test
      run: |
          # Update ubuntu-20.04 in order to install curl and jq
          sudo apt update && sudo apt -y install curl jq
    
    

    The JSON code in the request specifies the environment variables that you want to set in the Testing Farm environment. You also need to provide the API_KEY and path to the TMT plan, as shown in the following listing. The request is then sent to a Testing Farm requests URL:

    
    - name: Schedule a test on Testing Farm
      id: sched_test
      run: |
        cat << EOF > request.json
        {
        "api_key": "${{ secrets.API_KEY }}",
        "test": {"fmf": {
          "url": "<URL_TO_TMT_FMF_plan>",
          "ref": "master",
          "name": "centos7"
        }},
        "environments": [{
          "arch": "x86_64",
          "os": {"compose": "CentOS-7"},
          "variables": {
              "REPO_URL": "$GITHUB_SERVER_URL/$GITHUB_REPOSITORY",
              "REPO_NAME": "$GITHUB_REPOSITORY",
              "PR_NUMBER": "${{ github.event.comment.issue_url }}",
              "TEST_NAME": "test"
          }
        }]
        }
        EOF
        curl ${{ secrets.TF_ENDPOINT }}/requests --data @request.json --header "Content-Type: application/json" --output response.json
        

    The job ID will be embedded in the HTTP response from Testing Farm, which you can parse from the JSON and later use to query the results:

    
    # Store REQ_ID into outputs for later on usage
    req_id=$(jq -r .id response.json)
    echo "REQ_ID=$req_id" >> $GITHUB_ENV
    
    

    Get the test results

    You can periodically request the state of your current test job from Testing Farm. The status request is an HTTP GET pointing to the Testing Farm URL endpoint—specifically, to REQ_ID, which you stored in the previous step:

    
    curl ${{ secrets.TF_ENDPOINT }}/requests/${{ env.REQ_ID }}
    

    When the job is completed, this information is stored in the value of the state key. The final test result can be parsed from the result key value.

    Test logs can be gathered within the job ID directory at testing-farm.io. Test results can be displayed as a status directly within a pull request with the GitHub status API.

    Run the test suite on Testing Farm

    At this point, you know how to set up everything you need to execute a test on Testing Farm infrastructure directly from a GitHub repository.

    A full Testing Farm/GitHub Actions scheme example like the one described in this article can be found in the GitHub repository for the Software Collections team. This GitHub Action runs tests on Fedora, CentOS 7, CentOS Stream 9, RHEL 7, and RHEL 8. The action requires that the tested repository has access to the Testing Farm API and request URL, stored as GitHub secrets. The GITHUB_TOKEN secret is necessary to connect to the GitHub API.

    Testing Farm machines are situated within the Red Hat infrastructure, in case you are using Testing Farm private clouds. Therefore, all tests running on those machines must be checked for vulnerabilities and potentially dangerous behavior. Consequently, you should be sure to check the code in pull requests carefully from the role of owner or member.

    Once you review the pull request, assuming you don't catch any problems or find any incorrect code, you can write a comment into the pull request containing the string [test]. Submitting this string triggers the tests.

    Important note: This article has described how to set up the GitHub Action so that only the owner or a member of the GitHub organization can trigger the tests, a constraint we introduced for security reasons.

    Conclusion

    The combination of GitHub Actions and the Testing Farm environment provides a robust and easy-to-configure testing platform. By using GitHub Actions, you can automate responses to activity in a GitHub repository and straightforwardly display test results directly in the same repository.

    Testing Farm has an infrastructure of machines available on request, incorporating RHEL, CentOS, and Fedora distributions with wide configuration options adjustable for any use case. Bringing those features together offers developers and testers a great opportunity to detect defects before they enter the product codebase.

    Last updated: March 18, 2024

    Related Posts

    • Deploy self-hosted GitHub Actions runners for Red Hat OpenShift

    • Automate dependency analytics with GitHub Actions

    • Managing GitOps control planes for secure GitOps practices

    • A developer's guide to CI/CD and GitOps with Jenkins Pipelines

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI