hero-action
An All-In-One action to test a GitHub Action.
Tested in unfor19/hero-action-test
Usage
- Generate a new Personal Access Token with the scope: repo + workflow. Keep this token in a safe place we'll use it later on.
- Add the following workflow
.github/workflows/testing.ymlto your action's repository, e.g.hero-actionname: 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
- Create a new GitHub repository to test your action, e.g.
hero-action-test, add the following file.github/workflows/test-action.yml.name: test-action on: workflow_dispatch: inputs: src_repository: description: Source Repository - {owner}/{repo_name} required: true src_workflow_name: description: Source Workflow Name required: true src_sha: description: Source Repository SHA - GITHUB_SHA required: true jobs: test: runs-on: ubuntu-20.04 name: Add steps to test your action steps: - uses: actions/checkout@v2 ############################## START MODIFY THIS PART # - name: Your Action # continue-on-error: true # Allow failure, on failure, a status update will be sent to source repo # uses: repo_owner/repo_name@repo_branch # with: # input1: some_input # input2: another_input ############################## END MODIFY THIS PART outputs: target_job_status: ${{ job.status }} update-status-check: name: Update Status Check In Source Repository runs-on: ubuntu-20.04 needs: - test # Change if necessary if: ${{ always() }} steps: - name: Status Update Action Repo uses: unfor19/hero-action@v1.0.2 with: action: "status-update" gh_token: ${{ secrets.GH_TOKEN }} # scope: repo + workflow src_repository: ${{ github.event.inputs.src_repository }} src_workflow_name: ${{ github.event.inputs.src_workflow_name }} src_sha: ${{ github.event.inputs.src_sha }} target_repository: ${{ github.repository }} target_job_status: ${{ needs.test.outputs.target_job_status }} target_run_id: ${{ github.run_id }}
- Add the secret
GH_TOKENto both repositories,hero-actionandhero-action-test - Commit and push code to your action's repository, or dispatch a workflow manually.
How It Works
- The action repository,
hero-action, triggers a workflow in the test repository,hero-action-test. Meanwhile, thehero-actionis "stuck" with the commit status pending. - The repository
hero-action-testtests the action by using it, I'm testinghero-actionby using it inhero-action-test, see unfor19/hero-action-test - Upon success/failure, the test action
hero-action-testcreates a commit status in the action's repository, this updates the status of the pending workflow with success or failure
Help Menu
./entrypoint.sh --helpUsage: bash entrypoint.sh --help
--hero_action | -ha [ENV_VAR] Which action to execute: dispatch, dispatch-status, status-create, status-update
--hero_gh_token | -hgt [null] GitHub Token to be used for calling GitHub APIs
--hero_src_repository | -srepo [null] Source Repository {owner}/{repository}
--hero_src_workflow_name | -sworkflow [testing] Source Workflow Name
--hero_src_sha | -ssha [null] Source Repository Commit SHA
--hero_target_repository | -trepo [null] Target Repository {owner}/{repository}
--hero_target_workflow_name | -tworkflow [test-action.yml] Target Repository Workflow Name
--hero_target_ref | -tref [master] Target Repository Branch Name
--hero_target_job_status | -tjobstatus [null] Target Job Status
--hero_target_run_id | -trunid [null] Target Run ID
NOTE: the code block above ☝️ was automatically generated with replacer! See the raw version of this README.md file
Projects Using This Action
Contributing
Report issues/questions/feature requests on the Issues section.
Pull requests are welcome! These are the steps:
- Fork this repo
- Create your feature branch from master
git checkout -b my-new-feature
- Build development image
docker build -t "hero-action:dev" --target "dev" .
- Create
.envfilecp "env" ".env"
- Run development image
docker run --rm -it -v "$PWD":"/code" --env-file ".env" --workdir "/code" "hero-action:dev"
- Add the code of your new feature
- Run tests on your code, feel free to add more tests
# in container ./tests/test.sh ... # All good? Move on to the next step
- Commit your remarkable changes
git commit -am 'Added new feature' - Push to the branch
git push --set-up-stream origin my-new-feature
- Create a new Pull Request and provide details about your changes
Authors
Created and maintained by Meir Gabay
License
This project is licensed under the MIT License - see the LICENSE file for details

