Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(run-name): update class methods for WorkflowHandler #15

Closed
wants to merge 9 commits into from
25 changes: 25 additions & 0 deletions .github/workflows/build-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Build & Test
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -64,6 +66,27 @@ jobs:
token: ${{ secrets.PERSONAL_TOKEN }}
wait-for-completion: false

echo-3-test:
needs: [build]
runs-on: ubuntu-latest
name: "echo-3-test [trigger|by workflow filename|wait for completion by run-name]"
steps:
- name: Check out repository
uses: actions/checkout@v3
- name: Download dist
uses: actions/download-artifact@v3
with:
name: build
path: dist
- name: Invoke echo 3 workflow using this action (wait for completion by run-name)
uses: ./
with:
workflow: echo-3.yaml
token: ${{ secrets.PERSONAL_TOKEN }}
inputs: '{"message": "blah-blah"}'
wait-for-completion: true
run-name: echo-3-blah-blah

# - name: Invoke echo 1 workflow by id
# uses: ./
# with:
Expand Down Expand Up @@ -204,9 +227,11 @@ jobs:
# ref: master

deploy:
if: ${{ github.event_name != 'pull_request' }}
needs:
- echo-1-test
- echo-2-test
- echo-3-test
- long-running-test
- failing-test
- timeout-test
Expand Down
20 changes: 20 additions & 0 deletions .github/workflows/echo-3.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Message Echo 3
run-name: echo-3-${{ github.event.inputs.message }}

on:
workflow_dispatch:
inputs:
message:
description: "Message to echo"
required: true
# No default

jobs:
echo:
runs-on: ubuntu-latest
environment:
name: foo
url: www.google.com
steps:
- name: Echo message
run: echo '${{ github.event.inputs.message }}'
14 changes: 8 additions & 6 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10135,17 +10135,19 @@ class WorkflowHandler {
}
findWorklowRunIdFromRunName(runName) {
return __awaiter(this, void 0, void 0, function* () {
const result = yield this.octokit.rest.checks.listForRef({
check_name: runName,
const workflowId = yield this.getWorkflowId();
const result = yield this.octokit.rest.actions.listWorkflowRuns({
owner: this.owner,
repo: this.repo,
ref: this.ref,
filter: 'latest'
workflow_id: workflowId,
event: 'workflow_dispatch',
created: `>=${new Date(this.triggerDate).toISOString()}`
});
if (result.length == 0) {
const runs = result.data.workflow_runs.filter((r) => r.name === runName);
if (!runs.length) {
throw new Error('Run not found');
}
return result.check_runs[0].id;
return runs[0].id;
});
}
getWorkflowId() {
Expand Down
17 changes: 9 additions & 8 deletions src/workflow-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ export class WorkflowHandler {
}
}


async getWorkflowRunArtifacts(): Promise<WorkflowRunResult> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not remove code that you should not change with this PR.
You PR is to fix issue with runName, not cleaning code. Maybe this code is not used yet but could be later

try {
const runId = await this.getWorkflowRunId();
Expand All @@ -121,7 +120,6 @@ export class WorkflowHandler {
}
}


async getWorkflowRunId(): Promise<number> {
if (this.workflowRunId) {
return this.workflowRunId;
Expand Down Expand Up @@ -172,19 +170,22 @@ export class WorkflowHandler {
}

private async findWorklowRunIdFromRunName(runName: string): Promise<number> {
const result = await this.octokit.rest.checks.listForRef({
check_name: runName,
const workflowId = await this.getWorkflowId();

const result = await this.octokit.rest.actions.listWorkflowRuns({
owner: this.owner,
repo: this.repo,
ref: this.ref,
filter: 'latest'
workflow_id: workflowId,
event: 'workflow_dispatch',
created: `>=${new Date(this.triggerDate).toISOString()}`
});

if (result.length == 0) {
const runs = result.data.workflow_runs.filter((r: any) => r.name === runName);
if (!runs.length) {
throw new Error('Run not found');
}

return result.check_runs[0].id as number;
return runs[0].id as number;
}

private async getWorkflowId(): Promise<number | string> {
Expand Down