Skip to content

Commit

Permalink
Merge pull request #2977 from regro/reuse
Browse files Browse the repository at this point in the history
feat: reusable workflow for tests
  • Loading branch information
beckermr authored Sep 2, 2024
2 parents 3a922fc + 368868d commit 30c2aae
Show file tree
Hide file tree
Showing 3 changed files with 14,022 additions and 14,506 deletions.
184 changes: 184 additions & 0 deletions .github/workflows/tests-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
name: tests-reusable

on:
workflow_call:
secrets:
CODECOV_TOKEN:
required: true

env:
PY_COLORS: "1"
IMAGE_NAME: conda-forge-tick

jobs:
tests:
name: tests
runs-on: "ubuntu-latest"
permissions:
actions: write # for deleting cache entries
contents: read
strategy:
# continue running the tests even if one of the groups fails
fail-fast: false
matrix:
# if change the number of groups here, also change it next to --splits below
group: [1, 2]
defaults:
run:
shell: bash -leo pipefail {0}

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
repository: "regro/cf-scripts"

- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-file: conda-lock.yml
environment-name: cf-scripts
condarc-file: autotick-bot/condarc

- name: configure conda and install code
run: |
pip install --no-deps --no-build-isolation -e .
- name: test versions
run: |
cd ..
python -c "import conda_forge_tick; assert conda_forge_tick.__version__ != '0.0.0'"
cd -
pip uninstall conda-forge-tick --yes
rm -rf dist/*
python -m build --sdist . --outdir dist
pip install --no-deps --no-build-isolation dist/*.tar.gz
cd ..
python -c "import conda_forge_tick; assert conda_forge_tick.__version__ != '0.0.0'"
cd -
pip uninstall conda-forge-tick --yes
python -m pip install -v --no-deps --no-build-isolation -e .
- name: start MongoDB
uses: MongoCamp/mongodb-github-action@e76ad215d47c31a99b4b0b1fde05f6cd1185df1a # e76ad215d47c31a99b4b0b1fde05f6cd1185df1a
with:
mongodb-version: "latest"

- name: test mongodb is OK
run: |
python -c "from pymongo import MongoClient; import os; print(MongoClient(os.environ['MONGODB_CONNECTION_STRING']))"
env:
MONGODB_CONNECTION_STRING: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000"

- name: set up docker buildx
uses: docker/setup-buildx-action@v3

- name: build docker image
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6
with:
context: .
push: false
load: true
tags: ${{ env.IMAGE_NAME }}:test

- name: restore test durations
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: .test_durations
key: test-durations-${{ github.ref }}-${{ github.sha }}
restore-keys: |
test-durations-${{ github.ref }}-
test-durations-
- name: run pytest
run: |
export TEST_BOT_TOKEN_VAL=unpassword
export BOT_TOKEN=${TEST_BOT_TOKEN_VAL}
# note: we do not use pytest-xdist (-n auto) here for now because they interfere with hiding the
# MONGODB_CONNECTION_STRING sensitive environment variable
if [[ -f .test_durations ]]; then
cp .test_durations .test_durations.${{ matrix.group }}
fi
pytest \
-v \
--splits 2 --group ${{ matrix.group }} \
--store-durations \
--durations-path=.test_durations.${{ matrix.group }} \
--randomly-seed=${{ github.run_id }} \
--splitting-algorithm least_duration \
--cov=conda_forge_tick \
--cov=tests \
--cov-config=.coveragerc \
--cov-report=term-missing \
--cov-report=xml \
--durations=10 \
--ignore=tests/model \
tests
env:
MONGODB_CONNECTION_STRING: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000"
RUN_URL: ""

- name: upload test durations
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
with:
name: test-durations-${{ matrix.group }}
path: .test_durations.${{ matrix.group }}
include-hidden-files: true

- name: upload coverage
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
with:
name: coverage-${{ matrix.group }}
path: .coverage
include-hidden-files: true

test-coverage-and-durations:
name: test-coverage-and-durations
needs: tests
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -leo pipefail {0}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
with:
repository: "regro/cf-scripts"

- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-file: conda-lock.yml
environment-name: cf-scripts
condarc-file: autotick-bot/condarc

- name: download coverage artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: coverage-*

- name: combine coverage
run: |
coverage combine coverage-*/.coverage*
coverage xml
- name: upload codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: cache test durations
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: .test_durations
key: test-durations-${{ github.ref }}-${{ github.sha }}
restore-keys: |
test-durations-${{ github.ref }}-
test-durations-
- name: download test duration artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: test-durations-*

- name: combine test durations
run: |
jq '. + input' test-durations-*/.test_durations.* > .test_durations
173 changes: 3 additions & 170 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,179 +7,12 @@ on:
pull_request: null
merge_group: null

env:
PY_COLORS: "1"
IMAGE_NAME: conda-forge-tick

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
tests:
name: tests
runs-on: "ubuntu-latest"
permissions:
actions: write # for deleting cache entries
contents: read
strategy:
# continue running the tests even if one of the groups fails
fail-fast: false
matrix:
# if change the number of groups here, also change it next to --splits below
group: [1, 2]
defaults:
run:
shell: bash -leo pipefail {0}

steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-file: conda-lock.yml
environment-name: cf-scripts
condarc-file: autotick-bot/condarc

- name: configure conda and install code
run: |
pip install --no-deps --no-build-isolation -e .
- name: test versions
run: |
cd ..
python -c "import conda_forge_tick; assert conda_forge_tick.__version__ != '0.0.0'"
cd -
pip uninstall conda-forge-tick --yes
rm -rf dist/*
python -m build --sdist . --outdir dist
pip install --no-deps --no-build-isolation dist/*.tar.gz
cd ..
python -c "import conda_forge_tick; assert conda_forge_tick.__version__ != '0.0.0'"
cd -
pip uninstall conda-forge-tick --yes
python -m pip install -v --no-deps --no-build-isolation -e .
- name: start MongoDB
uses: MongoCamp/mongodb-github-action@e76ad215d47c31a99b4b0b1fde05f6cd1185df1a # e76ad215d47c31a99b4b0b1fde05f6cd1185df1a
with:
mongodb-version: "latest"

- name: test mongodb is OK
run: |
python -c "from pymongo import MongoClient; import os; print(MongoClient(os.environ['MONGODB_CONNECTION_STRING']))"
env:
MONGODB_CONNECTION_STRING: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000"

- name: set up docker buildx
uses: docker/setup-buildx-action@v3

- name: build docker image
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6
with:
context: .
push: false
load: true
tags: ${{ env.IMAGE_NAME }}:test

- name: restore test durations
uses: actions/cache/restore@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: .test_durations
key: test-durations-${{ github.ref }}-${{ github.sha }}
restore-keys: |
test-durations-${{ github.ref }}-
test-durations-
- name: run pytest
run: |
export TEST_BOT_TOKEN_VAL=unpassword
export BOT_TOKEN=${TEST_BOT_TOKEN_VAL}
# note: we do not use pytest-xdist (-n auto) here for now because they interfere with hiding the
# MONGODB_CONNECTION_STRING sensitive environment variable
if [[ -f .test_durations ]]; then
cp .test_durations .test_durations.${{ matrix.group }}
fi
pytest \
-v \
--splits 2 --group ${{ matrix.group }} \
--store-durations \
--durations-path=.test_durations.${{ matrix.group }} \
--randomly-seed=${{ github.run_id }} \
--splitting-algorithm least_duration \
--cov=conda_forge_tick \
--cov=tests \
--cov-config=.coveragerc \
--cov-report=term-missing \
--cov-report=xml \
--durations=10 \
--ignore=tests/model \
tests
env:
MONGODB_CONNECTION_STRING: "mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000"
RUN_URL: ""

- name: upload test durations
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
with:
name: test-durations-${{ matrix.group }}
path: .test_durations.${{ matrix.group }}
include-hidden-files: true

- name: upload coverage
uses: actions/upload-artifact@50769540e7f4bd5e21e526ee35c689e35e0d6874 # v4
with:
name: coverage-${{ matrix.group }}
path: .coverage
include-hidden-files: true

test-coverage-and-durations:
name: test-coverage-and-durations
needs: tests
runs-on: "ubuntu-latest"
defaults:
run:
shell: bash -leo pipefail {0}
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4

- uses: mamba-org/setup-micromamba@f8b8a1e23a26f60a44c853292711bacfd3eac822 # v1
with:
environment-file: conda-lock.yml
environment-name: cf-scripts
condarc-file: autotick-bot/condarc

- name: download coverage artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: coverage-*

- name: combine coverage
run: |
coverage combine coverage-*/.coverage*
coverage xml
- name: upload codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4
with:
token: ${{ secrets.CODECOV_TOKEN }}

- name: cache test durations
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4
with:
path: .test_durations
key: test-durations-${{ github.ref }}-${{ github.sha }}
restore-keys: |
test-durations-${{ github.ref }}-
test-durations-
- name: download test duration artifacts
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
pattern: test-durations-*

- name: combine test durations
run: |
jq '. + input' test-durations-*/.test_durations.* > .test_durations
uses: ./.github/workflows/tests-reusable.yml
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Loading

0 comments on commit 30c2aae

Please sign in to comment.