From c9b83df928b23694fc425ba5e68f29b9c6e88245 Mon Sep 17 00:00:00 2001 From: Florian Charlaix Date: Mon, 19 Feb 2024 20:21:31 +0100 Subject: [PATCH] CI Add tests and package deploy --- .forgejo/workflows/build.yml | 92 ++++++++++++++++++++++++++ .forgejo/workflows/sonarqube.yml | 38 ----------- .gitignore | 5 ++ VERSION | 1 + administrator/modules/test/__init__.py | 2 +- administrator/test/test_basic.py | 5 ++ setup.py | 14 ++-- tox.ini | 15 +++++ 8 files changed, 128 insertions(+), 44 deletions(-) create mode 100644 .forgejo/workflows/build.yml delete mode 100644 .forgejo/workflows/sonarqube.yml create mode 100644 VERSION create mode 100644 administrator/test/test_basic.py create mode 100644 tox.ini diff --git a/.forgejo/workflows/build.yml b/.forgejo/workflows/build.yml new file mode 100644 index 0000000..259e711 --- /dev/null +++ b/.forgejo/workflows/build.yml @@ -0,0 +1,92 @@ +name: Build + +on: + push: + branches: + - master + +jobs: + tests: + name: Tests + runs-on: docker + + container: + image: python:3.11-alpine + + steps: + - name: "Setup env" + run: | + apk add --no-cache git nodejs + pip install tox + + - name: "Get repo" + uses: actions/checkout@v4 + + - name: "Tests" + run: tox + + sonarqube: + name: SonarQube + runs-on: docker + + if: github.ref == 'refs/heads/master' + + container: + image: alpine + + steps: + - name: "Setup env" + run: apk add --no-cache git nodejs bash curl jq + + - name: "Get repo" + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis + + - name: "SonarQube Scan" + uses: https://github.com/sonarsource/sonarqube-scan-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + # If you wish to fail your job when the Quality Gate is red, uncomment the + # following lines. This would typically be used to fail a deployment. + - name: "SonarQube Quality gate" + uses: https://github.com/sonarsource/sonarqube-quality-gate-action@master + timeout-minutes: 5 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} + + deploy: + name: Deploy + runs-on: docker + needs: + - tests + - sonarqube + + if: github.ref == 'refs/heads/master' + + container: + image: python:3.11-alpine + + steps: + - name: "Setup env" + run: | + apk add --no-cache git nodejs + pip install build twine + + - name: "Get repo" + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: "Build" + run: python -m build + + - name: "Push" + uses: https://github.com/pypa/gh-action-pypi-publish@release/v1 + with: + user: "${{ env.GITHUB_ACTOR }}" + password: "${{ secrets.PACKAGE_TOKEN }}" + repository-url: "${{ env.GITHUB_SERVER_URL }}/api/packages/${{ env.GITHUB_REPOSITORY_OWNER }}/pypi" diff --git a/.forgejo/workflows/sonarqube.yml b/.forgejo/workflows/sonarqube.yml deleted file mode 100644 index 05bac5f..0000000 --- a/.forgejo/workflows/sonarqube.yml +++ /dev/null @@ -1,38 +0,0 @@ -name: SonarQube - -on: - push: - branches: - - master - -jobs: - sonarqube: - name: SonarQube - runs-on: docker - - container: - image: alpine - - steps: - - name: "Setup env" - run: apk add --no-cache git nodejs bash curl jq - - - name: "Get repo" - uses: actions/checkout@v4 - with: - fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis - - - name: "SonarQube Scan" - uses: https://github.com/sonarsource/sonarqube-scan-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} - - # If you wish to fail your job when the Quality Gate is red, uncomment the - # following lines. This would typically be used to fail a deployment. - - name: "SonarQube Quality gate" - uses: https://github.com/sonarsource/sonarqube-quality-gate-action@master - timeout-minutes: 5 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }} diff --git a/.gitignore b/.gitignore index 340d611..e8ff4c5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,11 @@ /.vscode /venv +/.venv /administrator/settings/local_settings.py __pycache__ /discord.log /*.db +/.tox +/.eggs/ +/*.egg-info/ +/build/ \ No newline at end of file diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..6c6aa7c --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.1.0 \ No newline at end of file diff --git a/administrator/modules/test/__init__.py b/administrator/modules/test/__init__.py index e807b01..7ac2779 100644 --- a/administrator/modules/test/__init__.py +++ b/administrator/modules/test/__init__.py @@ -5,7 +5,7 @@ from discord.ext.commands import Cog, Bot class Test(Cog): def __init__(self, bot: Bot) -> None: self.bot = bot - + @app_commands.command(name="ping") async def ping(self, interaction: Interaction) -> None: await interaction.response.send_message("Pong !", ephemeral=True) diff --git a/administrator/test/test_basic.py b/administrator/test/test_basic.py new file mode 100644 index 0000000..f1ee188 --- /dev/null +++ b/administrator/test/test_basic.py @@ -0,0 +1,5 @@ +def test_bypass(): + """ + Bypass pyrtest + """ + pass diff --git a/setup.py b/setup.py index 1a48e7e..810b231 100644 --- a/setup.py +++ b/setup.py @@ -4,18 +4,22 @@ from setuptools import setup, find_packages with open("README.md") as f: readme = f.read() -with open("LICENSE") as f: - license = f.read() - setup( name='administrator', - version='0.1.0', + setuptools_git_versioning={ + "enabled": True, + "version_file": "VERSION", + "count_commits_from_version_file": True, + "dev_template": "{tag}.dev{ccount}", + "dirty_template": "{tag}.{branch}{ccount}", + }, + setup_requires=["setuptools-git-versioning"], description='All purpose Discord bot', long_description=readme, author='Ethanell', author_email='ethanell@flifloo.fr', url='https://git.flifloo.fr/flifloo/Administrator', - license=license, + license="GNU General Public License v3.0", packages=find_packages(exclude=('tests', 'docs')) ) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..cc75b5b --- /dev/null +++ b/tox.ini @@ -0,0 +1,15 @@ +[tox] +env_list = + py311 +minversion = 4.4.7 + +[testenv] +description = run the tests with pytest +package = wheel +wheel_build_env = .pkg +deps = + pytest>=6 + flake8 + -r requirements.txt +commands = + pytest {tty:--color=yes} {posargs} administrator