diff --git a/.github/actions/filter-test-configs/action.yml b/.github/actions/filter-test-configs/action.yml index 25ffe7877b1dd..4794495fb7610 100644 --- a/.github/actions/filter-test-configs/action.yml +++ b/.github/actions/filter-test-configs/action.yml @@ -13,6 +13,10 @@ inputs: required: true type: string description: JSON description of what test configs to run. + job-name: + type: string + required: false + default: "" outputs: test-matrix: @@ -56,6 +60,7 @@ runs: - name: Get the job name id: get-job-name + if: inputs.job-name == '' continue-on-error: true shell: bash run: | @@ -91,7 +96,7 @@ runs: shell: bash env: GITHUB_TOKEN: ${{ inputs.github-token }} - JOB_NAME: ${{ steps.get-job-name.outputs.job-name }} + JOB_NAME: ${{ inputs.job-name == '' && steps.get-job-name.outputs.job-name || inputs.job-name }} PR_NUMBER: ${{ github.event.pull_request.number }} TAG: ${{ steps.parse-ref.outputs.tag }} EVENT_NAME: ${{ github.event_name }} diff --git a/.github/actions/get-workflow-job-id/action.yml b/.github/actions/get-workflow-job-id/action.yml index be202c960c773..b910b33fe0779 100644 --- a/.github/actions/get-workflow-job-id/action.yml +++ b/.github/actions/get-workflow-job-id/action.yml @@ -11,18 +11,20 @@ outputs: job-id: description: The retrieved workflow job id value: ${{ steps.get-job-id.outputs.job-id }} + job-name: + description: The retrieved workflow job name + value: ${{ steps.get-job-id.outputs.job-name }} runs: using: composite steps: - - name: Get jobid or fail + - name: Get job id and name or fail # timeout-minutes is unsupported for composite workflows, see https://github.com/actions/runner/issues/1979 # timeout-minutes: 10 shell: bash id: get-job-id run: | set -eux - GHA_WORKFLOW_JOB_ID=$(python3 .github/scripts/get_workflow_job_id.py "${GITHUB_RUN_ID}" "${RUNNER_NAME}") - echo "job-id=${GHA_WORKFLOW_JOB_ID}" >> "${GITHUB_OUTPUT}" + python3 .github/scripts/get_workflow_job_id.py "${GITHUB_RUN_ID}" "${RUNNER_NAME}" env: GITHUB_TOKEN: ${{ inputs.github-token }} diff --git a/.github/scripts/get_workflow_job_id.py b/.github/scripts/get_workflow_job_id.py index c0244c74670be..4fd11c12fe166 100644 --- a/.github/scripts/get_workflow_job_id.py +++ b/.github/scripts/get_workflow_job_id.py @@ -111,7 +111,7 @@ def fetch_jobs(url: str, headers: Dict[str, str]) -> List[Dict[str, str]]: # running. -def find_job_id(args: Any) -> str: +def find_job_id_name(args: Any) -> Tuple[str, str]: # From https://docs.github.com/en/actions/learn-github-actions/environment-variables PYTORCH_REPO = os.environ.get("GITHUB_REPOSITORY", "pytorch/pytorch") PYTORCH_GITHUB_API = f"https://api.github.com/repos/{PYTORCH_REPO}" @@ -130,15 +130,27 @@ def find_job_id(args: Any) -> str: for job in jobs: if job["runner_name"] == args.runner_name: - return job["id"] + return (job["id"], job["name"]) raise RuntimeError(f"Can't find job id for runner {args.runner_name}") +def set_output(name: str, val: Any) -> None: + if os.getenv("GITHUB_OUTPUT"): + with open(str(os.getenv("GITHUB_OUTPUT")), "a") as env: + print(f"{name}={val}", file=env) + else: + print(f"::set-output name={name}::{val}") + + def main() -> None: args = parse_args() try: - print(find_job_id(args)) + # Get both the job ID and job name because we have already spent a request + # here to get the job info + job_id, job_name = find_job_id_name(args) + set_output("job-id", job_id) + set_output("job-name", job_name) except Exception as e: print(repr(e), file=sys.stderr) print(f"workflow-{args.workflow_run_id}") diff --git a/.github/workflows/_linux-build.yml b/.github/workflows/_linux-build.yml index fa66e366ee62b..8bb09a27a46f4 100644 --- a/.github/workflows/_linux-build.yml +++ b/.github/workflows/_linux-build.yml @@ -116,6 +116,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Build if: steps.filter.outputs.is-test-matrix-empty == 'False' || inputs.test-matrix == '' diff --git a/.github/workflows/_linux-test.yml b/.github/workflows/_linux-test.yml index 2fbe7447b0357..d2e02300836e8 100644 --- a/.github/workflows/_linux-test.yml +++ b/.github/workflows/_linux-test.yml @@ -128,6 +128,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Download pytest cache uses: ./.github/actions/pytest-cache-download diff --git a/.github/workflows/_mac-build.yml b/.github/workflows/_mac-build.yml index a8a7d09bdec05..a27ddaf629b51 100644 --- a/.github/workflows/_mac-build.yml +++ b/.github/workflows/_mac-build.yml @@ -160,6 +160,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Build if: steps.filter.outputs.is-test-matrix-empty == 'False' || inputs.test-matrix == '' diff --git a/.github/workflows/_mac-test-mps.yml b/.github/workflows/_mac-test-mps.yml index 51effa1d7f3bb..c92b625fefe6d 100644 --- a/.github/workflows/_mac-test-mps.yml +++ b/.github/workflows/_mac-test-mps.yml @@ -154,6 +154,7 @@ jobs: with: use-gha: true file-suffix: ${{ github.job }}-${{ matrix.config }}-${{ matrix.shard }}-${{ matrix.num_shards }}-${{ matrix.runner }}_${{ steps.get-job-id.outputs.job-id }} + - name: Clean up disk space if: always() continue-on-error: true diff --git a/.github/workflows/_mac-test.yml b/.github/workflows/_mac-test.yml index 3188eb8587ffb..58579c43f2045 100644 --- a/.github/workflows/_mac-test.yml +++ b/.github/workflows/_mac-test.yml @@ -99,6 +99,13 @@ jobs: id: parse-ref run: .github/scripts/parse_ref.py + - name: Get workflow job id + id: get-job-id + uses: ./.github/actions/get-workflow-job-id + if: always() + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Check for keep-going label and re-enabled test issues # This uses the filter-test-configs action because it conviniently # checks for labels and re-enabled test issues. It does not actually do @@ -108,6 +115,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Pre-process arm64 wheels if: inputs.build-environment == 'macos-12-py3-arm64' @@ -180,13 +188,6 @@ jobs: run: | cat test/**/*_toprint.log || true - - name: Get workflow job id - id: get-job-id - uses: ./.github/actions/get-workflow-job-id - if: always() - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Stop monitoring script if: always() && ${{ steps.monitor-script.outputs.monitor-script-pid }} continue-on-error: true diff --git a/.github/workflows/_rocm-test.yml b/.github/workflows/_rocm-test.yml index 0f2e1e1daf362..50a5853fde14e 100644 --- a/.github/workflows/_rocm-test.yml +++ b/.github/workflows/_rocm-test.yml @@ -84,6 +84,13 @@ jobs: id: parse-ref run: .github/scripts/parse_ref.py + - name: Get workflow job id + id: get-job-id + uses: ./.github/actions/get-workflow-job-id + if: always() + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Check for keep-going label and re-enabled test issues # This uses the filter-test-configs action because it conviniently # checks for labels and re-enabled test issues. It does not actually do @@ -93,6 +100,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Set Test step time id: test-timeout @@ -201,13 +209,6 @@ jobs: run: | cat test/**/*_toprint.log || true - - name: Get workflow job id - id: get-job-id - uses: ./.github/actions/get-workflow-job-id - if: always() - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Stop monitoring script if: always() && steps.monitor-script.outputs.monitor-script-pid shell: bash diff --git a/.github/workflows/_win-build.yml b/.github/workflows/_win-build.yml index da1c48550705f..42d2b1c55351d 100644 --- a/.github/workflows/_win-build.yml +++ b/.github/workflows/_win-build.yml @@ -105,6 +105,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Build if: steps.filter.outputs.is-test-matrix-empty == 'False' || inputs.test-matrix == '' diff --git a/.github/workflows/_win-test.yml b/.github/workflows/_win-test.yml index 5daa2867c37d0..bba18e9f714a4 100644 --- a/.github/workflows/_win-test.yml +++ b/.github/workflows/_win-test.yml @@ -114,6 +114,13 @@ jobs: run: | tree /F C:\$Env:GITHUB_RUN_ID\build-results + - name: Get workflow job id + id: get-job-id + uses: ./.github/actions/get-workflow-job-id + if: always() + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Check for keep-going label and re-enabled test issues # This uses the filter-test-configs action because it conviniently # checks for labels and re-enabled test issues. It does not actually do @@ -123,6 +130,7 @@ jobs: with: github-token: ${{ secrets.GITHUB_TOKEN }} test-matrix: ${{ inputs.test-matrix }} + job-name: ${{ steps.get-job-id.outputs.job-name }} - name: Download pytest cache uses: ./.github/actions/pytest-cache-download @@ -188,13 +196,6 @@ jobs: run: | cat test/**/*_toprint.log || true - - name: Get workflow job id - id: get-job-id - uses: ./.github/actions/get-workflow-job-id - if: always() - with: - github-token: ${{ secrets.GITHUB_TOKEN }} - - name: Stop monitoring script if: always() && steps.monitor-script.outputs.monitor-script-pid shell: bash