-
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.
Created release validation for yml file
Added a release validation in github action to know if the version is one of the previous ones at least
- Loading branch information
Showing
4 changed files
with
118 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,2 @@ | ||
requests==2.31.0 | ||
python-dotenv==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,75 @@ | ||
import os | ||
import sys | ||
import traceback | ||
import configparser | ||
from http import HTTPStatus | ||
import requests | ||
from dotenv import load_dotenv | ||
|
||
|
||
def main() -> None: | ||
""" | ||
Verify if the version is the same of one of the previous versions. | ||
Returns: | ||
- None | ||
""" | ||
token = os.getenv("GH_API_TOKEN") | ||
user_repo = os.getenv("GITHUB_REPOSITORY") | ||
headers = { | ||
"Authorization": f"Bearer {token}", | ||
"Accept": "application/json", | ||
"X-GitHub-Api-Version": "2022-11-28" | ||
} | ||
|
||
releases = f"https://api.github.com/repos/{user_repo}/releases" | ||
response = requests.get(releases, headers=headers, timeout=20) | ||
response_body: list[dict[str, any]] = response.json() | ||
if response.status_code == HTTPStatus.OK.value: | ||
previous_versions = [release.get("tag_name")[1:] for release in response_body] # example: ['1.0.0'] | ||
root = os.getenv("GITHUB_WORKSPACE") | ||
config = configparser.ConfigParser() | ||
config.read(f"{root}/setup.cfg") | ||
actual_version = config.get("metadata", "version") | ||
if actual_version in previous_versions: | ||
print("\033[33m The version is the same of one of the previous versions, please update the version \033[0m") | ||
sys.exit(1) | ||
else: | ||
print(f"\033[33m Something went wrong getting the releases: {response_body} \033[0m") | ||
sys.exit(1) | ||
|
||
def load_env_vars() -> None: | ||
""" | ||
Load the environment variables from .env file. | ||
Returns: | ||
- None | ||
""" | ||
try: | ||
load_dotenv("vars.env") | ||
print("\033[92m The vars.env file loaded \033[0m") | ||
except FileNotFoundError: | ||
print("\033[33m The vars.env file was not found, using env vars of github action \033[0m") | ||
|
||
if __name__ == "__main__": | ||
try: | ||
load_env_vars() | ||
ENVIRONMENT = "" | ||
destiny_branch = os.getenv("GITHUB_BASE_REF") | ||
if destiny_branch == "master": | ||
ENVIRONMENT = "PRD" | ||
elif destiny_branch == "development": | ||
ENVIRONMENT = destiny_branch.upper() | ||
else: | ||
print("\033[92m The destiny branch is not master or dev, script doesnt need to run \033[0m") | ||
if ENVIRONMENT == "PRD": | ||
main() | ||
else: | ||
print("\033[92m PR destiny is not to dev, skipping the execution of this code \033[0m") | ||
except Exception: | ||
print(f"\033[33m Complete exception traceback: {traceback.format_exc()} \033[0m") | ||
sys.exit(1) | ||
else: | ||
print("\033[92m The release version is valid \033[0m") | ||
finally: | ||
print("\033[92m End of the script \033[0m") |
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,37 @@ | ||
name: Validate Pull Requests | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- '*' | ||
- '!master' | ||
|
||
jobs: | ||
validate-pull-requests: | ||
runs-on: ubuntu-latest | ||
env: | ||
PR_NUMBER: ${{ github.event.number }} | ||
GH_API_TOKEN: ${{ secrets.GH_API_TOKEN }} | ||
|
||
steps: | ||
- name: Show the PR number | ||
run: | | ||
echo "The PR number is: $PR_NUMBER" | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python 3.11 | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.11 | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r .github/scripts/requirements.txt | ||
- name: Validate PR release | ||
run: | | ||
echo "Validating PR release" | ||
python .github/scripts/validate_release.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 |
---|---|---|
|
@@ -35,4 +35,7 @@ MANIFEST | |
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
.webassets-cache | ||
|
||
# Environment variables | ||
*.env |