Skip to content

Commit

Permalink
[WIP] Add 'dev.py'
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Hernandez <[email protected]>
  • Loading branch information
jhernand committed Nov 16, 2023
1 parent bb61d02 commit f84c00a
Show file tree
Hide file tree
Showing 21 changed files with 790 additions and 94 deletions.
3 changes: 3 additions & 0 deletions .containerignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
!/LICENSE.txt
!/Makefile
!/README.md
!/dev.py
!/dev.txt
!/dev/
!/go.mod
!/go.sum
!/internal
Expand Down
37 changes: 37 additions & 0 deletions .github/actions/install-tools/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright (c) 2023 Red Hat, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

name: Install tools
runs:
using: composite
steps:
- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Install Python
uses: actions/setup-python@v2
with:
python-version: '3.11'
cache: pip
cache-dependency-path: dev.txt

- name: Install Python modules
shell: bash
run: pip install -r dev.txt

- name: Install tools
shell: bash
run: ./dev.py setup
42 changes: 15 additions & 27 deletions .github/workflows/check-pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ jobs:
- name: Checkout the source
uses: actions/checkout@v3

- name: Install tools
uses: ./.github/actions/install-tools

- name: Build image
run: make image
run: ./dev.py build image

unit-tests:
name: Unit tests
Expand All @@ -38,18 +41,14 @@ jobs:
- name: Checkout the source
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install tools
uses: ./.github/actions/install-tools

- name: Install Go tools
run: |
go install github.com/onsi/ginkgo/v2/ginkgo@$(go list -f '{{.Version}}' -m github.com/onsi/ginkgo/v2)
go install go.uber.org/mock/[email protected]
- name: Install tools
run: ./dev.py setup

- name: Run the tests
run: make tests
run: ./dev.py test

check-generated-code:
name: Check generated code
Expand All @@ -58,17 +57,11 @@ jobs:
- name: Checkout the source
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Install Go tools
run: |
go install go.uber.org/mock/[email protected]
- name: Install tools
uses: ./.github/actions/install-tools

- name: Generate code
run: make generate
run: ./dev.py generate

- name: Check differences
run: git diff --exit-code
Expand All @@ -80,13 +73,8 @@ jobs:
- name: Checkout the source
uses: actions/checkout@v3

- name: Install Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Install tools
uses: ./.github/actions/install-tools

- name: Run the linter
uses: golangci/golangci-lint-action@v3
with:
version: v1.54.2
args: --timeout=5m
run: ./dev.py lint
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.log
*.pyc
/__debug*
/oran-o2ims
__pycache__
11 changes: 11 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "setup",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/dev.py",
"args": [
"ci-job",
],
"console": "integratedTerminal",
"justMyCode": true
},
{
"name": "version",
"type": "go",
Expand Down
18 changes: 15 additions & 3 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,19 @@

FROM registry.access.redhat.com/ubi9/ubi:9.2 AS builder

# Install packages:
# Install OS packages:
RUN \
dnf install -y \
make \
python3.11 \
python3.11-pip \
&& \
dnf clean all

# In RHEL containers the default is Python 3.9, but we need the version of Python 3.11 that we
# installed as the default, otherwise our build scripts don't work correctly:
RUN \
ln -sf python3.11 /usr/bin/python3

# Currently RHEL 9 doesn't provide a Go 1.21 compiler, so we need to install it from the Go
# downloads site:
RUN \
Expand All @@ -39,6 +45,12 @@ WORKDIR \
ENV \
PATH="${PATH}:/usr/local/go/bin"

# Install Python packages:
COPY \
dev.txt .
RUN \
pip3.11 install -r dev.txt

# Copy the source:
COPY \
--chown=builder:builder \
Expand All @@ -51,7 +63,7 @@ RUN \

# Build the binary:
RUN \
make binary
./dev.py build binary

FROM registry.access.redhat.com/ubi9-minimal:9.2 AS runtime

Expand Down
61 changes: 0 additions & 61 deletions Makefile

This file was deleted.

59 changes: 59 additions & 0 deletions dev.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#
# Copyright (c) 2023 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

"""
This script is a development tool for the project.
"""

import logging
import sys

import click

import dev

@click.group()
def cli():
"""
Development tools.
"""

# Add the commands:
cli.add_command(dev.build)
cli.add_command(dev.ci_job)
cli.add_command(dev.clean)
cli.add_command(dev.fmt)
cli.add_command(dev.generate)
cli.add_command(dev.lint)
cli.add_command(dev.push)
cli.add_command(dev.setup)
cli.add_command(dev.test)

if __name__ == '__main__':
# Configure logging:
formatter = dev.Formatter()
handler = logging.StreamHandler()
handler.setFormatter(formatter)
logging.root.handlers = [handler]
logging.root.level = logging.DEBUG

# Run the command:
try:
cli()
except Exception as err:
logging.error(err)
sys.exit(1)
7 changes: 4 additions & 3 deletions .github/workflows/requirements.txt → dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2023 Red Hat, Inc.
# Copyright (c) 2023 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
Expand All @@ -12,6 +12,7 @@
# the License.
#

# This file lists the Python dependencies used by the GitHub actions.
# This file contains the list of Python modules required by the `dev.py` script.

requests
click
click-default-group
26 changes: 26 additions & 0 deletions dev/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-

#
# Copyright (c) 2023 Red Hat Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
# in compliance with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License
# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
# or implied. See the License for the specific language governing permissions and limitations under
# the License.
#

from .build import *
from .ci_job import *
from .clean import *
from .fmt import *
from .formatter import *
from .generate import *
from .lint import *
from .push import *
from .setup import *
from .test import *
Loading

0 comments on commit f84c00a

Please sign in to comment.