Skip to content

Commit f1dc677

Browse files
committed
Added GitHub Actions
For publishingn on PyPi Dependabot CodeQL Labeling PR
1 parent 37669d2 commit f1dc677

File tree

7 files changed

+222
-0
lines changed

7 files changed

+222
-0
lines changed

.github/dependabot.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "pip" # See documentation for possible values
9+
directory: "/" # Location of package manifests
10+
schedule:
11+
interval: "weekly"

.github/labeler.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
documentation:
2+
- "**/*.md"
3+
- LICENSE
4+
- "docs/**/*"
5+
- "screenshots/**/*"
6+
7+
dependencies:
8+
- requirements.txt
9+
10+
enhancement:
11+
- "**"
12+
13+
github-actions:
14+
- ".github/**/*"
15+
16+
tests:
17+
- "spam_detector_ai/test_and_tuning/**/*"
18+
19+
models:
20+
- "spam_detector_ai/models/**/*"
21+
22+
training:
23+
- "spam_detector_ai/training/**/*"
24+
- "spam_detector_ai/data/**/*"
25+
- "spam_detector_ai/classifiers/**/*"
26+
- "spam_detector_ai/prediction/**/*"
27+
- "spam_detector_ai/loading_and_processing/**/*"

.github/workflows/codeql.yml

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL"
13+
14+
on:
15+
push:
16+
branches-ignore:
17+
- 'main'
18+
workflow_dispatch:
19+
20+
jobs:
21+
analyze:
22+
name: Analyze
23+
# Runner size impacts CodeQL analysis time. To learn more, please see:
24+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
25+
# - https://gh.io/supported-runners-and-hardware-resources
26+
# - https://gh.io/using-larger-runners
27+
# Consider using larger runners for possible analysis time improvements.
28+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
29+
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
30+
permissions:
31+
# required for all workflows
32+
security-events: write
33+
34+
# only required for workflows in private repositories
35+
actions: read
36+
contents: read
37+
38+
strategy:
39+
fail-fast: false
40+
matrix:
41+
language: [ 'javascript-typescript', 'python' ]
42+
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ]
43+
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both
44+
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
45+
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support
46+
47+
steps:
48+
- name: Checkout repository
49+
uses: actions/checkout@v4
50+
51+
# Initializes the CodeQL tools for scanning.
52+
- name: Initialize CodeQL
53+
uses: github/codeql-action/init@v3
54+
with:
55+
languages: ${{ matrix.language }}
56+
# If you wish to specify custom queries, you can do so here or in a config file.
57+
# By default, queries listed here will override any specified in a config file.
58+
# Prefix the list here with "+" to use these queries and those in the config file.
59+
60+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
61+
# queries: security-extended,security-and-quality
62+
63+
64+
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
65+
# If this step fails, then you should remove it and run the build manually (see below)
66+
- name: Autobuild
67+
uses: github/codeql-action/autobuild@v3
68+
69+
# ℹ️ Command-line programs to run using the OS shell.
70+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
71+
72+
# If the Autobuild fails above, remove it and uncomment the following three lines.
73+
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance.
74+
75+
# - run: |
76+
# echo "Run, Build Application using script"
77+
# ./location_of_script_within_repo/buildscript.sh
78+
79+
- name: Perform CodeQL Analysis
80+
uses: github/codeql-action/analyze@v3
81+
with:
82+
category: "/language:${{matrix.language}}"

.github/workflows/labeler.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# This workflow will triage pull requests and apply a label based on the
2+
# paths that are modified in the pull request.
3+
#
4+
# To use this workflow, you will need to set up a .github/labeler.yml
5+
# file with configuration. For more information, see:
6+
# https://github.com/actions/labeler
7+
8+
name: Labeler
9+
on: [pull_request_target]
10+
11+
jobs:
12+
label:
13+
14+
runs-on: ubuntu-latest
15+
permissions:
16+
contents: read
17+
pull-requests: write
18+
19+
steps:
20+
- uses: actions/labeler@v4
21+
with:
22+
repo-token: "${{ secrets.GITHUB_TOKEN }}"
23+
sync-labels: false
24+
dot: true

.github/workflows/publish.yml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: Upload Python Package to PyPI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
jobs:
10+
deploy:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
16+
- name: Set up Python
17+
uses: actions/setup-python@v2
18+
with:
19+
python-version: '3.x'
20+
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install setuptools wheel twine requests
25+
26+
# Check if the current version is already on PyPI
27+
- name: Check version on PyPI
28+
id: version_check
29+
run: |
30+
python check_version.py
31+
continue-on-error: true
32+
33+
# Build the package (folder exclusion is handled by MANIFEST.in)
34+
- name: Build package
35+
if: steps.version_check.outputs.version_exists != 'true'
36+
run: |
37+
python setup.py sdist bdist_wheel
38+
39+
- name: Upload to PyPI
40+
if: steps.version_check.outputs.version_exists != 'true'
41+
env:
42+
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
43+
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
44+
run: |
45+
twine upload dist/*

check_version.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import requests
2+
from spam_detector_ai import __version__, __package_name__, __test_version__
3+
4+
5+
def check_package_version(package_name, current_version):
6+
version_exists = False
7+
8+
if __test_version__:
9+
print("Test version, skipping PyPI check.")
10+
version_exists = True
11+
else:
12+
response = requests.get(f"https://pypi.org/pypi/{package_name}/json")
13+
14+
if response.status_code == 200:
15+
released_versions = response.json()["releases"].keys()
16+
if current_version in released_versions:
17+
print(f"Version {current_version} already exists on PyPI!")
18+
version_exists = True
19+
20+
# Output for GitHub Actions
21+
print(f"::set-output name=version_exists::{version_exists}")
22+
23+
24+
check_package_version(__package_name__, __version__)

spam_detector_ai/__init__.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,12 @@
55
from . import prediction
66
from . import test_and_tuning
77
from . import training
8+
9+
__author__ = "Adams Pierre David"
10+
__author_email__ = "[email protected]"
11+
__author_website__ = "https://adamspierredavid.com/"
12+
__description__ = "Detecting and filtering spam messages using Machine Learning models."
13+
__package_name__ = "spam-detector-ai"
14+
__url__ = "https://github.com/adamspd/spam-detection-project"
15+
__version__ = "1.0.3"
16+
__test_version__ = True

0 commit comments

Comments
 (0)