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 issue where truncated job names would cause the job to fail. #45

Merged
merged 34 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6a46570
Working branch (#1)
c3charvat Oct 8, 2024
6ad33c5
Working branch (#2)
c3charvat Oct 8, 2024
e9228cb
add_extra_test
c3charvat Oct 8, 2024
2f63e34
Merge branches 'main' and 'main' of https://github.com/c3charvat/acti…
c3charvat Oct 8, 2024
dd6d641
what_happened
c3charvat Oct 8, 2024
85b0e25
Revert "what_happened"
c3charvat Oct 8, 2024
be42c9a
Revert "Merge branches 'main' and 'main' of https://github.com/c3char…
c3charvat Oct 8, 2024
a294d63
Working branch (#3)
c3charvat Oct 8, 2024
06c002d
comment_out_tests
c3charvat Oct 8, 2024
c85ec93
add_test_back_in
c3charvat Oct 8, 2024
bac7c89
add_back_in_testing
c3charvat Oct 8, 2024
23c1ec3
rate_limit???
c3charvat Oct 8, 2024
26d428c
isolate_matrix
c3charvat Oct 8, 2024
49e2790
fix_job_name
c3charvat Oct 8, 2024
8ae7994
update_id
c3charvat Oct 8, 2024
3833524
try_moving_back
c3charvat Oct 8, 2024
6e770c8
yep_these_cant_exist_together
c3charvat Oct 8, 2024
a4504b4
Merge branch 'main' of https://github.com/c3charvat/actions--context
c3charvat Oct 11, 2024
b08f41a
temp_log_action
c3charvat Oct 11, 2024
4350ace
more_logging
c3charvat Oct 11, 2024
8d19ec5
more_logs
c3charvat Oct 11, 2024
5bc9f47
add_logs
c3charvat Oct 11, 2024
49d9d36
add_extra_check
c3charvat Oct 11, 2024
e5b6619
switch_to_filter
c3charvat Oct 11, 2024
eeec66a
fix_error_message
c3charvat Oct 11, 2024
7f81bcc
fix_97_char_exact_issue
c3charvat Oct 14, 2024
9f0942a
Merge branch 'qoomon:main' into main
c3charvat Oct 21, 2024
261b20f
add_extra_test
c3charvat Oct 21, 2024
2e70973
resolve_comments
c3charvat Oct 21, 2024
3c368f3
add_more_testing
c3charvat Oct 21, 2024
680d7b8
fix_missing_comma
c3charvat Oct 21, 2024
53b3046
update_job_length
c3charvat Oct 21, 2024
c3336f4
remove_duplicate_Testing
c3charvat Oct 21, 2024
f3992eb
fix_comments
c3charvat Oct 21, 2024
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
29 changes: 29 additions & 0 deletions .github/workflows/example-reusable-from-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Example Reusable Workflow Called From a Matrix
on:
workflow_call:
inputs:
id:
required: true
type: string
input_1:
required: true
type: string
input_2:
required: false
default: ''
type: string
workflow-context:
required: true
type: string

jobs:
build:
runs-on: ubuntu-latest
steps:
- run: env | grep GITHUB_

- uses: actions/checkout@v4

- uses: ./
with:
workflow-context: ${{ inputs.workflow-context }}
42 changes: 42 additions & 0 deletions .github/workflows/matrix-example.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Example Matrix Action

on:
push:
branches: ['main']
workflow_dispatch:

jobs:
build-with-reusable-workflow-with-matrix-inputs:
strategy:
fail-fast: false
matrix:
inputs: [
{id: '1.1', input_1: 'In_this_input_we_are_testing_very_very_very_long_strings', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},
{id: '1.1', input_1: 'In_this_input_we_are_testing_very_very_very_long_strings', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},
{id: '1.1', input_1: 'In_this_input_we_are_testing_very_very_very_long_strings', input_2: 'In_this_input_we_are_testing_very_very_very_long_string'},
{id: '1.2', input_1: 'Example', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},
{id: '1.3', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},]
uses: ./.github/workflows/example-reusable-from-matrix.yml
with:
id: ${{matrix.inputs.id}} # Id to seperate the different runs
input_2: ${{matrix.inputs.input_2}}
input_1: ${{matrix.inputs.input_1}}
workflow-context: build-with-reusable-workflow-with-matrix-inputs, ${{ toJSON(matrix) }}

build-with-reusable-workflow-with-limit:
strategy:
max-parallel: 2
fail-fast: false
matrix:
inputs: [
{id: '2.1', input_1: 'In_this_input_we_are_testing_very_very_very_long_strings', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},
{id: '2.1', input_1: 'In_this_input_we_are_testing_very_very_very_long_strings', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},
{id: '2.1', input_1: 'In_this_input_we_are_testing_very_very_very_long_strings', input_2: 'In_this_input_we_are_testing_very_very_very_long_string'},
{id: '2.2', input_1: 'Example', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},
{id: '2.3', input_2: 'In_this_input_we_are_testing_very_very_very_long_strings'},]
uses: ./.github/workflows/example-reusable-from-matrix.yml
with:
id: ${{matrix.inputs.id}} # Id to seperate the different runs
input_2: ${{matrix.inputs.input_2}}
input_1: ${{matrix.inputs.input_1}}
workflow-context: build-with-reusable-workflow-with-limit, ${{ toJSON(matrix) }}
2 changes: 2 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ inputs:
# --- Workarounds for missing GitHub Actions context variables ---
job-name:
default: '${{ github.job }}'
runner-name:
default: '${{ runner.name }}'
'#job-matrix':
description: 'DO NOT SET MANUALLY'
default: '${{ toJSON(matrix) }}'
Expand Down
16 changes: 13 additions & 3 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44573,7 +44573,8 @@ function getAbsoluteJobName({ job, matrix, workflowContextChain }) {
actualJobName = `${actualJobName} (${flatValues.join(', ')})`;
}
}
if (actualJobName.length > 97) {
// If the job name is too long, github truncates it and adds an ellipsis
if (actualJobName.length > 97 && actualJobName.charAt(97) != ')') {
actualJobName = actualJobName.substring(0, 97) + '...';
}
workflowContextChain?.forEach((workflowContext) => {
Expand Down Expand Up @@ -44634,15 +44635,24 @@ async function getJobObject(octokit) {
}
throw error;
});
const currentJob = workflowRunJobs.find((job) => job.name === absoluteJobName);
const runnerName = getInput('runner-name', { required: true });
//In the case of truncated job name, the runner name was the only other way i could find to identify the job
// This still might produce a run that points to the wrong job, but it's the best I could do
const currentJob = workflowRunJobs.filter((job) => job.name === absoluteJobName && job.status === "in_progress" && job.runner_name === runnerName);
if (!currentJob) {
throw new Error(`Current job '${absoluteJobName}' could not be found in workflow run.\n` +
'If this action is used within a reusable workflow, ensure that ' +
'action input \'workflow-context\' is set to ${{ inputs.workflow-context }}' +
'and workflow input \'workflow-context\' was set to \'"CALLER_JOB_NAME", ${{ toJSON(matrix) }}\'' +
'or \'"CALLER_JOB_NAME", ${{ toJSON(matrix) }}, ${{ inputs.workflow-context }}\' in case of a nested workflow.');
}
const jobObject = { ...currentJob, };
else if (currentJob.length != 1) {
throw new Error(`Current job '${absoluteJobName}' returned multiple matches'.\n` +
'If this action is used within a reusable workflow, or matrix please ensure that the job name is unique.' +
'If the length of \'"CALLER_JOB_NAME" + ${{ toJSON(matrix) }}\' exceeds 97 characters' +
'Github Actions may have truncated it. Thus, potentially making it non unique. ');
}
const jobObject = { ...currentJob[0], };
return _jobObject = jobObject;
}
let _deploymentObject;
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 15 additions & 5 deletions lib/actions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as core from '@actions/core'
import {InputOptions} from '@actions/core'
import {z, ZodSchema} from 'zod'
import {array, z, ZodSchema} from 'zod'
c3charvat marked this conversation as resolved.
Show resolved Hide resolved
import {Context} from '@actions/github/lib/context';
import process from 'node:process';
import {_throw, getFlatValues, JsonObject, JsonObjectSchema, JsonParser, YamlParser} from './common.js';
Expand Down Expand Up @@ -212,7 +212,8 @@ function getAbsoluteJobName({job, matrix, workflowContextChain}: {
actualJobName = `${actualJobName} (${flatValues.join(', ')})`
}
}
if (actualJobName.length > 97) {
// If the job name is too long, github truncates it and adds an ellipsis
if (actualJobName.length > 97 && actualJobName.charAt(97) != ')') {
actualJobName = actualJobName.substring(0, 97) + '...'
}

Expand Down Expand Up @@ -286,17 +287,26 @@ export async function getJobObject(octokit: InstanceType<typeof GitHub>): Promis
throw error
})

const currentJob = workflowRunJobs.find((job) => job.name === absoluteJobName)

const runnerName = getInput('runner-name', {required: true})
//In the case of truncated job name, the runner name was the only other way i could find to identify the job
// This still might produce a run that points to the wrong job, but it's the best I could do
const currentJob = workflowRunJobs.filter((job) => job.name === absoluteJobName && job.status=== "in_progress" && job.runner_name === runnerName)
if (!currentJob) {
c3charvat marked this conversation as resolved.
Show resolved Hide resolved
throw new Error(`Current job '${absoluteJobName}' could not be found in workflow run.\n` +
'If this action is used within a reusable workflow, ensure that ' +
'action input \'workflow-context\' is set to ${{ inputs.workflow-context }}' +
'and workflow input \'workflow-context\' was set to \'"CALLER_JOB_NAME", ${{ toJSON(matrix) }}\'' +
'or \'"CALLER_JOB_NAME", ${{ toJSON(matrix) }}, ${{ inputs.workflow-context }}\' in case of a nested workflow.'
)
} else if (currentJob.length != 1) {
throw new Error(`Current job '${absoluteJobName}' returned multiple matches'.\n` +
'If this action is used within a reusable workflow, or matrix please ensure that the job name is unique.' +
'If the length of \'"CALLER_JOB_NAME" + ${{ toJSON(matrix) }}\' exceeds 97 characters' +
c3charvat marked this conversation as resolved.
Show resolved Hide resolved
'Github Actions may have truncated it. Thus, potentially making it non unique. '
)
}

const jobObject = {...currentJob,}
const jobObject = {...currentJob[0],}
return _jobObject = jobObject;
}

Expand Down