Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/workflows/macos-job.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: Run a macOS job

on:
workflow_call:
inputs:
script:
description: 'Script to utilize'
default: "python setup.py bdist_wheel"
type: string
timeout:
description: 'Timeout for the job (in minutes)'
default: 30
type: number
runner:
description: 'Runner type to utilize'
default: "macos-12"
type: string
python-version:
description: If set to any value, dont use sudo to clean the workspace
required: false
type: string
default: "3.9"
upload-artifact:
description: 'Name to give artifacts uploaded from ${RUNNER_ARTIFACT_DIR}'
default: ""
type: string
download-artifact:
description: 'Name to download artifacts to ${RUNNER_ARTIFACT_DIR}'
default: ""
type: string
repository:
description: 'Repository to checkout, defaults to ""'
default: ""
type: string
fetch-depth:
description: 'Number of commits to fetch, defaults to 1 similar to actions/checkout'
default: 1
type: number
submodules:
description:
Same as actions/checkout, set to `true` to checkout submodules or `recursive` to
recursively checkout everything
default: ""
type: string
ref:
description: 'Reference to checkout, defaults to "nightly"'
default: ""
type: string
test-infra-repository:
description: "Test infra repository to use"
default: "pytorch/test-infra"
type: string
test-infra-ref:
description: "Test infra reference to use"
default: ""
type: string
job-name:
description: "Name for the job, which is displayed in the GitHub UI"
default: "macos-job"
type: string
continue-on-error:
description: "Prevents a job from failing when a step fails. Set to true to allow a job to pass when exec script step fails."
default: false
type: boolean
binary-matrix:
description: "If we are calling this workflow with binary build matrix entry, will initialize matrix entries and env vars"
required: false
default: ''
type: string

jobs:
job:
name: ${{ inputs.job-name }}
env:
REPOSITORY: ${{ inputs.repository || github.repository }}
SCRIPT: ${{ inputs.script }}
runs-on: ${{ inputs.runner }}
timeout-minutes: ${{ inputs.timeout }}
steps:
- name: Clean workspace
run: |
echo "::group::Cleanup debug output"
rm -rfv "${GITHUB_WORKSPACE}"
mkdir -p "${GITHUB_WORKSPACE}"
echo "::endgroup::"

- name: Checkout repository (${{ inputs.test-infra-repository }}@${{ inputs.test-infra-ref }})
uses: actions/checkout@v3
with:
# Support the use case where we need to checkout someone's fork
repository: ${{ inputs.test-infra-repository }}
ref: ${{ inputs.test-infra-ref }}
path: test-infra

- name: Setup miniconda
uses: ./test-infra/.github/actions/setup-miniconda

- name: Checkout repository (${{ inputs.repository || github.repository }}@${{ inputs.ref }})
uses: actions/checkout@v3
with:
# Support the use case where we need to checkout someone's fork
repository: ${{ inputs.repository || github.repository }}
ref: ${{ inputs.ref || github.ref }}
path: ${{ inputs.repository || github.repository }}
fetch-depth: ${{ inputs.fetch-depth }}
submodules: ${{ inputs.submodules }}

- name: Setup useful environment variables
working-directory: ${{ inputs.repository }}
run: |
RUNNER_ARTIFACT_DIR="${RUNNER_TEMP}/artifacts"
mkdir -p "${RUNNER_ARTIFACT_DIR}"
echo "RUNNER_ARTIFACT_DIR=${RUNNER_ARTIFACT_DIR}" >> "${GITHUB_ENV}"

RUNNER_TEST_RESULTS_DIR="${RUNNER_TEMP}/test-results"
mkdir -p "${RUNNER_TEST_RESULTS_DIR}"
echo "RUNNER_TEST_RESULTS_DIR=${RUNNER_TEST_RESULTS_DIR}" >> "${GITHUB_ENV}"

- name: Download artifacts (if any)
uses: actions/download-artifact@v3
if: ${{ inputs.download-artifact != '' }}
with:
name: ${{ inputs.download-artifact }}
path: ${{ runner.temp }}/artifacts/

- name: Run script
shell: bash -l {0}
continue-on-error: ${{ inputs.continue-on-error }}
working-directory: ${{ inputs.repository }}
run: |
{
echo "#!/usr/bin/env bash";
echo "set -eou pipefail";
# Source conda so it's available to the script environment
echo 'eval "$(conda shell.bash hook)"';
echo "${SCRIPT}";
} > "${RUNNER_TEMP}/exec_script"
while read line; do
eval "export ${line}"
done < "${RUNNER_TEMP}/github_env_${GITHUB_RUN_ID}"
bash "${RUNNER_TEMP}/exec_script"

- name: Surface failing tests
if: always()
uses: pmeier/[email protected]
with:
path: ${{ env.RUNNER_TEST_RESULTS_DIR }}
fail-on-empty: false

- name: Setup upterm session
uses: owenthereal/action-upterm@v1
with:
limit-access-to-actor: true

- name: Check if there are potential artifacts and move them to the correct artifact location
shell: bash -l {0}
working-directory: ${{ inputs.repository }}
id: check-artifacts
if: ${{ inputs.upload-artifact != '' }}
env:
UPLOAD_ARTIFACT_NAME: ${{ inputs.upload-artifact }}
run: |
# If the default execution path is followed then we should get a wheel in the dist/ folder
# attempt to just grab whatever is in there and scoop it all up
if find "dist/" -name "*.whl" >/dev/null 2>/dev/null; then
mv -v dist/*.whl "${RUNNER_ARTIFACT_DIR}/"
fi
# Set to fail upload step if there are no files for upload and expected files for upload
echo 'if-no-files-found=error' >> "${GITHUB_OUTPUT}"

- name: Upload artifacts to GitHub (if any)
uses: actions/upload-artifact@v3
if: ${{ inputs.upload-artifact != '' }}
with:
name: ${{ inputs.upload-artifact }}
path: ${{ runner.temp }}/artifacts/
if-no-files-found: ${{ steps.check-artifacts.outputs.if-no-files-found }}
Loading
Loading