diff --git a/.github/workflows/build_wheel.yml b/.github/workflows/build_wheel.yml index 1edf42589..5467a7cc9 100644 --- a/.github/workflows/build_wheel.yml +++ b/.github/workflows/build_wheel.yml @@ -1,9 +1,6 @@ name: Build wheel and release into PYPI -on: - release: - types: [published] - +on: push: branches: - dev_off diff --git a/.github/workflows/build_wheels_on_release.yml b/.github/workflows/build_wheels_on_release.yml new file mode 100644 index 000000000..fd62c80c2 --- /dev/null +++ b/.github/workflows/build_wheels_on_release.yml @@ -0,0 +1,50 @@ +name: Build wheel and release into PYPI + +on: + release: + types: [published] + workflow_dispatch: {} + +jobs: + + build_wheels: + if: github.repository_owner == 'mlcommons' + name: Build wheel + runs-on: ubuntu-latest + environment: release + + permissions: + id-token: write + contents: write + + strategy: + fail-fast: false + steps: + # Step : Checkout the code + - uses: actions/checkout@v4 + with: + fetch-depth: 2 + ssh-key: ${{ secrets.DEPLOY_KEY }} + ref: ${{ github.ref_name }} + + # Step : Set up Python + - uses: actions/setup-python@v3 + + # Step : Install required dependencies + - name: Install requirements + run: python3 -m pip install setuptools wheel build + + # Step : Build the Python wheel + - name: Build wheels + working-directory: ./ + run: python3 -m build && rm dist/*.whl + + # Step : Publish to PyPI + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + with: + verify-metadata: true + skip-existing: true + packages-dir: dist + repository-url: https://upload.pypi.org/legacy/ + verbose: true diff --git a/VERSION b/VERSION index 3eefcb9dd..7dea76edb 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.0.0 +1.0.1 diff --git a/script/get-generic-sys-util/meta.yaml b/script/get-generic-sys-util/meta.yaml index bd4006e72..8f75171de 100644 --- a/script/get-generic-sys-util/meta.yaml +++ b/script/get-generic-sys-util/meta.yaml @@ -602,6 +602,14 @@ variations: brew: pkg-config dnf: pkg-config yum: pkg-config + postfix: + env: + MLC_SYS_UTIL_NAME: postfix + new_env_keys: + - MLC_POSTFIX_VERSION + state: + postfix: + apt: postfix psmisc: env: MLC_SYS_UTIL_NAME: psmisc diff --git a/script/send-mail/customize.py b/script/send-mail/customize.py new file mode 100644 index 000000000..d561f8466 --- /dev/null +++ b/script/send-mail/customize.py @@ -0,0 +1,47 @@ +from mlc import utils +import os +import subprocess + + +def preprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + # Start constructing the argument string + args = f"--subject '{env.get('MLC_EMAIL_SUBJECT', '')}' " + + # Process other arguments + args += f"--to_addresses '{env.get('MLC_EMAIL_TO_ADDRESSES', '')}' " + args += f"--cc_addresses '{env.get('MLC_EMAIL_CC_ADDRESSES', '')}' " + args += f"--bcc_addresses '{env.get('MLC_EMAIL_BCC_ADDRESSES', '')}' " + args += f"--content_file '{env.get('MLC_EMAIL_CONTENT_FILE', '')}' " + + # Process attachments + args += f"--attachments '{env.get('MLC_EMAIL_ATTACHMENTS', '')}'" + + # Add flags for SMTP server, email and password if needed + if env.get('MLC_EMAIL_USE_SMTP_SERVER'): + args += "--use_smtp_server " + args += f"--email '{env.get('MLC_EMAIL_SMPT_EMAIL', '')}' " + args += f"--password '{env.get('MLC_EMAIL_SMTP_PASSWORD', '')}' " + args += f"--smtp_server '{env.get('MLC_EMAIL_SMTP_SERVER', '')}' " + + subject = env.get('MLC_EMAIL_SUBJECT', '') + to_address = ",".join(env.get('MLC_EMAIL_TO_ADDRESS', [])) + + env['MLC_RUN_CMD'] = f"""{env['MLC_PYTHON_BIN_WITH_PATH']} {os.path.join(env['MLC_TMP_CURRENT_SCRIPT_PATH'], 'send-email.py')} {args}""" + + return {'return': 0} + + +def postprocess(i): + + env = i['env'] + state = i['state'] + + os_info = i['os_info'] + + return {'return': 0} diff --git a/script/send-mail/meta.yaml b/script/send-mail/meta.yaml new file mode 100644 index 000000000..90abe9d63 --- /dev/null +++ b/script/send-mail/meta.yaml @@ -0,0 +1,30 @@ +alias: send-mail +automation_alias: script +automation_uid: 5b4e0237da074764 +category: Utils +deps: + - tags: detect,os + - tags: get,python + names: + - python + - python3 + - tags: get,generic-sys-util,_postfix + enable_if_env: + MLC_HOST_OS_FLAVOR: + - ubuntu +new_env_keys: [] +new_state_keys: [] +post_deps: [] +posthook_deps: [] +prehook_deps: [] +input_mapping: + subject: MLC_EMAIL_SUBJECT + to_addresses: MLC_EMAIL_TO_ADDRESSES + to_address: MLC_EMAIL_TO_ADDRESSES + attachments: MLC_EMAIL_ATTACHMENTS + attachment: MLC_EMAIL_ATTACHMENTS +tags: +- send +- mail +- email +uid: 5f9b9654ecbe4662 diff --git a/script/send-mail/run.bat b/script/send-mail/run.bat new file mode 100644 index 000000000..80625c80e --- /dev/null +++ b/script/send-mail/run.bat @@ -0,0 +1,23 @@ +@echo off +setlocal enabledelayedexpansion + +:: Function to exit if the last command failed +:exit_if_error +if %ERRORLEVEL% NEQ 0 exit /b %ERRORLEVEL% +exit /b 0 + +:: Function to run a command +:run +echo Running: +echo %1 +echo. + +if /I "%MLC_FAKE_RUN%" NEQ "yes" ( + call %1 + call :exit_if_error +) +exit /b 0 + +:: Add your run commands here... +:: call :run "%MLC_RUN_CMD%" + diff --git a/script/send-mail/run.sh b/script/send-mail/run.sh new file mode 100644 index 000000000..99e53cc91 --- /dev/null +++ b/script/send-mail/run.sh @@ -0,0 +1,18 @@ +#!/bin/bash +function exit_if_error() { + test $? -eq 0 || exit $? +} + +function run() { + echo "Running: " + echo "$1" + echo "" + if [[ ${MLC_FAKE_RUN} != 'yes' ]]; then + eval "$1" + exit_if_error + fi +} + +#Add your run commands here... + +run "$MLC_RUN_CMD" diff --git a/script/send-mail/send-email.py b/script/send-mail/send-email.py new file mode 100644 index 000000000..0bb25f7e2 --- /dev/null +++ b/script/send-mail/send-email.py @@ -0,0 +1,131 @@ +import smtplib +import sys +import argparse +from email.mime.multipart import MIMEMultipart +from email.mime.base import MIMEBase +from email.mime.text import MIMEText +from email.utils import COMMASPACE +from email import encoders + + +def send_email(subject, to_addresses, cc_addresses, bcc_addresses, content_file, + attachments, use_smtp_server=False, smtp_server=None, email=None, password=None): + + to_list = to_addresses.split(',') + cc_list = cc_addresses.split(',') + bcc_list = bcc_addresses.split(',') + attachment_list = attachments.split(',') + + if content_file and os.path.exists(content_file): + with open(content_file, 'r') as file: + email_content = file.read() + else: + email_content = '' + + msg = MIMEMultipart() + msg['From'] = email if use_smtp_server else 'localhost' + msg['To'] = COMMASPACE.join(to_list) + msg['Cc'] = COMMASPACE.join(cc_list) + msg['Subject'] = subject + + msg.attach(MIMEText(email_content, 'plain')) + + for attachment in attachment_list: + if attachment.strip() == '': + continue + + with open(attachment, 'rb') as file: + part = MIMEBase('application', 'octet-stream') + part.set_payload(file.read()) + encoders.encode_base64(part) + part.add_header( + 'Content-Disposition', + f'attachment; filename={attachment}') + msg.attach(part) + + recipients = to_list + cc_list + bcc_list + + if use_smtp_server: + with smtplib.SMTP_SSL(smtp_server) as server: + server.login(email, password) + server.sendmail(email, recipients, msg.as_string()) + print("Email sent successfully using SMTP server!") + else: + with smtplib.SMTP('localhost') as server: + server.sendmail( + 'localhost@example.com', + recipients, + msg.as_string()) + print("Email sent successfully using localhost!") + + +if __name__ == '__main__': + parser = argparse.ArgumentParser( + description='Send an email with specified attachments') + parser.add_argument('--subject', type=str, help='Email subject') + parser.add_argument( + '--to_addresses', + type=str, + help='To addresses, comma-separated') + parser.add_argument( + '--cc_addresses', + type=str, + nargs='?', + default='', + help='CC addresses, comma-separated') + parser.add_argument( + '--bcc_addresses', + type=str, + nargs='?', + default='', + help='BCC addresses, comma-separated') + parser.add_argument( + '--content_file', + type=str, + nargs='?', + default='', + help='File containing email content') + parser.add_argument( + '--attachments', + type=str, + nargs='?', + default='', + + help='Attachments, comma-separated file paths') + + parser.add_argument( + '--use_smtp_server', + action='store_true', + help='Use an SMTP server instead of localhost') + parser.add_argument( + '--email', + type=str, + default='', + nargs='?', + help='Email address for SMTP server') + parser.add_argument( + '--password', + type=str, + default='', + nargs='?', + help='Password for SMTP server') + parser.add_argument('--smtp_server', type=str, help='SMTP server address') + + args = parser.parse_args() + + if args.use_smtp_server and not all( + [args.email, args.password, args.smtp_server]): + parser.error( + '--email, --password, and --smtp_server are required when --use_smtp_server is set') + + send_email( + args.subject, + args.to_addresses, + args.cc_addresses, + args.bcc_addresses, + args.content_file, + args.attachments, + args.use_smtp_server, + args.smtp_server, + args.email, + args.password)