Run all the autotests #192
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Run all the autotests | |
on: | |
pull_request: | |
push: | |
schedule: | |
- cron: '0 3 * * *' | |
jobs: | |
add_header: | |
if: github.repository_owner == 'rucio' || github.event_name != 'schedule' | |
name: Add header lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
with: | |
# We need the history to determine the file creation date. | |
fetch-depth: 0 | |
- name: Check headers | |
shell: bash | |
run: | | |
python3 tools/add_header --dry-run --disable-progress-bar | |
python_annotations: | |
if: | | |
!startsWith(github.ref_name, 'release') | |
&& !startsWith(github.base_ref, 'release') | |
&& github.event_name != 'schedule' | |
&& github.ref_type != 'tag' | |
name: Check Python Type Annotations | |
runs-on: ubuntu-latest | |
env: | |
UPDATED_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE: ../updated_type_annotation_report.txt | |
INITIAL_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE: ../initial_type_annotation_report.txt | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Count current number of missing type annotations | |
id: count_updated | |
shell: bash | |
run: | | |
pip install flake8 flake8-annotations | |
source tools/count_missing_type_annotations_utils.sh | |
create_missing_python_type_annotations_report ${{ env.UPDATED_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }} | |
echo "The current number of missing python type annotations: $(wc -l < ${{ env.UPDATED_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }})" | |
- name: Checkout ancestor commit with rucio/master | |
uses: ./.github/actions/checkout_ancestor_commit | |
with: | |
paths_to_copy: | | |
tools/count_missing_type_annotations.sh | |
tools/count_missing_type_annotations_utils.sh | |
- name: Count initial number of missing type annotations | |
id: count_initial | |
shell: bash | |
run: | | |
source tools/count_missing_type_annotations_utils.sh | |
create_missing_python_type_annotations_report ${{ env.INITIAL_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }} | |
echo "The initial number of missing python type annotations: $(wc -l < ${{ env.INITIAL_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }})" | |
- name: Diff of missing annotations | |
shell: bash | |
run: | | |
diff ${{ env.INITIAL_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }} ${{ env.UPDATED_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }} || true | |
- name: Compare numbers of missing type annotations | |
shell: bash | |
run: | | |
INITIAL_NUMBER_OF_MISSING_TYPE_ANNOTATIONS=$(wc -l < ${{ env.INITIAL_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }}) | |
UPDATED_NUMBER_OF_MISSING_TYPE_ANNOTATIONS=$(wc -l < ${{ env.UPDATED_PYTHON_TYPE_ANNOTATIONS_REPORT_FILE }}) | |
echo "The initial number of missing type annotations is: $INITIAL_NUMBER_OF_MISSING_TYPE_ANNOTATIONS" | |
echo "The updated number of missing type annotations is: $UPDATED_NUMBER_OF_MISSING_TYPE_ANNOTATIONS" | |
if [ $UPDATED_NUMBER_OF_MISSING_TYPE_ANNOTATIONS -gt $INITIAL_NUMBER_OF_MISSING_TYPE_ANNOTATIONS ]; then | |
echo "The number of missing python type annotations should never increase! This way we ensure that new functions are type annotated." | |
echo "Look into the first lines of 'Diff of missing type annotations' to get a reference point what function might be missing type annotations." | |
echo "**TL;DR** New code has to be type annotated, old code should be migrated. Look into Best Practices[1] for specific instructions on how to use it in our repository." | |
echo "Look into the Rucio Type Annotations Guide[2] to get some help on why, what and how to add type annotations." | |
echo | |
echo "[1] https://codimd.web.cern.ch/6-SU3cTpQSWRK6FHkM7mAA#Best-Practices" | |
echo "[2] https://codimd.web.cern.ch/6-SU3cTpQSWRK6FHkM7mAA#" | |
exit 1 | |
fi | |
python_pyright: | |
if: | | |
!startsWith(github.ref_name, 'release') | |
&& !startsWith(github.base_ref, 'release') | |
&& github.event_name != 'schedule' | |
&& github.ref_type != 'tag' | |
name: Python type check (Pyright) | |
runs-on: ubuntu-latest | |
env: | |
PYRIGHT_CURRENT_REPORT: ../pyright_current_report.json | |
PYRIGHT_ANCESTOR_REPORT: ../pyright_ancestor_report.json | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Install dependencies | |
run: | | |
sudo apt-get update && sudo apt-get install -y npm libkrb5-dev libxmlsec1-dev | |
npm install --global pyright | |
python -m pip --no-cache-dir install --upgrade -r requirements.txt | |
- name: Make pyright report of current commit | |
run: | | |
tools/run_pyright.sh generate ${{ env.PYRIGHT_CURRENT_REPORT }} | |
- name: Show the current Pyright report | |
run: cat ${{ env.PYRIGHT_CURRENT_REPORT }} | |
- name: Checkout ancestor commit with rucio/master | |
uses: ./.github/actions/checkout_ancestor_commit | |
with: | |
paths_to_copy: | | |
pyrightconfig.json | |
tools/run_pyright.sh | |
tools/run_pyright/ | |
- name: Make pyright report of ancestor commit | |
run: | | |
tools/run_pyright.sh generate ${{ env.PYRIGHT_ANCESTOR_REPORT }} | |
- name: Show the ancestor Pyright report | |
run: cat ${{ env.PYRIGHT_ANCESTOR_REPORT }} | |
- name: Compare reports | |
run: | | |
tools/run_pyright.sh compare --Werror \ | |
${{ env.PYRIGHT_ANCESTOR_REPORT }} \ | |
${{ env.PYRIGHT_CURRENT_REPORT }} | |
setup: | |
if: github.repository_owner == 'rucio' || github.event_name != 'schedule' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Update pip | |
run: python3 -m pip install -U pip setuptools | |
- name: Install python requirements for matrix_parser.py | |
run: python3 -m pip install -U PyYAML | |
- name: Identify branch | |
id: branch | |
run: python3 -c 'from os import environ as env; print("::set-output name=branch::" + (env.get("GITHUB_BASE_REF", None) if env.get("GITHUB_BASE_REF", None) else env.get("GITHUB_REF", "master")))' | |
- name: Identify Matrix | |
id: matrix | |
run: | | |
EVENT="${{ github.event_name }}" | |
if [ $EVENT != 'schedule' ]; then | |
echo "::set-output name=matrix::$(./tools/test/matrix_parser.py < ./etc/docker/test/matrix.yml)" | |
else | |
echo "::set-output name=matrix::$(./tools/test/matrix_parser.py < ./etc/docker/test/matrix_nightly.yml)" | |
fi | |
outputs: | |
branch: ${{ steps.branch.outputs.branch }} | |
matrix: ${{ steps.matrix.outputs.matrix }} | |
test: | |
needs: setup | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
cfg: ${{ fromJson(needs.setup.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Build images | |
id: images | |
shell: bash | |
run: | | |
docker login https://ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} | |
i=0; until [ "$i" -ge 3 ]; do | |
IMAGES=$(echo '${{ toJson(matrix.cfg) }}' | ./tools/test/build_images.py \ | |
--cache-repo ghcr.io/${{ github.repository }} \ | |
--branch "${{ needs.setup.outputs.branch }}" ./etc/docker/test || echo "") | |
if [[ -n $IMAGES ]]; then break; | |
else | |
i=$((i+1)); sleep 5; | |
echo "::warning::Building images failed, retrying…" | |
fi | |
done | |
docker logout https://ghcr.io | |
if [[ -z "$IMAGES" ]]; then echo "::error::Building images failed ultimately"; exit 1; fi | |
echo "::set-output name=images::$IMAGES" | |
- name: Run test with cfg | |
run: 'echo ''{"matrix": ${{ toJson(matrix.cfg) }}, "images": ${{ steps.images.outputs.images }} }'' | ./tools/test/run_tests.py' | |
release-patch-setup: | |
if: | | |
github.event_name == 'pull_request' && !startsWith(github.event.pull_request.base.ref, 'release') && !startsWith(github.event.pull_request.head.ref, 'feature') | |
&& (github.repository_owner == 'rucio' || github.event_name != 'schedule') | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Update pip | |
run: python3 -m pip install -U pip setuptools | |
- name: Install python requirements for matrix_parser.py | |
run: python3 -m pip install -U sh PyYAML | |
- name: Grab latest release branch | |
id: grabrelease | |
run: echo "::set-output name=release_branch::$(echo "${{ github.event.repository.branches_url }}" | ./tools/github/workflow/grabrelease.py)" | |
- name: Fetch pull request commit range | |
id: prcommits | |
run: echo "::set-output name=source_commits::$(echo "${{ github.event.pull_request.commits_url }}" | ./tools/github/workflow/prcommits.py)" | |
- name: Test cherry-picking pull request changes | |
run: | | |
echo '{ | |
"source_remote_name": "${{ github.actor }}", | |
"source_remote": "${{ github.event.pull_request.head.repo.full_name }}", | |
"source_commits": "${{ steps.prcommits.outputs.source_commits }}", | |
"target_remote": "${{ github.event.pull_request.base.repo.full_name }}", | |
"target_branch": "${{ steps.grabrelease.outputs.release_branch }}" | |
}' | ./tools/github/workflow/mergetest.py | |
- name: Identify Matrix | |
id: matrix | |
run: echo "::set-output name=matrix::$(./tools/test/matrix_parser.py < ./etc/docker/test/matrix.yml)" | |
outputs: | |
release_branch: ${{ steps.grabrelease.outputs.release_branch }} | |
source_commits: ${{ steps.prcommits.outputs.source_commits }} | |
matrix: ${{ steps.matrix.outputs.matrix }} | |
release-patch-test: | |
needs: release-patch-setup | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
cfg: ${{ fromJson(needs.release-patch-setup.outputs.matrix) }} | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Update pip | |
run: python3 -m pip install -U pip setuptools | |
- name: Install python requirements for mergetest.py | |
run: python3 -m pip install -U sh | |
- name: Cherry-pick pull request changes | |
run: | | |
echo '{ | |
"source_remote_name": "${{ github.actor }}", | |
"source_remote": "${{ github.event.pull_request.head.repo.full_name }}", | |
"source_commits": "${{ needs.release-patch-setup.outputs.source_commits }}", | |
"target_remote": "${{ github.event.pull_request.base.repo.full_name }}", | |
"target_branch": "${{ needs.release-patch-setup.outputs.release_branch }}" | |
}' | ./tools/github/workflow/mergetest.py | |
- name: Build images | |
id: images | |
shell: bash | |
run: | | |
docker login https://ghcr.io -u ${{ github.actor }} -p ${{ secrets.GITHUB_TOKEN }} | |
i=0; until [ "$i" -ge 3 ]; do | |
IMAGES=$(echo '${{ toJson(matrix.cfg) }}' | DOCKER_BUILDKIT=1 ./tools/test/build_images.py \ | |
--cache-repo ghcr.io/${{ github.repository }} \ | |
--branch "${{ needs.release-patch-setup.outputs.release_branch }}" ./etc/docker/test || echo "") | |
if [[ -n $IMAGES ]]; then break; | |
else | |
i=$((i+1)); sleep 5; | |
echo "::warning::Building images failed, retrying…" | |
fi | |
done | |
docker logout https://ghcr.io | |
if [[ -z "$IMAGES" ]]; then echo "::error::Building images failed ultimately"; exit 1; fi | |
echo "::set-output name=images::$IMAGES" | |
- name: Run test with cfg | |
run: 'echo ''{"matrix": ${{ toJson(matrix.cfg) }}, "images": ${{ steps.images.outputs.images }} }'' | ./tools/test/run_tests.py' |