Skip to content

Commit

Permalink
Clean up (#2)
Browse files Browse the repository at this point in the history
* upDate clean main

* Cleaned TODO add img

* update requirements

* update CI.yml

* update read previous version

* fix 1

* fix 2

* fix3

* fix4

* fix6

* fix7

* fix8

* fix9

* fix10

* fix11

* fix12

* fix 13

* fix14

* fix15

* fix 16

* fix17

* img added

* fix colors

* fix colors2

* deploy on GH page

---------

Co-authored-by: Esteban Lascourreges <esteban.lascourreges@corpowerocean.com>
  • Loading branch information
LordLumineer and Esteban Lascourreges authored Nov 14, 2023
1 parent 4261927 commit 48b1c29
Show file tree
Hide file tree
Showing 20 changed files with 2,949 additions and 1,371 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/ci-RC.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: CI/CD Realase Candidate

on:
pull_request:
branches:
- RC

jobs:
test-Realease-Candidate:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.12

- name: check origin
run: |
echo "origin= $(git remote get-url origin)"
echo "origin= $(git ls-remote origin)"
- name: update pip
run: python -m pip install --upgrade pip

- name: Install Dependencies
run: |
pip install -r requirements.txt
- name: Uvicorn Run for Test
run: |
uvicorn ThroneAPI:app --host 0.0.0.0 --port 8000 --reload & echo $! > uvicorn_pid
- name: Get Current Version
id: get_current_version
run: echo "CURRENT_VERSION=$(curl http://localhost:8000/version)" >> $GITHUB_ENV

- name: Get Previous Version
id: get_previous_version
run: |
git fetch origin RC
git checkout RC
version=$(git show origin/RC:ThroneAPI.py | grep -oP "API_VERSION = \"\K[0-9.]+" ThroneAPI.py || echo "0.0.0")
echo "Version: $version"
echo "PREVIOUS_VERSION=$version" >> $GITHUB_ENV
- name: Compare Versions
id: compare_versions
run: |
pip install semantic_version
current_version=${{ env.CURRENT_VERSION }}
previous_version=${{ env.PREVIOUS_VERSION }}
echo "Current Version: $current_version"
echo "Previous Version: $previous_version"
python -c "from semantic_version import Version; import sys; sys.exit(0 if Version('${{ env.CURRENT_VERSION }}') > Version('${{ env.PREVIOUS_VERSION }}') else 1)"
- name: Check Version Comparison Result
run: |
if [ ${{ steps.compare_versions.outcome }} == "failure" ]; then
echo "Error: Current version is not superior to the previous version."
exit 1
fi
- name: Test Throne data
run: |
test_result=$(curl http://localhost:8000/test?username=lordlumineer&display_currency=eur) # Perform a request to /test
if [ "$test_result" == "false" ]; then
echo "Test failed: /test returned false"
exit 1
fi
- name: End Uvicorn Run
run: |
uvicorn_pid=$(cat uvicorn_pid)
kill $uvicorn_pid || true # Kill the Uvicorn process if it's still running, ignore errors
- name: Test Docker Build
run: |
docker-compose build
- name: Test Docker Up
run: |
docker-compose up -d
sleep 5
- name: Test Docker
run: |
test_result=$(curl http://localhost:8000/test?username=lordlumineer) # Perform a request to /test
if [ "$test_result" == "false" ]; then
echo "Test failed: /test returned false"
exit 1
fi
- name: Stop Docker
run: |
docker-compose down
19 changes: 12 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: CI
name: CI/CD Prpduction

on:
pull_request:
branches:
- main
- latest

jobs:
test:
test-Production:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: 3.12

Expand All @@ -35,7 +35,12 @@ jobs:

- name: Get Previous Version
id: get_previous_version
run: echo "PREVIOUS_VERSION=$(git show origin/main:ThroneAPI.py | grep -oP "API_VERSION = '\K[0-9.]+" || echo "0.0.0")" >> $GITHUB_ENV
run: |
git fetch origin latest
git checkout latest
version=$(git show origin/latest:ThroneAPI.py | grep -oP "API_VERSION = \"\K[0-9.]+" ThroneAPI.py || echo "0.0.0")
echo "Version: $version"
echo "PREVIOUS_VERSION=$version" >> $GITHUB_ENV
- name: Compare Versions
id: compare_versions
Expand All @@ -56,7 +61,7 @@ jobs:
- name: Test Throne data
run: |
test_result=$(curl http://localhost:8000/test?username=lordlumineer) # Perform a request to /test
test_result=$(curl http://localhost:8000/test?username=lordlumineer&display_currency=eur) # Perform a request to /test
if [ "$test_result" == "false" ]; then
echo "Test failed: /test returned false"
Expand Down
27 changes: 27 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Deploy on GitHub Pages

on:
push:
branches: [ "latest" ]

jobs:
deploy-github-pages:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: 3.12

- name: update pip
run: python -m pip install --upgrade pip

- name: Install Dependencies
run: pip install -r requirements.txt

- name: Uvicorn Run for Test
run: uvicorn ThroneAPI:app --port 8000 --reload
30 changes: 30 additions & 0 deletions .github/workflows/docker-publish-RC.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Publish Docker Image on Release Candidate

on:
push:
branches:
- RC

jobs:
publish-Release-Candidate:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v3

- name: Get Version
id: get_version
run: |
version=$(grep -oP "API_VERSION = \"\K[0-9.]+" ThroneAPI.py || echo "0.0.0")
echo "Version: $version"
echo "$version" > version
- name: Login to DockerHub
run: echo ${{ secrets.DOCKER_PASSWORD }} | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Build and Push Docker Image
run: |
version=$(cat version)
docker build -t lordlumineer/throne-api:RC-${version} .
docker push lordlumineer/throne-api:RC-${version}
8 changes: 4 additions & 4 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Publish Docker Image
name: Publish Docker Image on Production

on:
push:
branches:
- main
- latest

jobs:
publish:
publish-Production:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2
uses: actions/checkout@v3

- name: Get Version
id: get_version
Expand Down
Loading

0 comments on commit 48b1c29

Please sign in to comment.