ShellD
ShellD

Reputation: 85

How to test a custom GitHub action without publishing it to marketplace?

I created a GitHub action, I am looking for a way to test itself before publishing it to marketplace. How can I test it by creating a workflow file within the same repository?

I have the following workflow.

name: "Build"
on:
  pull_request:
  push:
    branches:
      - master
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - uses: test-action # name of my action

Upvotes: 6

Views: 4423

Answers (3)

Cardinal
Cardinal

Reputation: 2195

There are different levels of testing: system, integration, unit.

I am also an author of many Actions and I've described my approach in the article. The main idea is:

  • You can use unit tests with familiar tools according the technology you use to test separate units of your action
  • To test the whole action use github-action-ts-run-api TS library to run tests both locally (to have short feedback loop without permanent pushes to the repo) and on CI (using your workflow).

The library emulates GitHub runner and has API to pass different inputs, env variables, analyse outputs, exit code, etc. of your action, supports executing JavaScript and Docker actions.

Upvotes: 1

GuiFalourd
GuiFalourd

Reputation: 23190

You can also call the action specific branch to use an action which hasn't been published yet (even in other repositories).

  steps:  
    - uses: <username>/<repo-name>@<branch-name>
      with:
       # input params if there is any

This can (for example) allow to test implementations located in different branches.

Upvotes: 10

Robin Raju
Robin Raju

Reputation: 1325

You can use the ./ syntax to use an action available in the same repository.

  steps:  
    - uses: ./
      with:
       # input params if you have any

Upvotes: 12

Related Questions