-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add action code from khalford/check-version-action
- Loading branch information
Showing
21 changed files
with
577 additions
and
1 deletion.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
[report] | ||
|
||
exclude_lines = | ||
if __name__ == .__main__.: |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
name: Lint | ||
on: [push, pull_request] | ||
jobs: | ||
test_and_lint: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ "3.12", "3.x" ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: "pip" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Analyse with pylint | ||
run: | | ||
python3 -m pylint src --recursive=true --rcfile=.pylintrc | ||
python3 -m pylint tests --recursive=true --rcfile=.pylintrc | ||
- name: Run Black formatter | ||
uses: psf/black@stable |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
name: Integration Test | ||
on: [push, pull_request] | ||
jobs: | ||
self-test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Main to compare | ||
uses: actions/checkout@v4 | ||
with: | ||
ref: 'main' | ||
path: 'main' | ||
|
||
- uses: actions/checkout@v4 | ||
with: | ||
path: 'branch' | ||
|
||
- name: Self test | ||
if: ${{ github.ref != 'refs/heads/main' }} | ||
id: selftest | ||
uses: khalford/check-version-action@main | ||
with: | ||
app_version_path: "version.txt" | ||
docker_compose_path: "docker-compose.yml" | ||
|
||
- name: Log Success | ||
if: ${{ env.app_updated == 'true' }} | ||
run: | | ||
echo "App version has been updated correctly!" | ||
- name: Log Success | ||
if: ${{ env.compose_updated == 'true' }} | ||
run: | | ||
echo "Compose version has been updated correctly!" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
name: Unit Test | ||
on: [push, pull_request] | ||
jobs: | ||
test_and_lint: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: [ "3.12", "3.x" ] | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
cache: "pip" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run tests | ||
run: | | ||
python3 -m pytest tests | ||
- name: Run tests and collect coverage | ||
run: | | ||
python3 -m pytest tests --cov-report xml:coverage.xml --cov | ||
- name: Upload coverage to Codecov | ||
uses: codecov/codecov-action@v4 | ||
with: | ||
token: ${{secrets.CODECOV_TOKEN}} | ||
files: cloud-coverage.xml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.idea | ||
main_version | ||
branch_version | ||
src/__pycache__/* | ||
tests/__pycache__/* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[FORMAT] | ||
# Black will enforce 88 chars on Python code | ||
# this will enforce 120 chars on docs / comments | ||
max-line-length=120 | ||
|
||
# Disable various warnings: | ||
|
||
# W0237 Disabled as it makes the code more readable | ||
# R0801 Disabled as it's a small amount of duplication | ||
disable=W0237, R0801 | ||
|
||
[MASTER] | ||
init-hook='import sys; sys.path.append("src")' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FROM python:3 | ||
WORKDIR /app | ||
COPY . . | ||
RUN pip install -r requirements.txt | ||
CMD ["python","/app/src/main.py"] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,65 @@ | ||
# check-version-action | ||
# Check Version | ||
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/stfc/check-version-action/self_test.yaml?label=Intergration%20Test) | ||
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/stfc/check-version-action/lint.yaml?label=Linting) | ||
![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/stfc/check-version-action/test.yaml?label=Tests) | ||
[![codecov](https://codecov.io/gh/stfc/check-version-action/graph/badge.svg?token=OD2Z90ST8R)](https://codecov.io/gh/stfc/check-version-action) | ||
|
||
|
||
This action compares the application version number from your working branch to the main branch. | ||
|
||
You can also check that the **first** image version that appears in your `docker-compose.yaml` file will match the application version | ||
|
||
The comparison follows the PEP 440 Version Identification and Dependency Specification. | ||
|
||
More detailed information about the versions can be found [here](https://packaging.python.org/en/latest/specifications/version-specifiers/) | ||
|
||
# Usage | ||
|
||
## Notes: | ||
|
||
As of October 2024 GitHub actions using Docker Containers can only be run on GitHub runners using a Linux operating system.<br> | ||
Read here for details: [Link to GitHub docs](https://docs.github.com/en/actions/sharing-automations/creating-actions/about-custom-actions#types-of-actions) | ||
|
||
The release tag is extracted and stored in `$GITHUB_ENV`, | ||
you can access this in your workflow with `$ {{ env.release_tag }}` | ||
|
||
<!-- start usage --> | ||
```yaml | ||
- name: Checkout main | ||
uses: actions/checkout@v4 | ||
with: | ||
# Change to "master" if needed | ||
ref: 'main' | ||
# Do not change the path here | ||
path: 'main' | ||
|
||
- name: Checkout current working branch | ||
uses: actions/checkout@v4 | ||
with: | ||
# Do not change the path here | ||
path: 'branch' | ||
|
||
- name: Compare versions | ||
# Don't run on main otherwise it will compare main with main | ||
if: ${{ github.ref != 'refs/heads/main' }} | ||
id: version_comparison | ||
uses: khalford/check-version-action@main | ||
with: | ||
# Path to version file from project root | ||
app_version_path: "version.txt" | ||
# Optional: To check if compose image version matches application version | ||
docker_compose_path: "docker-compose.yaml" | ||
|
||
- name: Log App Success | ||
if: ${{ env.app_updated == 'true' }} | ||
run: | | ||
echo "App version has been updated correctly!" | ||
# Optional: If using the docker compose check | ||
- name: Log Compose Success | ||
if: ${{ env.compose_updated == 'true' }} | ||
run: | | ||
echo "Compose version has been updated correctly!" | ||
``` | ||
<!-- end usage --> | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: 'Check Semver Version Number' | ||
description: 'Check if the semver version number has changed from the main branch. Can also check if the docker compose file reflects the application version.' | ||
inputs: | ||
app_version_path: | ||
description: 'Path to main app version file.' | ||
required: true | ||
default: './version.txt' | ||
docker_compose_path: | ||
description: 'Path to compose file.' | ||
required: false | ||
outputs: | ||
app_updated: | ||
description: 'If the app version was updated or not.' | ||
compose_updated: | ||
description: 'If the compose version was updated or not.' | ||
|
||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
services: | ||
self-test: | ||
image: some/test:1.0.0 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[pytest] | ||
pythonpath = src | ||
testpaths = tests | ||
python_files = *.py | ||
python_functions = test_* |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
packaging | ||
pylint | ||
pytest | ||
pytest-cov |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"""This is the base module including helper/abstract classes and errors.""" | ||
|
||
from abc import ABC, abstractmethod | ||
from pathlib import Path | ||
from typing import Union | ||
from packaging.version import Version | ||
|
||
|
||
class VersionNotUpdated(Exception): | ||
"""The version number has not been updated or updated incorrectly.""" | ||
|
||
|
||
class Base(ABC): | ||
"""The base abstract class to build features on.""" | ||
|
||
@abstractmethod | ||
def run(self, path1: Path, path2: Path) -> bool: | ||
""" | ||
This method is the entry point to the feature. | ||
It should take two paths and return the comparison result. | ||
""" | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def read_files(path1: Path, path2: Path) -> (str, str): | ||
"""This method should read the contents of the compared files and return the strings""" | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def get_version(content: str) -> Version: | ||
"""This method should extract the version from the file and return it as a packaging Version object""" | ||
|
||
@staticmethod | ||
@abstractmethod | ||
def compare(version1: Version, version2: Version) -> Union[bool, VersionNotUpdated]: | ||
"""This method should compare the versions and return a bool status""" |
Oops, something went wrong.