Skip to content
You're viewing an older version of this GitHub Action. Do you want to see the latest version instead?
play

GitHub Action

Run a TypeScript function

v0.0.5

Run a TypeScript function

play

Run a TypeScript function

Helper workflow wrapping actions/github-script with TypeScript

Installation

Copy and paste the following snippet into your .yml file.

              

- name: Run a TypeScript function

uses: urcomputeringpal/[email protected]

Learn more about this action in urcomputeringpal/github-script-ts

Choose a version

github-script-ts

A workflow wrapping https://github.com/actions/github-script with Typescript functionality.

Features

  • Enables easily running Typescript functions exported from a tiny private module like the one in .github/ in Actions workflows. Caches build results automatically.
  • Enables a local testing workflow for advanced Actions logic.
  • Provides a superior experience to editing Javascript embedded in YAML.

Usage

Writing scripts

The @urcomputeringpal/github-script-ts package contains a type definition for the arguments passed to your script. Put all of these files in .github to create scripts of your own:

src/function1.ts

import { GitHubScriptArguments } from "@urcomputeringpal/github-script-ts";

export async function function1(args: GitHubScriptArguments): Promise<String> {
    // const { github, context, core } = args;
    // const { glob, io, exec, fetch } = args;
    // ...
    return 'string';
}

src/index.ts

export { function1 } from "./function1";

package.json

{
    "name": "ts-scripts",
    "version": "0.0.1",
    "private": true,
    "scripts": {
        "build": "tsc",
    },
    "dependencies": {
        "@urcomputeringpal/github-script-ts": "0.0.1"
    }
}

tsconfig.json

{
    "compilerOptions": {
        "module": "commonjs",
        "declaration": true,
        "target": "es5",
        "strict": true
    },
    "include": ["src/*.ts"],
    "exclude": ["node_modules", "**/*.test.ts"]
}

Running your script in a workflow

See action.yml for all accepted inputs.

- name: Checkout repository
  uses: actions/checkout@v3

  # Perform setup. Caches build results with actions/cache.
- name: Setup TypeScript scripts
  uses: urcomputeringpal/github-script-ts@v0

  # Run function1. If it returns a value it can be used in subsequent steps
  # by accessing the `result` output of the step like so
  # ${{ steps.function1.outputs.result }}
- name: Run function1
  id: function1
  uses: urcomputeringpal/github-script-ts@v0
  with:
      github-token: ${{ secrets.GITHUB_TOKEN }}
      function: function1
      # args: >
      #   {github, context, core, exec, io, fetch}
      # path: ./.github
      # build: npm run build
      # module: src/index.js
      # result-encoding: string
      

- name: Use function1 result
  run: |
      echo "function1 result: ${{ steps.function1.outputs.result }}"