• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1{%- set upload_artifact_s3_action = "seemethere/upload-artifact-s3@v5" -%}
2{%- set download_artifact_s3_action = "seemethere/download-artifact-s3@v4" -%}
3{%- set upload_artifact_action = "actions/upload-artifact@v3" -%}
4{%- set download_artifact_action = "actions/download-artifact@v3" -%}
5
6{%- set timeout_minutes = 240 -%}
7
8# NOTE: If testing pytorch/builder changes you can change this variable to change what pytorch/builder reference
9#       the binary builds will check out
10{%- set builder_repo = "pytorch/builder" -%}
11{%- set builder_branch = "release/2.4" -%}
12
13{%- macro concurrency(build_environment) -%}
14concurrency:
15  group: !{{ build_environment }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.ref_type == 'branch' && github.sha }}-${{ github.event_name == 'workflow_dispatch' }}
16  cancel-in-progress: true
17{%- endmacro -%}
18
19{%- macro display_ec2_information() -%}
20      - name: Display EC2 information
21        shell: bash
22        run: |
23          set -euo pipefail
24          function get_ec2_metadata() {
25            # Pulled from instance metadata endpoint for EC2
26            # see https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
27            category=$1
28            curl -fsSL "http://169.254.169.254/latest/meta-data/${category}"
29          }
30          echo "ami-id: $(get_ec2_metadata ami-id)"
31          echo "instance-id: $(get_ec2_metadata instance-id)"
32          echo "instance-type: $(get_ec2_metadata instance-type)"
33          echo "system info $(uname -a)"
34{%- endmacro -%}
35
36{%- macro setup_ec2_windows() -%}
37      !{{ display_ec2_information() }}
38      - name: "[FB EMPLOYEES] Enable SSH (Click me for login details)"
39        uses: pytorch/test-infra/.github/actions/setup-ssh@main
40        continue-on-error: true
41        with:
42          github-secret: ${{ secrets.GITHUB_TOKEN }}
43      # Needed for binary builds, see: https://github.com/pytorch/pytorch/issues/73339#issuecomment-1058981560
44      - name: Enable long paths on Windows
45        shell: powershell
46        run: |
47          Set-ItemProperty -Path "HKLM:\\SYSTEM\CurrentControlSet\Control\FileSystem" -Name "LongPathsEnabled" -Value 1
48      # Since it's just a defensive command, the workflow should continue even the command fails. This step can be
49      # removed once Windows Defender is removed from the AMI
50      - name: Disables Windows Defender scheduled and real-time scanning for files in directories used by PyTorch
51        continue-on-error: true
52        shell: powershell
53        run: |
54          Add-MpPreference -ExclusionPath $(Get-Location).tostring(),$Env:TEMP -ErrorAction Ignore
55          # Let's both exclude the path and disable Windows Defender completely just to be sure
56          # that it doesn't interfere
57          Set-MpPreference -DisableRealtimeMonitoring $True -ErrorAction Ignore
58{%- endmacro -%}
59
60{%- macro apply_filter() -%}
61      - name: Check if the job is disabled
62        id: filter
63        # Binary workflows checkout to pytorch subdirectory instead
64        uses: ./pytorch/.github/actions/filter-test-configs
65        with:
66          github-token: ${{ secrets.GITHUB_TOKEN }}
67          # NB: Use a mock test matrix with a default value here. After filtering, if the
68          # returned matrix is empty, it means that the job is disabled
69          test-matrix: |
70            { include: [
71              { config: "default" },
72            ]}
73{%- endmacro -%}
74
75{%- macro checkout(submodules="recursive", deep_clone=True, directory="", repository="pytorch/pytorch", branch="", checkout_pr_head=True) -%}
76      - name: Checkout !{{ 'PyTorch' if repository == "pytorch/pytorch" else repository }}
77        uses: malfet/checkout@silent-checkout
78        with:
79      {%- if branch %}
80          ref: !{{ branch }}
81      {%- elif checkout_pr_head %}
82          ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
83      {%- endif %}
84      {%- if deep_clone %}
85          # deep clone, to allow use of git merge-base
86          fetch-depth: 0
87      {%- endif %}
88          submodules: !{{ submodules }}
89      {%- if repository != "pytorch/pytorch" %}
90          repository: !{{ repository }}
91      {%- endif %}
92      {%- if directory %}
93          path: !{{ directory }}
94      {%- endif %}
95          quiet-checkout: true
96      - name: Clean !{{ 'PyTorch' if repository == "pytorch/pytorch" else repository }} checkout
97        run: |
98          # Remove any artifacts from the previous checkouts
99          git clean -fxd
100      {%- if directory%}
101        working-directory: !{{ directory }}
102      {%- endif %}
103{%- endmacro -%}
104
105{%- macro wait_and_kill_ssh_windows(pytorch_directory="") -%}
106      - name: Wait until all sessions have drained
107        shell: powershell
108{%- if pytorch_directory %}
109        working-directory: !{{ pytorch_directory }}
110{%- endif %}
111        if: always()
112        timeout-minutes: 120
113        run: |
114          .github\scripts\wait_for_ssh_to_drain.ps1
115      - name: Kill active ssh sessions if still around (Useful if workflow was cancelled)
116        shell: powershell
117{%- if pytorch_directory %}
118        working-directory: !{{ pytorch_directory }}
119{%- endif %}
120        if: always()
121        run: |
122          .github\scripts\kill_active_ssh_sessions.ps1
123{%- endmacro -%}
124