Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/hello-yaml-command.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Hello yaml Command
on:
repository_dispatch:
types: [hello-yaml-local-command]
jobs:
helloYaml:
runs-on: ubuntu-latest
steps:
- name: Add reaction
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ github.event.client_payload.github.payload.comment.id }}
reactions: hooray

- name: Create URL to the run output
id: vars
run: echo "run-url=https://github.com/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT

- name: Create comment
uses: peter-evans/create-or-update-comment@v4
with:
issue-number: ${{ github.event.client_payload.github.payload.issue.number }}
body: |
Hello @${{ github.event.client_payload.github.actor }}!

This command was in a workflow file with the `.yaml` extension.

[Click here to see the command run output][1]

[1]: ${{ steps.vars.outputs.run-url }}
1 change: 1 addition & 0 deletions .github/workflows/slash-command-dispatch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
with:
token: ${{ secrets.REPO_ACCESS_TOKEN }}
commands: |
hello-yaml-local
hello-world-local
ping-local
permission: none
Expand Down
20 changes: 17 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ class GitHubHelper {
}
createWorkflowDispatch(cmd, clientPayload) {
return __awaiter(this, void 0, void 0, function* () {
const workflow = `${cmd.command}${cmd.event_type_suffix}.yml`;
const workflowName = `${cmd.command}${cmd.event_type_suffix}`;
const workflow = yield this.getWorkflow(cmd.repository, workflowName);
const slashCommand = clientPayload.slash_command;
const ref = slashCommand.args.named.ref
? slashCommand.args.named.ref
Expand All @@ -366,8 +367,21 @@ class GitHubHelper {
if (count == 10)
break;
}
yield this.octokit.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches', Object.assign(Object.assign({}, this.parseRepository(cmd.repository)), { workflow_id: workflow, ref: ref, inputs: inputs }));
core.info(`Command '${cmd.command}' dispatched to workflow '${workflow}' in '${cmd.repository}'`);
yield this.octokit.request('POST /repos/{owner}/{repo}/actions/workflows/{workflow}/dispatches', Object.assign(Object.assign({}, this.parseRepository(cmd.repository)), { workflow: workflow, ref: ref, inputs: inputs }));
core.info(`Command '${cmd.command}' dispatched to workflow '${workflowName}' in '${cmd.repository}'`);
});
}
getWorkflow(repository, workflowName) {
return __awaiter(this, void 0, void 0, function* () {
core.debug(`Getting workflow ${workflowName} for repository ${repository}`);
const { data: workflows } = yield this.octokit.rest.actions.listRepoWorkflows(Object.assign({}, this.parseRepository(repository)));
for (const workflow of workflows.workflows) {
if (workflow.path === `${workflowName}.yml` || workflow.path === `${workflowName}.yaml`) {
core.info(`Selecting workflow file ${workflow.path}`);
return workflow.path;
}
}
throw new Error(`Workflow ${workflowName} not found`);
});
}
getDefaultBranch(repository) {
Expand Down
2 changes: 1 addition & 1 deletion docs/workflow-dispatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ There are significant differences in the action's behaviour when using `workflow

It is important to name the `workflow_dispatch` event workflow correctly since the action targets the workflow based on its filename.
The target filename is a combination of the command name and the `event-type-suffix`.
Additionally, the file extension must be `.yml`.
The file extensions `.yml` and `.yaml` are supported.

For the following example configuration, the target workflows are:
- `deploy-command.yml`
Expand Down
25 changes: 24 additions & 1 deletion src/github-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ export class GitHubHelper {
cmd: Command,
clientPayload: ClientPayload
): Promise<void> {
const workflow = `${cmd.command}${cmd.event_type_suffix}.yml`
const workflowName = `${cmd.command}${cmd.event_type_suffix}`
const workflow = await this.getWorkflow(cmd.repository, workflowName)
const slashCommand: SlashCommandPayload = clientPayload.slash_command
const ref = slashCommand.args.named.ref
? slashCommand.args.named.ref
Expand Down Expand Up @@ -181,6 +182,28 @@ export class GitHubHelper {
)
}

private async getWorkflow(
repository: string,
workflowName: string
): Promise<string> {
core.debug(`Getting workflow ${workflowName} for repository ${repository}`)
const {data: workflows} = await this.octokit.rest.actions.listRepoWorkflows(
{
...this.parseRepository(repository)
}
)
for (const workflow of workflows.workflows) {
if (
workflow.path === `${workflowName}.yml` ||
workflow.path === `${workflowName}.yaml`
) {
core.debug(`Selecting workflow file ${workflow.path}`)
return workflow.path
}
}
throw new Error(`Workflow ${workflowName} not found`)
}

private async getDefaultBranch(repository: string): Promise<string> {
const {data: repo} = await this.octokit.rest.repos.get({
...this.parseRepository(repository)
Expand Down