Skip to content

Commit 6128c1a

Browse files
committed
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 af0bf7f commit 6128c1a

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' || ' ' }}
@@ -102,6 +101,7 @@ jobs:
102101
ref: ${{ inputs.ref }}
103102
setup-miniconda: true
104103
python-version: ${{ env.PYTHON_VERSION }}
104+
cuda-version: ${{ env.CU_VERSION }}
105105
- name: Combine Env Var and Build Env Files
106106
if: ${{ inputs.env-var-script != '' }}
107107
working-directory: ${{ inputs.repository }}
@@ -144,7 +144,6 @@ jobs:
144144
--python "${PYTHON_VERSION}" \
145145
--output-folder distr/ \
146146
"${CONDA_PACKAGE_DIRECTORY}"
147-
148147
- name: Upload artifact to GitHub
149148
continue-on-error: true
150149
uses: actions/upload-artifact@v3
@@ -207,30 +206,20 @@ jobs:
207206
${CONDA_RUN_SMOKE} python "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT}"
208207
fi
209208
conda env remove -p "${CONDA_ENV_SMOKE}"
210-
- name: Upload package to conda
211-
if: ${{ (inputs.trigger-event == 'push' && env.CHANNEL != 'test') || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
212-
working-directory: ${{ inputs.repository }}
213-
env:
214-
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
215-
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
216-
run: |
217-
if [[ "${CHANNEL}" = "nightly" ]]; then
218-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN}"
219-
else
220-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN_TEST}"
221-
fi
222209
223-
set -euxo pipefail
224-
# shellcheck disable=SC1090
225-
source "${BUILD_ENV_FILE}"
226-
${CONDA_RUN} conda install --yes --quiet anaconda-client
227-
${CONDA_RUN} anaconda \
228-
-t "${CONDA_TOKEN}" \
229-
upload distr/linux-64/*.tar.bz2 \
230-
-u "pytorch-${CHANNEL}" \
231-
--label main \
232-
--no-progress \
233-
--force
210+
upload:
211+
needs: build
212+
uses: ./.github/workflows/_binary_conda_upload.yml
213+
with:
214+
repository: ${{ inputs.repository }}
215+
ref: ${{ inputs.ref }}
216+
test-infra-repository: ${{ inputs.test-infra-repository }}
217+
test-infra-ref: ${{ inputs.test-infra-ref }}
218+
build-matrix: ${{ inputs.build-matrix }}
219+
trigger-event: ${{ inputs.trigger-event }}
220+
secrets:
221+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
222+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
234223

235224
concurrency:
236225
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
@@ -112,6 +111,7 @@ jobs:
112111
ref: ${{ inputs.ref }}
113112
setup-miniconda: false
114113
python-version: ${{ env.PYTHON_VERSION }}
114+
cuda-version: ${{ env.CU_VERSION }}
115115
- name: Combine Env Var and Build Env Files
116116
if: ${{ inputs.env-var-script != '' }}
117117
working-directory: ${{ inputs.repository }}
@@ -148,7 +148,6 @@ jobs:
148148
--python "${PYTHON_VERSION}" \
149149
--output-folder distr/ \
150150
"${CONDA_PACKAGE_DIRECTORY}"
151-
152151
- name: Upload artifact to GitHub
153152
continue-on-error: true
154153
uses: actions/upload-artifact@v3
@@ -211,42 +210,25 @@ jobs:
211210
212211
export PATH=${OLD_PATH}
213212
conda env remove -p "${CONDA_ENV_SMOKE}"
214-
- name: Upload package to conda
215-
if: ${{ (inputs.trigger-event == 'push' && env.CHANNEL != 'test') || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
216-
working-directory: ${{ inputs.repository }}
217-
env:
218-
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
219-
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
220-
run: |
221-
if [[ "${CHANNEL}" = "nightly" ]]; then
222-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN}"
223-
else
224-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN_TEST}"
225-
fi
226-
227-
set -euxo pipefail
228-
# shellcheck disable=SC1090
229-
source "${BUILD_ENV_FILE}"
230-
231-
${CONDA_RUN} conda install --yes --quiet anaconda-client
232-
arch_name="$(uname -m)"
233-
if [ "${arch_name}" = "arm64" ]; then
234-
export ARCH_NAME="osx-arm64"
235-
else
236-
export ARCH_NAME="osx-64"
237-
fi
238-
${CONDA_RUN} anaconda \
239-
-t "${CONDA_TOKEN}" \
240-
upload "distr/${ARCH_NAME}"/*.tar.bz2 \
241-
-u "pytorch-${CHANNEL}" \
242-
--label main \
243-
--no-progress \
244-
--force
245213
- name: Clean up disk space
246214
if: always()
247215
continue-on-error: true
248216
uses: ./test-infra/.github/actions/check-disk-space
249217

218+
upload:
219+
needs: build
220+
uses: ./.github/workflows/_binary_conda_upload.yml
221+
with:
222+
repository: ${{ inputs.repository }}
223+
ref: ${{ inputs.ref }}
224+
test-infra-repository: ${{ inputs.test-infra-repository }}
225+
test-infra-ref: ${{ inputs.test-infra-ref }}
226+
build-matrix: ${{ inputs.build-matrix }}
227+
trigger-event: ${{ inputs.trigger-event }}
228+
secrets:
229+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
230+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
231+
250232
concurrency:
251233
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}-${{ inputs.repository }}-${{ github.event_name == 'workflow_dispatch' }}
252234
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}
@@ -111,6 +110,7 @@ jobs:
111110
ref: ${{ inputs.ref }}
112111
setup-miniconda: false
113112
python-version: ${{ env.PYTHON_VERSION }}
113+
cuda-version: ${{ env.CU_VERSION }}
114114
- name: Run Pre-Script with Caching
115115
if: ${{ inputs.pre-script != '' }}
116116
uses: ./test-infra/.github/actions/run-script-with-cache
@@ -228,30 +228,20 @@ jobs:
228228
${CONDA_RUN_SMOKE} python "${{ inputs.repository }}/${SMOKE_TEST_SCRIPT}"
229229
fi
230230
conda env remove -p "${CONDA_ENV_SMOKE}"
231-
- name: Upload package to conda
232-
if: ${{ (inputs.trigger-event == 'push' && env.CHANNEL != 'test') || (env.CHANNEL == 'test' && startsWith(github.event.ref, 'refs/tags/')) }}
233-
working-directory: ${{ inputs.repository }}
234-
env:
235-
PACKAGE_NAME: ${{ inputs.package-name }}
236-
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
237-
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
238-
run: |
239-
if [[ "${CHANNEL}" = "nightly" ]]; then
240-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN}"
241-
else
242-
export CONDA_TOKEN="${CONDA_PYTORCHBOT_TOKEN_TEST}"
243-
fi
244231
245-
set -euxo pipefail
246-
source "${BUILD_ENV_FILE}"
247-
${CONDA_RUN} conda install --yes --quiet anaconda-client
248-
${CONDA_RUN} anaconda \
249-
-t "${CONDA_TOKEN}" \
250-
upload "distr/win-64/${PACKAGE_NAME}*.tar.bz2" \
251-
-u "pytorch-${CHANNEL}" \
252-
--label main \
253-
--no-progress \
254-
--force
232+
upload:
233+
needs: build
234+
uses: ./.github/workflows/_binary_conda_upload.yml
235+
with:
236+
repository: ${{ inputs.repository }}
237+
ref: ${{ inputs.ref }}
238+
test-infra-repository: ${{ inputs.test-infra-repository }}
239+
test-infra-ref: ${{ inputs.test-infra-ref }}
240+
build-matrix: ${{ inputs.build-matrix }}
241+
trigger-event: ${{ inputs.trigger-event }}
242+
secrets:
243+
CONDA_PYTORCHBOT_TOKEN: ${{ secrets.CONDA_PYTORCHBOT_TOKEN }}
244+
CONDA_PYTORCHBOT_TOKEN_TEST: ${{ secrets.CONDA_PYTORCHBOT_TOKEN_TEST }}
255245

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

0 commit comments

Comments
 (0)