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

tests: add feature tagging workflow #15148

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

maykathm
Copy link
Contributor

@maykathm maykathm commented Feb 27, 2025

Dependent on feature tag logging in #15091

This adds the ability to generate feature tags for a spread run in two ways:

  • Using the workflow dispatch in the new Feature Tagging workflow
  • Pushing on master (will only tag spread tests that have been changed)
  • Using run-spread with SPREAD_TAG_FEATURES set

Both methods permit automatically rerunning spread and consolidating the ending results into system-by-system json files of features. In the workflow, the results are uploaded as an artifact, though this is a temporary measure since in the future the tags will instead be loaded into a DB elsewhere.

Both the run-spread additions and the workflow contain a rerunning mechanism to automatically rerun spread with the failed tests a maximum number of times. Once the workflow/run-spread script has finished all spread runs, including reruns, it will consolidate the feature tagging results into a single final json file for each system. It consolidates results by creating a final version with all tests run where more recent individual test results substitute the less recent.

@maykathm maykathm added the Skip spread Indicate that spread job should not run label Feb 27, 2025
Copy link

github-actions bot commented Feb 27, 2025

Fri Mar 21 11:00:02 UTC 2025

Spread tests skipped

@maykathm maykathm force-pushed the SNAPDENG-34441-add-feature-tagging-workflow branch 2 times, most recently from 3d46364 to 34ed733 Compare February 28, 2025 15:49
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.10%. Comparing base (a272aac) to head (49a5046).
Report is 206 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #15148      +/-   ##
==========================================
+ Coverage   78.07%   78.10%   +0.02%     
==========================================
  Files        1182     1191       +9     
  Lines      157743   159148    +1405     
==========================================
+ Hits       123154   124297    +1143     
- Misses      26943    27118     +175     
- Partials     7646     7733      +87     
Flag Coverage Δ
unittests 78.10% <ø> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@maykathm maykathm force-pushed the SNAPDENG-34441-add-feature-tagging-workflow branch from 34ed733 to 44ba42a Compare February 28, 2025 16:13
@maykathm maykathm marked this pull request as ready for review March 11, 2025 12:47
…sing '\' to using '--' to reflect changes in debug tagging PR
@maykathm maykathm force-pushed the SNAPDENG-34441-add-feature-tagging-workflow branch 5 times, most recently from c4ff4f0 to ba0efa9 Compare March 14, 2025 16:10
@maykathm maykathm force-pushed the SNAPDENG-34441-add-feature-tagging-workflow branch from ba0efa9 to 75369e9 Compare March 14, 2025 16:18
Copy link
Contributor

@zyga zyga left a comment

Choose a reason for hiding this comment

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

First pass. I'm kind of -1 on the python that looks more like perl in the sense that everything is a dict. Can we avoid that and actually use objects of some type (typedict is a hack but passable). If loading json is a problem we can sync to find a solution.

@@ -0,0 +1,18 @@
rules:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please start with a comment that links to an explanation of what this file is for and what reads it?

for system in systems:
composed = compose_system(dir=args.dir, system=system,
failed_tests=args.failed_tests, env_variables=args.env_variables)
system = "_".join(system.split(':'))
Copy link
Contributor

Choose a reason for hiding this comment

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

You can just replace:

Suggested change
system = "_".join(system.split(':'))
system = system.replace(":", "_")

failed_tests=args.failed_tests, env_variables=args.env_variables)
system = "_".join(system.split(':'))
with open(os.path.join(args.output, system + attempt + '.json'), 'w') as f:
f.write(json.dumps(composed))
Copy link
Contributor

Choose a reason for hiding this comment

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

Or you can avoid the intermediate:

Suggested change
f.write(json.dumps(composed))
json.dump(composed, f)



if __name__ == '__main__':
parser = argparse.ArgumentParser(description="""
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move the description variable above main to make this format with less indent?

def run_attempt_type(value):
if value is not int or int(value) <= 0:
raise argparse.ArgumentTypeError(
"%s is invalid. Run attempts are integers and start at 1" % value)
Copy link
Contributor

Choose a reason for hiding this comment

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

% is somewhat discouraged, perhaps, f-string or just plain .format?

'_1') and any(rerun for rerun in reruns_no_ext if rerun.startswith(file[:-2]))]
reruns_no_ext.sort(key=lambda x: int(x.split('_')[-1]))
for rerun in reruns_no_ext:
beginning = '_'.join(rerun.split('_')[:-1])
Copy link
Contributor

Choose a reason for hiding this comment

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

This wants to be a helper but I'm not sure how to call it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

'''
files = [f for f in os.listdir(
dir) if os.path.isfile(os.path.join(dir, f))]
systems = [":".join(file.split(':')[:2])
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be a helper that returns a namedtuple and the exepression here grabs the system attribute?

Can you make the whole thing a set comprehension please?

return original_name, suite_name, test_name, variant_name


def _compose_test(dir: str, file: str, failed_tests: str) -> dict:
Copy link
Contributor

Choose a reason for hiding this comment

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

You know you want to use typed dict?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

run-spread Outdated
if [ -z "$SPREAD_TAG_FEATURES" ]; then
SPREAD_USE_PREBUILT_SNAPD_SNAP=true exec spread "$@"
else
WRITE_DIR="/tmp/features"
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, can we use a temp dir?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since this would be for personal use, I thought tmp would be the best option.

run-spread Outdated
done

./tests/lib/compose-features.py \
--dir ${WRITE_DIR}/composed-feature-tags \
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we shellcheck the file and shfmt the text later?

@maykathm maykathm force-pushed the SNAPDENG-34441-add-feature-tagging-workflow branch from d4ad170 to 56daeb9 Compare March 21, 2025 10:34
@maykathm maykathm force-pushed the SNAPDENG-34441-add-feature-tagging-workflow branch from 56daeb9 to 49a5046 Compare March 21, 2025 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip spread Indicate that spread job should not run
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants