I would like my repo to have 2 functions:
Both require an action.
Both require an action.yml in the repo. How do I combine them?
You could leave each of your actions in their own separate GitHub Action repository.
And, since August 2020, combine them.
See:
GitHub Actions: Composite Run Steps
You can now create reusable actions using shell scripts and even mix multiple shell languages in the same action.
You probably have a lot of shell script to automate many tasks, now you can easily turn them into an action and reuse them for different workflows. Sometimes it's easier to just write a shell script than JavaScript or Docker.
Now you don't have to worry about wrapping it up your scripts in a Docker containers.Here's an example of how you can use composite run steps actions:
workflow.yml:
jobs: build: runs-on: windows-latest steps: - uses: actions/checkout@v2 - uses: octocat/say-hello@v1 with: name: OctoCat
octocat/say-hello/action.yml:
inputs: name: description: 'Your name' default: 'No name provided' runs: using: "composite" steps: - run: echo Hello ${{ inputs.name }}. shell: bash - run: echo "Nice to meet you!" shell: pwsh
Learn more about composite run steps and visit the GitHub Actions community forum for questions.
@chenghopan! If you want to have two actions inside the same repository, they should be located in separate directories.
However, the action.yml
file is not required.
This file is only required for an action if you plan to list it in the GitHub Marketplace.
If you have the actions in the same repo, they can have their own action.yml
file located along with their Dockerfile or node script. Here's an example with two dockerfiles:
.
├── README.md
├── .github
│ └── workflows
│ └── main.yml
├── action1
│ ├── Dockerfile
│ ├── action.yml
│ └── entrypoint.sh
└── action2
├── Dockerfile
├── action.yml
└── entrypoint.sh
And here's a workflow in the same repo calling both actions in the same repo:
name: Test two actions
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: ./action1
- uses: ./action2
And here's a workflow in a different repo calling the actions:
name: Test two actions
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: managedkaos/github-actions-two-actions/action1@master
- uses: managedkaos/github-actions-two-actions/action2@master
If you're OK with not listing the actions in the GitHub Marketplace, just put the action.yml
file in the same dir as the action and you'll be fine!
For reference, you can find the code in these examples here: