Since it is not feasible for @github-actions-workflow-ts/actions to include all actions, it is likely that consumers of this project will benefit from the ability to generate their own actions, similary to how this is currently done in packages/actions/scripts/generate.ts.
This would be useful in two scenarios:
- While waiting for a package to be added to
@github-actions-workflow-ts/actions (or waiting for a new version to be published)
- When your project depends on an action does not meet the inclusion criteria for
@github-actions-workflow-ts/actions or cannot be included for other reasons (e.g. private actions for internal use)
Proposed API
To facilitate this, it would be beneficial to expose an API similar to the following:
Programmatic Usage
import fs from "node:fs"
import {
generateAction,
resolveVersionTag,
fetchActionYml,
} from "@github-actions-workflow-ts/actions-codegen"
const baseAction = generateBaseAction(
const owner = 'actions'
const repo = 'checkout'
const version = 'v6'
// Users may want to generate code for a specific version (e.g. a commit SHA), so allowing them to customize ref resolution is preferable.
const ref = await resolveVersionTag('v6')
// In the case of e.g. local / private actions, it maybe desirable to customize action YML resolution.
const yml = await fetchActionYml(owner, repo, ref, {
githubPat: '...' // Defaults to `process.env.GH_PAT`, can be set to `null`
})
const action = generateAction({
// Used for default `uses` string (`${owner}/${repo}@${version}`)
owner,
repo,
version,
// Used for validation (if semver) and auto-complete hints
ref,
// Used for generating types
yml,
// Used internally to override default base class import. Default:
baseImportSpecifier: "@github-actions-workflow-ts/actions",
})
fs.writeFileSync("path/to/action.ts", action.src)
Command-Line Usage
# Use default behavior for resolving action ref and fetching yml (programmatic usage required to customise)
npx @github-actions-workflow-ts/actions-codegen generate action \
--owner actions \
--repo checkout \
--version v6 \
--base-import-specifier @github-actions-workflow-ts/actions
Status
Some of the implementation depends on the decisions made in #61, so for now I'm just raising this issue to gather thoughts and see if the feature is desirable.
If this suggestion is accepted, and once #61 is merged, I'll be happy to raise a PR with the implementation =)
Since it is not feasible for
@github-actions-workflow-ts/actionsto include all actions, it is likely that consumers of this project will benefit from the ability to generate their own actions, similary to how this is currently done inpackages/actions/scripts/generate.ts.This would be useful in two scenarios:
@github-actions-workflow-ts/actions(or waiting for a new version to be published)@github-actions-workflow-ts/actionsor cannot be included for other reasons (e.g. private actions for internal use)Proposed API
To facilitate this, it would be beneficial to expose an API similar to the following:
Programmatic Usage
Command-Line Usage
# Use default behavior for resolving action ref and fetching yml (programmatic usage required to customise) npx @github-actions-workflow-ts/actions-codegen generate action \ --owner actions \ --repo checkout \ --version v6 \ --base-import-specifier @github-actions-workflow-ts/actionsStatus
Some of the implementation depends on the decisions made in #61, so for now I'm just raising this issue to gather thoughts and see if the feature is desirable.
If this suggestion is accepted, and once #61 is merged, I'll be happy to raise a PR with the implementation =)