-
Notifications
You must be signed in to change notification settings - Fork 0
226 lines (196 loc) · 7.61 KB
/
tests.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
name: Tests
on:
# https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#push
push:
branches:
- main
# https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#pull_request
pull_request:
# https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads#workflow_dispatch
workflow_dispatch:
# no payload
schedule:
# https://crontab.guru/#37_18_*_*_*
- cron: 37 18 * * *
concurrency:
# Concurrency group that uses the workflow name and PR number if available
# or commit SHA as a fallback. If a new build is triggered under that
# concurrency group while a previous build is running it will be canceled.
# Repeated pushes to a PR will cancel all previous builds, while multiple
# merges to main will not cancel.
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
env:
# https://conda.github.io/conda-libmamba-solver/user-guide/configuration/#advanced-options
CONDA_LIBMAMBA_SOLVER_NO_CHANNELS_FROM_INSTALLED: true
jobs:
# detect whether any code changes are included in this PR
changes:
runs-on: ubuntu-latest
permissions:
# necessary to detect changes
# https://github.com/dorny/paths-filter#supported-workflows
pull-requests: read
contents: read
outputs:
code: ${{ steps.filter.outputs.code }}
steps:
- name: Checkout Source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
# dorny/paths-filter needs git clone for non-PR events
# https://github.com/dorny/paths-filter#supported-workflows
if: github.event_name != 'pull_request'
- name: Filter Changes
uses: dorny/paths-filter@de90cc6fb38fc0963ad72b210f1f284cd68cea36 # v3.0.2
id: filter
with:
filters: |
code:
- 'conda_anaconda_telemetry/**'
- 'tests/**'
- '*.py'
- 'conda.recipe/**'
- '.github/workflows/tests.yml'
tests:
needs: changes
if: needs.changes.outputs.code == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
python-version: ["3.9", "3.12"]
os: ["macos-latest", "ubuntu-latest", "windows-latest"]
steps:
# Clean checkout of specific git ref needed for package metadata version
# which needs env vars GIT_DESCRIBE_TAG and GIT_BUILD_STR:
- name: Checkout Source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.ref }}
clean: true
fetch-depth: 0
- name: Hash + Timestamp
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-$(date -u "+%Y%m")" >> $GITHUB_ENV
- name: Cache Conda
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ~/conda_pkgs_dir
key: cache-${{ env.HASH }}
- uses: conda-incubator/setup-miniconda@d2e6a045a86077fb6cad6f5adf368e9076ddaa8d # v3
name: Setup Miniconda
with:
python-version: ${{ matrix.python-version }}
channels: defaults
run-post: false # skip post cleanup
- name: Conda Install
run: >
conda install
--name test
--yes
--file tests/requirements.txt
--file tests/requirements-ci.txt
python=${{ matrix.python-version }}
# TODO: how can we remove this step?
- name: Install Self
run: conda run --name test pip install --no-build-isolation --no-deps e .
- name: Conda Info
run: conda info --verbose
- name: Conda Config
run: conda config --show-sources
- name: Conda List
run: conda list --show-channel-urls --name test
- name: Run Tests
# Windows is sensitive to long paths, using `--basetemp=${{ runner.temp }} to
# keep the test directories shorter
run: >
conda run --name test
pytest
--doctest-modules
--cov=conda_anaconda_telemetry
--basetemp=${{ runner.temp }}
-n auto
build:
needs: [tests]
# only build canary build if
# - prior steps succeeded,
# - this is the main branch
if: >-
success()
&& !github.event.repository.fork
strategy:
matrix:
include:
- runner: ubuntu-latest
subdir: noarch
python-version: 3.12
runs-on: ${{ matrix.runner }}
steps:
# Clean checkout of specific git ref needed for package metadata version
# which needs env vars GIT_DESCRIBE_TAG and GIT_BUILD_STR:
- name: Checkout Source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.ref }}
clean: true
fetch-depth: 0
- name: Hash + Timestamp
run: echo "HASH=${{ runner.os }}-${{ runner.arch }}-Py${{ matrix.python-version }}-$(date -u "+%Y%m")" >> $GITHUB_ENV
- name: Cache Conda
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a # v4.1.2
with:
path: ~/conda_pkgs_dir
key: cache-${{ env.HASH }}
- uses: conda-incubator/setup-miniconda@d2e6a045a86077fb6cad6f5adf368e9076ddaa8d # v3
name: Setup Miniconda
with:
python-version: ${{ matrix.python-version }}
channels: defaults
run-post: false # skip post cleanup
# conda not preinstalled in arm64 runners
miniconda-version: ${{ runner.arch == 'ARM64' && 'latest' || null }}
architecture: ${{ runner.arch }}
- name: Build package
# make sure we don't run on forks
if: github.repository_owner == 'anaconda'
id: build
shell: bash -l {0}
env:
# Run conda-build in isolated activation to properly package the software
_CONDA_BUILD_ISOLATED_ACTIVATION: 1
run: |
set -euo pipefail
conda activate test
conda install --yes --quiet conda-build anaconda-client
# git needs to be installed after conda-build
# see https://github.com/conda/conda/issues/11758
# see https://github.com/conda/actions/pull/47
conda install --yes --quiet git
conda info
conda config --show-sources
conda list
conda build --croot=${{ runner.temp }}/pkgs --override-channels -c conda-canary/label/dev -c defaults recipe
- name: Set variables
id: set-vars
run: |
echo "PACKAGE_LABEL=${{ github.ref_name == 'main' && 'dev' || format('{0}-{1}', github.event.repository.name, github.ref_name) }}" >> $GITHUB_ENV
echo "PACKAGE_NAME=${{ github.event.repository.name }}" >> $GITHUB_ENV
- name: Upload package
# make sure we don't run in branches
if: github.ref_name == 'main'
id: upload
shell: bash -l {0}
run: |
echo "::group::Uploading package"
anaconda \
--token="${{ secrets.ANACONDA_ORG_TOKEN }}" \
upload \
--force \
--register \
--no-progress \
--user="distribution-plugins" \
--label="$PACKAGE_LABEL" \
${{ runner.temp }}/pkgs/${{ matrix.subdir }}/$PACKAGE_NAME-*.tar.bz2
echo "Uploaded the following files:"
basename -a ./pkgs/${{ matrix.subdir }}/$PACKAGE_NAME-*.tar.bz2
echo "::endgroup::"
echo "Use this command to try out the build:"
echo "conda install -c distribution-plugins/label/$PACKAGE_LABEL $PACKAGE_NAME"