diff --git a/.github/workflows/new_model_pr_merged_notification.yml b/.github/workflows/new_model_pr_merged_notification.yml new file mode 100644 index 00000000000..6282528c0b7 --- /dev/null +++ b/.github/workflows/new_model_pr_merged_notification.yml @@ -0,0 +1,68 @@ +# Used to notify core maintainers about new model PR being merged +name: New model PR merged notification + +on: + push: + branches: + - main + paths: + - 'src/transformers/models/*/modeling_*' + +jobs: + notify_new_model: + name: Notify new model + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Check new model + shell: bash + run: | + python -m pip install gitpython + python -c 'from utils.pr_slow_ci_models import get_new_model; new_model = get_new_model(diff_with_last_commit=True); print(new_model)' | tee output.txt + echo "NEW_MODEL=$(tail -n 1 output.txt)" >> $GITHUB_ENV + echo "COMMIT_SHA=$(git log -1 --format=%H)" >> $GITHUB_ENV + + - name: print commit sha + if: ${{ env.NEW_MODEL != ''}} + shell: bash + run: | + echo "$COMMIT_SHA" + + - name: print new model + if: ${{ env.NEW_MODEL != ''}} + shell: bash + run: | + echo "$NEW_MODEL" + + - name: Notify + if: ${{ env.NEW_MODEL != ''}} + uses: slackapi/slack-github-action@6c661ce58804a1a20f6dc5fbee7f0381b469e001 + with: + # Slack channel id, channel name, or user id to post message. + # See also: https://api.slack.com/methods/chat.postMessage#channels + channel-id: transformers-new-model-notification + # For posting a rich message using Block Kit + payload: | + { + "blocks": [ + { + "type": "header", + "text": { + "type": "plain_text", + "text": "New model!", + "emoji": true + } + }, + { + "type": "section", + "text": { + "type": "mrkdwn", + "text": " GH_ArthurZucker, GH_lysandrejik, GH_ydshieh" + } + } + ] + } + env: + SLACK_BOT_TOKEN: ${{ secrets.SLACK_CIFEEDBACK_BOT_TOKEN }} \ No newline at end of file diff --git a/utils/pr_slow_ci_models.py b/utils/pr_slow_ci_models.py index 312bd078e63..4403ade4980 100644 --- a/utils/pr_slow_ci_models.py +++ b/utils/pr_slow_ci_models.py @@ -64,7 +64,7 @@ def get_new_python_files_between_commits(base_commit: str, commits: List[str]) - return code_diff -def get_new_python_files() -> List[str]: +def get_new_python_files(diff_with_last_commit=False) -> List[str]: """ Return a list of python files that have been added between the current head and the main branch. @@ -80,17 +80,24 @@ def get_new_python_files() -> List[str]: # On GitHub Actions runners, it doesn't have local main branch main = repo.remotes.origin.refs.main - print(f"main is at {main.commit}") - print(f"Current head is at {repo.head.commit}") + if not diff_with_last_commit: + print(f"main is at {main.commit}") + print(f"Current head is at {repo.head.commit}") - branching_commits = repo.merge_base(main, repo.head) - for commit in branching_commits: - print(f"Branching commit: {commit}") - return get_new_python_files_between_commits(repo.head.commit, branching_commits) + commits = repo.merge_base(main, repo.head) + for commit in commits: + print(f"Branching commit: {commit}") + else: + print(f"main is at {main.commit}") + commits = main.commit.parents + for commit in commits: + print(f"Parent commit: {commit}") + + return get_new_python_files_between_commits(repo.head.commit, commits) -def get_new_model(): - new_files = get_new_python_files() +def get_new_model(diff_with_last_commit=False): + new_files = get_new_python_files(diff_with_last_commit) reg = re.compile(r"src/transformers/models/(.*)/modeling_.*\.py") new_model = ""