diff --git a/.github/workflows/warn-on-updating-requirements.yml b/.github/workflows/warn-on-updating-requirements.yml index 25f28e3ae744c7..45300b0235781b 100644 --- a/.github/workflows/warn-on-updating-requirements.yml +++ b/.github/workflows/warn-on-updating-requirements.yml @@ -17,10 +17,13 @@ jobs: pull-requests: write steps: - uses: actions/checkout@v4 + - name: Install dependencies + run: | + pip install requests - name: Post warning if file is edited uses: actions/github-script@v7 - with: - github-token: ${{secrets.GITHUB_TOKEN}} - script: | - const warn = require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/warn-requirements.js`); - await warn({ context, github }); + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + python dev/warn_on_editing_requirements.py \ + --pull-number ${{ github.event.pull_request.number }} diff --git a/.github/workflows/warn-requirements.js b/.github/workflows/warn-requirements.js deleted file mode 100644 index cad6a1b21cf7b1..00000000000000 --- a/.github/workflows/warn-requirements.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = async ({ context, github }) => { - const { owner, repo } = context.repo; - const { number } = context.issue; - - await github.rest.issues.createComment({ - issue_number: number, - owner: owner, - repo: repo, - body: "⚠️ Warning: It looks like you're editing requirements for MLflow. Please ensure that this doesn't cause any dependency conflicts with downstream tasks that depend on MLflow (e.g. image building).", - }); -}; diff --git a/dev/warn_on_editing_requirements.py b/dev/warn_on_editing_requirements.py new file mode 100644 index 00000000000000..4a5144c2a33e36 --- /dev/null +++ b/dev/warn_on_editing_requirements.py @@ -0,0 +1,29 @@ +import argparse +import os + +import requests + + +def comment(pull_number): + body = ( + "⚠️ Warning: It looks like you're editing requirements for MLflow. " + "Please ensure that this doesn't cause any dependency conflicts with " + "downstream tasks that depend on MLflow (e.g. image building)." + ) + token = os.environ.get("GITHUB_TOKEN") + headers = {"Authorization": f"token {token}"} + requests.post( + f"https://api.github.com/repos/mlflow/mlflow/issues/{pull_number}/comments", + json={"body": body}, + headers=headers, + ) + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--pull-number", required=True) + comment(parser.parse_args().pull_number) + + +if __name__ == "__main__": + main()