Skip to content

Commit

Permalink
Reimplementation of bash functions in python
Browse files Browse the repository at this point in the history
This is the first step to move from the spaghetti bash code to a more
testable, maintainable and extensible python re-implementation.

TODO(kwk): Some bits from the functions.sh have been migrated but are
probable not used anywhere yet.

TODO(kwk): Remove functions.sh once the migration is complete and all
workflows use the new setup.
  • Loading branch information
kwk committed Mar 19, 2024
1 parent a499835 commit b98a33d
Show file tree
Hide file tree
Showing 34 changed files with 2,110 additions and 118 deletions.
138 changes: 25 additions & 113 deletions .github/workflows/check-todays-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
workflow_dispatch: {}

permissions:
# We need this in order to create or update broken snapshot issues
# We need this in order to create or update snapshot issues
issues: write

jobs:
Expand All @@ -21,21 +21,24 @@ jobs:
include:
- name: standalone
maintainer_handle: "tuliom"
copr_project_tpl: "@fedora-llvm-team/llvm-snapshots-incubator-YYYYMMDD"
copr_ownername: "@fedora-llvm-team"
copr_project_tpl: "llvm-snapshots-incubator-YYYYMMDD"
copr_monitor_tpl: "https://copr.fedorainfracloud.org/coprs/g/fedora-llvm-team/llvm-snapshots-incubator-YYYYMMDD/monitor/"
needs_llvm_snapshot_builder: true
packages: "llvm-snapshot-builder python-lit llvm clang lld compiler-rt libomp"
- name: big-merge
maintainer_handle: "kwk"
copr_project_tpl: "@fedora-llvm-team/llvm-snapshots-big-merge-YYYYMMDD"
copr_ownername: "@fedora-llvm-team"
copr_project_tpl: "llvm-snapshots-big-merge-YYYYMMDD"
copr_monitor_tpl: "https://copr.fedorainfracloud.org/coprs/g/fedora-llvm-team/llvm-snapshots-big-merge-YYYYMMDD/monitor/"
extra_script_file: "scripts/functions-big-merge.sh"
needs_llvm_snapshot_builder: false
chroot_pattern: '^(fedora-(rawhide|[0-9]+)|rhel-9-)'
packages: "llvm"
- name: bootstrap
maintainer_handle: "kwk"
copr_project_tpl: "@fedora-llvm-team/llvm-snapshots-bootstrap-YYYYMMDD"
copr_ownername: "@fedora-llvm-team"
copr_project_tpl: "llvm-snapshots-bootstrap-YYYYMMDD"
copr_monitor_tpl: "https://copr.fedorainfracloud.org/coprs/g/fedora-llvm-team/llvm-snapshots-bootstrap-YYYYMMDD/monitor/"
extra_script_file: "scripts/functions-bootstrap.sh"
needs_llvm_snapshot_builder: false
chroot_pattern: 'fedora-39-x86_64'
packages: "llvm"

runs-on: ubuntu-latest
container: fedora:39
Expand All @@ -55,115 +58,24 @@ jobs:
- uses: actions/checkout@v4

- name: "Variables and functions"
shell: bash -e {0}
run: |
source scripts/functions.sh
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }}
today=`date +%Y%m%d`
username=@fedora-llvm-team
echo "username=$username" >> $GITHUB_ENV
echo "today_yyyymmdd=$today" >> $GITHUB_ENV
echo "project_today=${{ matrix.copr_project_tpl }}" | sed "s/YYYYMMDD/$today/" >> $GITHUB_ENV
echo "monitor_url=${{ matrix.copr_monitor_tpl }}" | sed "s/YYYYMMDD/$today/" >> $GITHUB_ENV
- uses: ./.github/actions/prepare-python

- name: "Install GitHub’s official command line tool: gh"
shell: bash -e {0}
run: |
source scripts/functions.sh
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }}
install_gh_client
- name: "Check for good builds"
- name: "Check todays builds"
shell: bash -e {0}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
source scripts/functions.sh
[[ ! -z "${{ matrix.extra_script_file }}" ]] && source ${{ matrix.extra_script_file }}
if was_broken_snapshot_detected_today ${GITHUB_REPOSITORY} ${{ matrix.name }}; then
echo "We already filed an issue for broken snapshots today."
handle_error_causes \
${GITHUB_REPOSITORY} \
${{ matrix.name }} \
${{ matrix.maintainer_handle }} \
${{ env.project_today }}
exit 0;
fi
extra_args=""
if ! copr_project_exists ${{ env.project_today }}; then
echo "The copr project ${{ env.project_today }} does not exist (yet)."
exit 0;
if [[ ! -z "${{ matrix.chroot_pattern }}" ]]; then
extra_args="${extra_args} --chroot-pattern ${{matrix.chroot_pattern}}"
fi
if [ "${{ matrix.needs_llvm_snapshot_builder }}" == "true" ]; then
extra_packages=llvm-snapshot-builder
fi
if ! has_all_good_builds ${{ env.project_today }} $extra_packages > /tmp/diff; then
if grep -i "failed" /tmp/diff; then
cat <<EOF > body.txt
Hello @${{ matrix.maintainer_handle }},
<details>
<summary>Looking at the <a href="${{ env.monitor_url }}">Fedora Copr build monitor</a> for ${{ env.today_yyyymmdd }} we found at least one failed build.</summary>
\`\`\`diff
$(cat /tmp/diff)
\`\`\`
</details>
The CI system will update this very comment over time to list the errors.
Please note, that logs snippets will be limited to `max_context_bytes` bytes.
`update_marker`
EOF
causes_file=`mktemp`
archs=`grep -ioP 'failed\s+[^-]+-[0-9,rawhide]+-\K[^\s]+' /tmp/diff | sort | uniq`
projects=`grep -ioP 'failed\s+[^\s]+\s+\K[^\s]+$' /tmp/diff | sort | uniq`
oses=`grep -ioP 'failed\s+\K.*' /tmp/diff | cut -d '-' -f 1-2 | sort | uniq`
error_causes=`get_error_causes ${{ env.project_today }} $causes_file`
# Ensure labels for arch, project, OS, strategy and error cause
# exist in the github project
create_labels_for_archs ${GITHUB_REPOSITORY} "$archs"
create_labels_for_projects ${GITHUB_REPOSITORY} "$projects"
create_labels_for_oses ${GITHUB_REPOSITORY} "$oses"
create_labels_for_strategies ${GITHUB_REPOSITORY} "${{ matrix.name }}"
create_labels_for_error_causes ${GITHUB_REPOSITORY} "$error_causes"
os_labels=`for os in $oses; do echo -n " --label os/$os "; done`
arch_labels=`for arch in $archs; do echo -n " --label arch/$arch " ; done`
project_labels=`for project in $projects; do echo -n " --label project/$project "; done`
error_labels=`for cause in $error_causes; do echo -n " --label error/$cause "; done`
strategy_labels=" --label strategy/${{ matrix.name }} "
gh --repo ${GITHUB_REPOSITORY} issue create \
--label broken_snapshot_detected $strategy_labels $os_labels $arch_labels $project_labels $error_labels \
--assignee ${{ matrix.maintainer_handle }} \
--title "Broken snapshot for ${{ env.today_yyyymmdd }} detected (${{ matrix.name }})" \
--body-file body.txt
# When you create an issue with:
# gh issue create
# the issue is not immediately found with:
# gh issue list
# Therefore we give it a bit of time before we continue here.
sleep 5;
handle_error_causes \
${GITHUB_REPOSITORY} \
${{ matrix.name }} \
${{ matrix.maintainer_handle }} \
${{ env.project_today }} \
$causes_file
exit 1
fi
fi
python3 snapshot_manager/main.py check ${extra_args}\
--github_repo ${GITHUB_REPOSITORY} \
--github_token_env ${GITHUB_TOKEN} \
--maintainer-handle ${{matrix.maintainer_handle}} \
--packages ${{matrix.packages}} \
--build-strategy ${{matrix.name}} \
--copr-project-tpl ${{matrix.copr_project_tpl}} \
--copr-monitor-tpl ${{matrix.copr_monitor_tpl}}
9 changes: 9 additions & 0 deletions .github/workflows/testing-farm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ on:
default: true
required: true
type: boolean
# secrets:
# # TODO(kwk): Rename this because of this error:
# # secret name `GITHUB_TOKEN` within `workflow_call` can not be used since it would collide with system reserved name
# GITHUB_TOKEN:
# required: true
# TESTING_FARM_API_TOKEN_PUBLIC_RANCH:
# required: true
# TESTING_FARM_API_TOKEN_REDHAT_RANCH:
# required: true

workflow_dispatch:
inputs:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
buildroot/
llvm-snapshot-builder*.tar.bz2
*.rpm
.coverage
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ repos:
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=1000']
args: ['--maxkb=3000']

# Disabled until https://github.com/teemtee/tmt/issues/2651 is fixed
# See https://tmt.readthedocs.io/en/latest/guide.html#checking-data-validity
Expand All @@ -20,7 +20,7 @@ repos:
# See https://black.readthedocs.io/en/stable/integrations/source_version_control.html
# Using this mirror lets us use mypyc-compiled black, which is about 2x faster
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 23.10.1
rev: 24.2.0
hooks:
- id: black
# It is recommended to specify the latest version of Python
Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@ copr-build-%:
--chroots $(chroot) \
--packagenames $(package) \
--timeout "108000"

.PHONY:
test-snapshot-manager:
cd snapshot_manager \
&& python3 \
-m coverage run \
-m unittest \
discover -v \
--durations 0 \
--top-level-directory $(PWD)/snapshot_manager \
./tests
9 changes: 7 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# This file is autogenerated by pip-compile with Python 3.12
# by the following command:
#
# pip-compile --output-file=requirements.txt requirements.txt.in
Expand Down Expand Up @@ -45,7 +45,9 @@ jinja2==3.1.3
markupsafe==2.1.4
# via jinja2
munch==4.0.0
# via copr
# via
# -r requirements.txt.in
# copr
numpy==1.26.3
# via pandas
packaging==23.2
Expand All @@ -68,8 +70,11 @@ python-dateutil==2.8.2
# via pandas
pytz==2023.4
# via pandas
regex==2023.12.25
# via -r requirements.txt.in
requests==2.31.0
# via
# -r requirements.txt.in
# copr
# pygithub
# requests-toolbelt
Expand Down
5 changes: 4 additions & 1 deletion requirements.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
PyGithub==2.2.0
pandas
plotly==5.19.0
copr
copr-cli
tft-cli==0.0.16
regex==2023.12.25
munch==4.0.0
copr==1.130
requests==2.31.0
2 changes: 2 additions & 0 deletions snapshot_manager/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__pycache__
*.py,cover
Loading

0 comments on commit b98a33d

Please sign in to comment.