DEV Community

Meir Gabay
Meir Gabay

Posted on

How To Test A GitHub Action

My Workflow

The project unfor19/hero-action is an All-In-One action to a test GitHub Action.

Submission Categories

  1. Maintainer Must-Haves
  2. Wacky Wildcards - I'm adding this one because it's a "hacky" way of using GitHub Actions to test an action (feels like a recursion)

Yaml File or Link to Code

GitHub logo unfor19 / hero-action

All-in-one action to develop and maintain GitHub Actions.

hero-action

testing test-action

An All-In-One action to test a GitHub Action.

Tested in unfor19/hero-action-test

Usage

  1. Generate a new Personal Access Token with the scope: repo + workflow. Keep this token in a safe place we'll use it later on.
  2. Add the following workflow .github/workflows/testing.yml to your action's repository, e.g. hero-action
    name: testing
    on:
      push:
        branches: [master]
        paths-ignore:
          - "README.md"
      workflow_dispatch:
    
    jobs:
      dispatch_test_action:
        name: Dispatch Test Action
        runs-on: ubuntu-20.04
        steps:
          - uses: actions/checkout@v2
          - name: Workflow Dispatch Status
            uses: unfor19/hero-action@v1.0.2
            with:
              action: "dispatch-status"
              src_repository: ${{ github.repository }}
              src_workflow_name: ${{ github.workflow }}
              src_sha: ${{ github.sha }}
              target_repository: ${{ github.repository }}-test
              target_workflow_name: "test-action.yml"
              gh_token: ${{ secrets.GH_TOKEN }} # scope: repo + workflow
    Enter fullscreen mode Exit fullscreen mode
  3. Create a new GitHub repository to test your action, e.g. hero-action-test, add…
  1. The action repository, my-repo, triggers a workflow in the test repository, my-repo-test. Meanwhile, the my-repo is "stuck" with the commit status pending. hero-action-commit-status-pending
  2. The repository my-repo-test tests the action by using it, see unfor19/hero-action-test
  3. Upon success/failure, the test action my-repo-test creates a commit status in the action's repository, this updates the status of the pending workflow with success or failure hero-action-commit-status-success

Additional Resources / Info

Latest comments (2)

Collapse
 
wanbeige1 profile image
WanBeige1

Great article. I'm a beginner and like this developer very much. Where can I learn the most basic development courses?

Collapse
 
unfor19 profile image
Meir Gabay

Thank you!
What's purpose? The "development course" should be picked according to your goals/needs