Skip to content

Commit 17020d8

Browse files
authored
Refactor conda upload job to a separate job running on GH ephemeral runner (#4886)
Similar to #4877, this moves conda upload into a separate job on GH ephemeral runner: * I need a new `_binary_conda_upload` reusable workflow because conda upload uses anaconda client to upload to conda, not awscli to upload to S3. * The build job doesn't have access to `pytorchbot-env` anymore, thus it has no access to `CONDA_PYTORCHBOT_TOKEN` and `CONDA_PYTORCHBOT_TOKEN_TEST` secrets. Only the upload job has this access.
1 parent 3bec171 commit 17020d8

File tree

4 files changed

+154
-82
lines changed

4 files changed

+154
-82
lines changed
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: upload conda
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
repository:
7+
description: 'Repository to checkout, defaults to ""'
8+
default: ''
9+
type: string
10+
ref:
11+
description: 'Reference to checkout, defaults to "nightly"'
12+
default: 'nightly'
13+
type: string
14+
test-infra-repository:
15+
description: 'Test infra repository to use'
16+
default: "pytorch/test-infra"
17+
type: string
18+
test-infra-ref:
19+
description: 'Test infra reference to use'
20+
default: ""
21+
type: string
22+
build-matrix:
23+
description: 'Build matrix to utilize'
24+
default: ''
25+
type: string
26+
trigger-event:
27+
description: 'Trigger Event in caller that determines whether or not to upload'
28+
type: string
29+
default: ''
30+
secrets:
31+
CONDA_PYTORCHBOT_TOKEN:
32+
description: 'Access Token needed to upload binaries to anaconda nightly channel'
33+
required: false
34+
CONDA_PYTORCHBOT_TOKEN_TEST:
35+
description: 'Access Token needed to upload binaries to anaconda test channel'
36+
required: false
37+
38+
jobs:
39+
upload:
40+
runs-on: ubuntu-22.04
41+
environment: ${{(inputs.trigger-event == 'push' && (startsWith(github.event.ref, 'refs/heads/nightly') || startsWith(github.event.ref, 'refs/tags/v'))) && 'pytorchbot-env' || ''}}
42+
strategy:
43+
fail-fast: false
44+
matrix: ${{ fromJSON(inputs.build-matrix) }}
45+
timeout-minutes: 30
46+
name: ${{ matrix.build_name }}
47+
steps:
48+
- uses: actions/checkout@v3
49+
with:
50+
repository: ${{ inputs.test-infra-repository }}
51+
ref: ${{ inputs.test-infra-ref }}
52+
path: test-infra
53+
54+
# For pytorch_pkg_helpers which we need to run to generate the artifact name and target S3 buckets
55+
- uses: ./test-infra/.github/actions/setup-binary-upload
56+
with:
57+
repository: ${{ inputs.repository }}
58+
ref: ${{ inputs.ref }}
59+
python-version: ${{ matrix.python_version }}
60+
cuda-version: ${{ matrix.desired_cuda }}
61+
upload-to-base-bucket: ${{ matrix.upload_to_base_bucket }}
62+
63+
- uses: ./test-infra/.github/actions/set-channel
64+
65+
- name: Download the artifact
66+
uses: actions/download-artifact@v3
67+
with:
68+
name: ${{ env.ARTIFACT_NAME }}
69+
path: ${{ inputs.repository }}/distr
70+
71+
- name: Nightly or release RC
72+
if: ${{ (inputs.trigger-event == 'push' && startsWith(github.event.ref, 'refs/heads/nightly')) || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
73+
shell: bash
74+
env:
75+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
76+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
77+
run: |
78+
set -ex
79+
echo "NIGHTLY_OR_TEST=1" >> "${GITHUB_ENV}"
80+
81+
if [[ "${CHANNEL}" = "nightly" ]]; then
82+
echo "CONDA_TOKEN=${CONDA_PYTORCHBOT_TOKEN}" >> "${GITHUB_ENV}"
83+
else
84+
echo "CONDA_TOKEN=${CONDA_PYTORCHBOT_TOKEN_TEST}" >> "${GITHUB_ENV}"
85+
fi
86+
87+
- name: Upload package to conda
88+
working-directory: ${{ inputs.repository }}
89+
run: |
90+
set -ex
91+
92+
# shellcheck disable=SC1090
93+
source "${BUILD_ENV_FILE}"
94+
conda install --yes --quiet anaconda-client
95+
96+
if [[ "${NIGHTLY_OR_TEST:-0}" == "1" ]]; then
97+
for pkg in distr/**/*.tar.bz2; do
98+
anaconda \
99+
-t "${CONDA_TOKEN}" \
100+
upload "${pkg}" \
101+
-u "pytorch-${CHANNEL}" \
102+
--label main \
103+
--no-progress \
104+
--force
105+
done
106+
else
107+
echo "Testing the upload of the following files to pytorch-${CHANNEL} conda channel:"
108+
for pkg in distr/**/*.tar.bz2; do
109+
ls -lah "${pkg}"
110+
done
111+
fi

.github/workflows/build_conda_linux.yml

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ jobs:
8181
CU_VERSION: ${{ matrix.desired_cuda }}
8282
name: ${{ matrix.build_name }}
8383
runs-on: ${{ matrix.validation_runner }}
84-
environment: ${{(inputs.trigger-event == 'push' || startsWith(github.event.ref, 'refs/tags/')) && 'pytorchbot-env' || ''}}
8584
container:
8685
image: ${{ matrix.container_image }}
8786
options: ${{ matrix.gpu_arch_type == 'cuda' && '--gpus all' || ' ' }}
@@ -108,6 +107,7 @@ jobs:
108107
ref: ${{ inputs.ref }}
109108
setup-miniconda: true
110109
python-version: ${{ env.PYTHON_VERSION }}
110+
cuda-version: ${{ env.CU_VERSION }}
111111
- name: Combine Env Var and Build Env Files
112112
if: ${{ inputs.env-var-script != '' }}
113113
working-directory: ${{ inputs.repository }}
@@ -150,7 +150,6 @@ jobs:
150150
--python "${PYTHON_VERSION}" \
151151
--output-folder distr/ \
152152
"${CONDA_PACKAGE_DIRECTORY}"
153-
154153
- name: Upload artifact to GitHub
155154
continue-on-error: true
156155
uses: actions/upload-artifact@v3
@@ -218,30 +217,20 @@ jobs:
218217
${CONDA_RUN_SMOKE} python "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT}"
219218
fi
220219
conda env remove -p "${CONDA_ENV_SMOKE}"
221-
- name: Upload package to conda
222-
if: ${{ (inputs.trigger-event == 'push' && env.CHANNEL != 'test') || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
223-
working-directory: ${{ inputs.repository }}
224-
env:
225-
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
226-
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
227-
run: |
228-
if [[ "${CHANNEL}" = "nightly" ]]; then
229-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN}"
230-
else
231-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN_TEST}"
232-
fi
233220
234-
set -euxo pipefail
235-
# shellcheck disable=SC1090
236-
source "${BUILD_ENV_FILE}"
237-
${CONDA_RUN} conda install --yes --quiet anaconda-client
238-
${CONDA_RUN} anaconda \
239-
-t "${CONDA_TOKEN}" \
240-
upload distr/linux-64/*.tar.bz2 \
241-
-u "pytorch-${CHANNEL}" \
242-
--label main \
243-
--no-progress \
244-
--force
221+
upload:
222+
needs: build
223+
uses: ./.github/workflows/_binary_conda_upload.yml
224+
with:
225+
repository: ${{ inputs.repository }}
226+
ref: ${{ inputs.ref }}
227+
test-infra-repository: ${{ inputs.test-infra-repository }}
228+
test-infra-ref: ${{ inputs.test-infra-ref }}
229+
build-matrix: ${{ inputs.build-matrix }}
230+
trigger-event: ${{ inputs.trigger-event }}
231+
secrets:
232+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
233+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
245234

246235
concurrency:
247236
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}

.github/workflows/build_conda_macos.yml

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ jobs:
8585
CU_VERSION: cpu
8686
name: ${{ matrix.build_name }}
8787
runs-on: ${{ inputs.runner-type }}
88-
environment: ${{(inputs.trigger-event == 'push' || startsWith(github.event.ref, 'refs/tags/')) && 'pytorchbot-env' || ''}}
8988
# If a build is taking longer than 60 minutes on these runners we need
9089
# to have a conversation
9190
timeout-minutes: 60
@@ -118,6 +117,7 @@ jobs:
118117
ref: ${{ inputs.ref }}
119118
setup-miniconda: false
120119
python-version: ${{ env.PYTHON_VERSION }}
120+
cuda-version: ${{ env.CU_VERSION }}
121121
- name: Combine Env Var and Build Env Files
122122
if: ${{ inputs.env-var-script != '' }}
123123
working-directory: ${{ inputs.repository }}
@@ -154,7 +154,6 @@ jobs:
154154
--python "${PYTHON_VERSION}" \
155155
--output-folder distr/ \
156156
"${CONDA_PACKAGE_DIRECTORY}"
157-
158157
- name: Upload artifact to GitHub
159158
continue-on-error: true
160159
uses: actions/upload-artifact@v3
@@ -222,42 +221,25 @@ jobs:
222221
223222
export PATH=${OLD_PATH}
224223
conda env remove -p "${CONDA_ENV_SMOKE}"
225-
- name: Upload package to conda
226-
if: ${{ (inputs.trigger-event == 'push' && env.CHANNEL != 'test') || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
227-
working-directory: ${{ inputs.repository }}
228-
env:
229-
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
230-
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
231-
run: |
232-
if [[ "${CHANNEL}" = "nightly" ]]; then
233-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN}"
234-
else
235-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN_TEST}"
236-
fi
237-
238-
set -euxo pipefail
239-
# shellcheck disable=SC1090
240-
source "${BUILD_ENV_FILE}"
241-
242-
${CONDA_RUN} conda install --yes --quiet anaconda-client
243-
arch_name="$(uname -m)"
244-
if [ "${arch_name}" = "arm64" ]; then
245-
export ARCH_NAME="osx-arm64"
246-
else
247-
export ARCH_NAME="osx-64"
248-
fi
249-
${CONDA_RUN} anaconda \
250-
-t "${CONDA_TOKEN}" \
251-
upload "distr/${ARCH_NAME}"/*.tar.bz2 \
252-
-u "pytorch-${CHANNEL}" \
253-
--label main \
254-
--no-progress \
255-
--force
256224
- name: Clean up disk space
257225
if: always()
258226
continue-on-error: true
259227
uses: ./test-infra/.github/actions/check-disk-space
260228

229+
upload:
230+
needs: build
231+
uses: ./.github/workflows/_binary_conda_upload.yml
232+
with:
233+
repository: ${{ inputs.repository }}
234+
ref: ${{ inputs.ref }}
235+
test-infra-repository: ${{ inputs.test-infra-repository }}
236+
test-infra-ref: ${{ inputs.test-infra-ref }}
237+
build-matrix: ${{ inputs.build-matrix }}
238+
trigger-event: ${{ inputs.trigger-event }}
239+
secrets:
240+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
241+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
242+
261243
concurrency:
262244
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}
263245
cancel-in-progress: true

.github/workflows/build_conda_windows.yml

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ jobs:
8181
CU_VERSION: ${{ matrix.desired_cuda }}
8282
name: ${{ matrix.build_name }}
8383
runs-on: ${{ matrix.validation_runner }}
84-
environment: ${{(inputs.trigger-event == 'push' || startsWith(github.event.ref, 'refs/tags/')) && 'pytorchbot-env' || ''}}
8584
defaults:
8685
run:
8786
shell: bash -l {0}
@@ -117,6 +116,7 @@ jobs:
117116
ref: ${{ inputs.ref }}
118117
setup-miniconda: false
119118
python-version: ${{ env.PYTHON_VERSION }}
119+
cuda-version: ${{ env.CU_VERSION }}
120120
- name: Run Pre-Script with Caching
121121
if: ${{ inputs.pre-script != '' }}
122122
uses: ./test-infra/.github/actions/run-script-with-cache
@@ -239,30 +239,20 @@ jobs:
239239
${CONDA_RUN_SMOKE} python "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT}"
240240
fi
241241
conda env remove -p "${CONDA_ENV_SMOKE}"
242-
- name: Upload package to conda
243-
if: ${{ (inputs.trigger-event == 'push' && env.CHANNEL != 'test') || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
244-
working-directory: ${{ inputs.repository }}
245-
env:
246-
PACKAGE_NAME: ${{ inputs.package-name }}
247-
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
248-
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
249-
run: |
250-
if [[ "${CHANNEL}" = "nightly" ]]; then
251-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN}"
252-
else
253-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN_TEST}"
254-
fi
255242
256-
set -euxo pipefail
257-
source "${BUILD_ENV_FILE}"
258-
${CONDA_RUN} conda install --yes --quiet anaconda-client
259-
${CONDA_RUN} anaconda \
260-
-t "${CONDA_TOKEN}" \
261-
upload "distr/win-64/${PACKAGE_NAME}*.tar.bz2" \
262-
-u "pytorch-${CHANNEL}" \
263-
--label main \
264-
--no-progress \
265-
--force
243+
upload:
244+
needs: build
245+
uses: ./.github/workflows/_binary_conda_upload.yml
246+
with:
247+
repository: ${{ inputs.repository }}
248+
ref: ${{ inputs.ref }}
249+
test-infra-repository: ${{ inputs.test-infra-repository }}
250+
test-infra-ref: ${{ inputs.test-infra-ref }}
251+
build-matrix: ${{ inputs.build-matrix }}
252+
trigger-event: ${{ inputs.trigger-event }}
253+
secrets:
254+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
255+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
266256

267257
concurrency:
268258
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}

0 commit comments

Comments
 (0)