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

Try to build static files on github actions #35427

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

Conversation

AmitPhulera
Copy link
Contributor

@AmitPhulera AmitPhulera commented Nov 25, 2024

Product Description

This PR builds the static files and upload them as github artifacts. As of now it will only build staticfiles when anything is pushed on autostaging branch.

It does not affect anything on production. Just introduces one management command that will run on actions.

Safety Assurance

Pretty safe, have a very limited scope and that is also outside production for now.

Safety story

Automated test coverage

N/A

QA Plan

N/A

Rollback instructions

  • This PR can be reverted after deploy with no further considerations

Labels & Review

  • Risk label is set correctly
  • The set of people pinged as reviewers is appropriate for the level of risk of the change

@AmitPhulera AmitPhulera requested a review from a team as a code owner January 15, 2025 13:16
@AmitPhulera AmitPhulera requested a review from biyeun as a code owner January 29, 2025 10:37
@AmitPhulera AmitPhulera changed the title [WIP] Try to build static files on github actions Try to build static files on github actions Feb 19, 2025
./manage.py resource_static
echo "Finished resource_static."
Copy link
Contributor

Choose a reason for hiding this comment

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

super nitpicky: Logging after seems like it mainly adds noise to the logs since there is immediately another log message before the next task starts. Would it make sense to remove the echo "Finished ..." lines?

return parts[-1]

# Default to last part of path
return parts[-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that this is the default, the previous two conditions ('contrib' in parts and 'apps' in parts) that also return parts[-1] seem redundant. Would it make sense to remove them?

return parts[-1]

# Get list of installed app paths
installed_apps = {get_app_name(app.name): app.path for app in apps.get_app_configs()}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is possible for two apps to have the same result of get_app_name(app.name), although we do not appear to have any at this time. However, this expression would silently omit one of them if that ever happened. For example, if we created corehq.apps.admin it would be a duplicate of django.contrib.admin.

Suggested change
installed_apps = {get_app_name(app.name): app.path for app in apps.get_app_configs()}
installed_apps = {get_app_name(app.name): app.path for app in apps.get_app_configs()}
from collections import Counter
names = Counter([get_app_name(app.name) for app in apps.get_app_configs()])
assert names.most_common(1)[0][1] == 1, "found duplicate app names: " \
+ ', '.join(n for n in names if names[n] > 1)


def should_copy_directory(dir_name):
# Skip node_modules
if 'node_modules' in dir_name:
Copy link
Contributor

Choose a reason for hiding this comment

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

Would == make more sense here? I don't expect it to happen, but imagine if we had an app named anode_modules (it would be excluded). But see the suggestion below before doing that.

Comment on lines +57 to +69
# Skip node_modules
if 'node_modules' in dir_name:
return False

# Check if directory is an installed app
if dir_name in installed_apps:
return True

# Check if directory is in additional_dirs
if dir_name in additional_dirs:
return True

return False
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# Skip node_modules
if 'node_modules' in dir_name:
return False
# Check if directory is an installed app
if dir_name in installed_apps:
return True
# Check if directory is in additional_dirs
if dir_name in additional_dirs:
return True
return False
return dir_name in installed_apps or dir_name in additional_dirs


if os.path.isdir(src_path) and should_copy_directory(item):
self.stdout.write(f"Copying {item}...")
copy_directory(src_path, dst_path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can copy_directory be replaced with shutil.copytree?

Suggested change
copy_directory(src_path, dst_path)
shutil.copytree(src_path, dst_path, dirs_exist_ok=True)

Could also pass ignore=ignore_patterns('node_modules') if these directories may contain node_modules that should be excluded. Is that necessary?

Comment on lines +34 to +46
# Split on dots and get the last part
parts = app_path.split('.')

# Handle special cases like 'django.contrib.admin' -> 'admin'
if 'contrib' in parts:
return parts[-1]

# Handle cases like 'corehq.apps.users' -> 'users'
if 'apps' in parts:
return parts[-1]

# Default to last part of path
return parts[-1]
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that this is the default, the previous two conditions ('contrib' in parts and 'apps' in parts) that also return parts[-1] seem redundant. Would it make sense to remove them?

Suggested change
# Split on dots and get the last part
parts = app_path.split('.')
# Handle special cases like 'django.contrib.admin' -> 'admin'
if 'contrib' in parts:
return parts[-1]
# Handle cases like 'corehq.apps.users' -> 'users'
if 'apps' in parts:
return parts[-1]
# Default to last part of path
return parts[-1]
return app_path.rsplit('.', 1)[-1]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants