Declaratively define GitHub actions

tl;dr: Define a GitHub Action using the workflow syntax, allowing reuse of other actions across repositories without creating own JS based wrapper actions.

Presently, there are two ways to define GitHub actions - either using JavaScript or Docker. If we want to reuse some action, we need to clone/install it and then make our own wrapper around it. It becomes more difficult when the action doesn’t provide a programmatic API. The workflow syntax already allows (re)use of various actions, but then one needs to copy same workflow across multiple projects. It would be great if we can define new GitHub actions by using the workflow syntax.

In JavaScript, we may write an action as:

// Skipping some syntax for brevity.
// ASSUMING all actions provide a programmatic API.
// All action libraries are in node_modules, checked-in to the git repository (or packaged using some other tool).
import core from "@actions/core";
import checkout from "@actions/checkout";
import exec from "some-exec-lib";
import deployToGhPages from "some-deploy-lib";
import postComment from "some-comment-lib";

async function main() {
  await checkout();
  await exec(`npm run build -- --profile ${core.getInput("some-input")}`);
  const outputs = await deployToGhPages({ token: core.getInput("github_token") });
  await postComment({ files: outputs.changed_files });
  // above gets out of hands quick.
}

main().catch((error) => {
  console.error(error);
  process.exit(1);
}

vs an action.yml in my-user/declarative-action may look like:

name: 'Build, deploy and add comment'
inputs:
  SOME_INPUT:
    description: 'input description'
    required: true
steps:
  - uses: actions/checkout@v2
  - run: npm run build
    with:
      profile: ${{ inputs.SOME_INPUT }}
  - id: deploy
    uses: peaceiris/actions-gh-pages@v3
    with:
      github_token: ${{ secrets.GITHUB_TOKEN }}
  - name: comment
    uses: ...
    with:
      files: ${{ outputs.deploy.changed_files }}

Now copying (and updating) above in a workflow across repositories will be cumbersome. So, users can use above action in a workflow as:

jobs:
  some_job:
    runs-on: ubuntu-latest
    steps:
      - uses: user/my-declarative-action@v1
        with:
          SOME_INPUT: my_input_value    
2 Likes

@sidvishnoi,

Thanks for your feedback.
Currently, we can’t reuse an action in another action like as the method you mentioned.

GitHub takes your suggestions very seriously, and the suggestions are very helpful for improving GitHub Actions.
I recommend that you can directly share your suggestion here. That will allow you to directly interact with the appropriate engineering team, and make it more convenient for the engineering team to collect and categorize your suggestions.

1 Like

Thanks. Shared through the feedback channel you provided.
Keeping this open here so community members can vote and show interest.

@sidvishnoi,

Sure. Thanks for your suggestions.

Hey @sidvishnoi,

If I’m understanding your comments correctly, you are wanting a way to write an action using the yaml syntax. If so, I’m happy to report its on our radar, though I’m unable to give a timeframe for when it will be available.

We have an ADR open to build this on the actions runner here. To begin, it will only support run steps, we will later expand it to include uses steps as well.

We are more than happy to take feedback and questions on the ADR if you have additional feedback!

1 Like

you are wanting a way to write an action using the yaml syntax

Yes!

We have an ADR open to build this on the actions runner

This is exciting :tada: Thank you!

If I’m understanding your comments correctly, you are wanting a way to write an action using the yaml syntax.

This seems possible today using an action like actions/github-script which allows you to inline javascript . You can find an example here https://github.com/actions/github-script#comment-on-an-issue