diff --git a/.circleci/config.yml b/.circleci/config.yml index 19428b7bb9c..f1cd43d7e10 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,6 +7,18 @@ parameters: nightly: type: boolean default: false + GHA_Actor: + type: string + default: "" + GHA_Action: + type: string + default: "" + GHA_Event: + type: string + default: "" + GHA_Meta: + type: string + default: "" jobs: # Ensure running with CircleCI/huggingface @@ -31,8 +43,12 @@ jobs: parallelism: 1 steps: - checkout - - run: if [[ "$CIRCLE_PULL_REQUEST" == "" && "$CIRCLE_BRANCH" != "main" && "$CIRCLE_BRANCH" != *-release ]]; then echo "Not a PR, not the main branch and not a release branch, skip test!"; circleci-agent step halt; fi - - run: 'curl -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/${CIRCLE_PULL_REQUEST##*/} >> github.txt' + - run: git branch + - run: git log -n 1 + - run: python3 utils/extract_pr_number_from_circleci.py > pr_number.txt + - run: echo $(cat pr_number.txt) + - run: if [[ "$(cat pr_number.txt)" == "" && "$CIRCLE_BRANCH" != "main" && "$CIRCLE_BRANCH" != *-release ]]; then echo "Not a PR, not the main branch and not a release branch, skip test!"; circleci-agent step halt; fi + - run: 'curl -L -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" https://api.github.com/repos/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/pulls/$(cat pr_number.txt) >> github.txt' - run: cat github.txt - run: (python3 -c 'import json; from datetime import datetime; fp = open("github.txt"); data = json.load(fp); fp.close(); f = "%Y-%m-%dT%H:%M:%SZ"; created = datetime.strptime(data["created_at"], f); updated = datetime.strptime(data["updated_at"], f); s = (updated - created).total_seconds(); print(int(s))' || true) > elapsed.txt - run: if [ "$(cat elapsed.txt)" == "" ]; then echo 60 > elapsed.txt; fi diff --git a/.circleci/create_circleci_config.py b/.circleci/create_circleci_config.py index 757ad7e06ea..0ec793a66de 100644 --- a/.circleci/create_circleci_config.py +++ b/.circleci/create_circleci_config.py @@ -398,7 +398,12 @@ def create_circleci_config(folder=None): "parameters": { # Only used to accept the parameters from the trigger "nightly": {"type": "boolean", "default": False}, - "tests_to_run": {"type": "string", "default": ''}, + # Only used to accept the parameters from GitHub Actions trigger + "GHA_Actor": {"type": "string", "default": ""}, + "GHA_Action": {"type": "string", "default": ""}, + "GHA_Event": {"type": "string", "default": ""}, + "GHA_Meta": {"type": "string", "default": ""}, + "tests_to_run": {"type": "string", "default": ""}, **{j.job_name + "_test_list":{"type":"string", "default":''} for j in jobs}, **{j.job_name + "_parallelism":{"type":"integer", "default":1} for j in jobs}, }, diff --git a/.github/workflows/trigger_circleci.yml b/.github/workflows/trigger_circleci.yml new file mode 100644 index 00000000000..c278610eccf --- /dev/null +++ b/.github/workflows/trigger_circleci.yml @@ -0,0 +1,16 @@ +name: Trigger CircleCI + +on: + pull_request_target: + types: [ready_for_review] + +jobs: + trigger-circleci: + runs-on: ubuntu-22.04 + steps: + - name: trigger CircleCI pipeline via GitHub Actions + uses: CircleCI-Public/trigger-circleci-pipeline-action@v1.0.5 + with: + GHA_Meta: "Trigger via GitHub Actions" + env: + CCI_TOKEN: ${{ secrets.CIRCLECI_PAT }} diff --git a/utils/extract_pr_number_from_circleci.py b/utils/extract_pr_number_from_circleci.py new file mode 100644 index 00000000000..8dbfcb60a53 --- /dev/null +++ b/utils/extract_pr_number_from_circleci.py @@ -0,0 +1,31 @@ +# coding=utf-8 +# Copyright 2025 The HuggingFace Inc. team. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Used by `.github/workflows/trigger_circleci.yml` to get the pull request number in CircleCI job runs.""" + +import os + + +if __name__ == "__main__": + pr_number = "" + + pr = os.environ.get("CIRCLE_PULL_REQUEST", "") + if len(pr) > 0: + pr_number = pr.split("/")[-1] + if pr_number == "": + pr = os.environ.get("CIRCLE_BRANCH", "") + if pr.startswith("pull/"): + pr_number = "".join(pr.split("/")[1:2]) + + print(pr_number)