Skip to content

Commit

Permalink
Merge branch 'pre-prod'
Browse files Browse the repository at this point in the history
  • Loading branch information
tristiisch committed Nov 14, 2023
2 parents 444b057 + bd754c1 commit f160508
Show file tree
Hide file tree
Showing 30 changed files with 834 additions and 247 deletions.
182 changes: 159 additions & 23 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ on:
- "Dockerfile"
- ".github/workflows/compile.yml"

env:
SRC: "./src/pyramid"
TEST: "./src/pyramid-test"
TEST_FILES: "*_test.py"

jobs:

compile:
Expand Down Expand Up @@ -53,24 +58,57 @@ jobs:
- name: Test compilation
run: |
python -m compileall ./src
python -m compileall ${{ env.SRC }}
- name: Save version
run: |
FULL_JSON=$(python src/pyramid --version)
FULL_JSON=$(python ${{ env.SRC }} --version)
echo "json=$(echo $FULL_JSON | jq -c)" >> $GITHUB_OUTPUT
echo "version=$(echo $FULL_JSON | jq -r '.version')" >> $GITHUB_OUTPUT
echo "commit_id=$(echo $FULL_JSON | jq -r '.git_info.commit_id')" >> $GITHUB_OUTPUT
echo "last_author=$(echo $FULL_JSON | jq -r '.git_info.last_author')" >> $GITHUB_OUTPUT
id: version

unit_test:
name: "Unit tests Python"
needs: compile
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
clean: false

- name: Set up Python 3.11
uses: actions/setup-python@v4
with:
python-version: "3.11"

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Units tests
run: |
python -m unittest discover -v -s ${{ env.TEST }} -p ${{ env.TEST_FILES }}
version_compatibility:
name: "Compile Python"
runs-on: ubuntu-latest
needs: compile
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10", "3.12"]
continue-on-error: true

steps:
Expand All @@ -86,9 +124,9 @@ jobs:
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ matrix.python-version }}
key: ${{ runner.os }}-python_${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ matrix.python-version }}
restore-keys: |
${{ runner.os }}-pip
${{ runner.os }}-python_${{ matrix.python-version }}-pip
- name: Install dependencies
run: |
Expand All @@ -97,11 +135,120 @@ jobs:
- name: Test compilation
run: |
python -m compileall ./src
python -m compileall ${{ env.SRC }}
publish_release:
name: "Publish release"
needs: ["compile", "unit_test"]
runs-on: ubuntu-latest
outputs:
docker_tag: ${{ steps.docker_tag.outputs.tag }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 100

- name: Set Docker Image Tag
id: docker_tag
run: |
if [ ${{ github.ref }} = 'refs/heads/main' ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
elif [ ${{ github.ref }} = 'refs/heads/pre-prod' ]; then
echo "tag=pre-prod" >> $GITHUB_OUTPUT
echo "tag_github=unstable" >> $GITHUB_OUTPUT
else
echo "tag=dev" >> $GITHUB_OUTPUT
fi
- name: Get commit messages
id: get_commit_messages
run: |
COMMIT_MESSAGES=$(git log --pretty=format:"%s" ${{ github.event.before }}..${{ github.sha }} | sed -e 's/^/* /')
echo "commit_messages=${COMMIT_MESSAGES}" >> $GITHUB_OUTPUT
- name: Get last release tag
if: steps.docker_tag.outputs.tag == 'latest'
id: get_last_release
run: |
RESPONSE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases/latest")
if [[ $(echo "$RESPONSE" | jq -r .message) == "Not Found" ]]; then
LAST_RELEASE_TAG=$(git rev-list --max-parents=0 HEAD)
else
LAST_RELEASE_TAG=$(echo "$RESPONSE" | jq -r .tag_name)
fi
echo "last_release_tag=${LAST_RELEASE_TAG}" >> $GITHUB_OUTPUT
- name: Create stable Release
if: steps.docker_tag.outputs.tag == 'latest'
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ needs.compile.outputs.version }}
release_name: Stable Release v${{ needs.compile.outputs.version }}
body: |
This has been deployed on the Discord bot `PyRamid#6882`.
To use the latest version the bot, please refer to the instructions outlined at https://github.com/tristiisch/PyRamid/#usage.
## Changes
${{ steps.get_commit_messages.outputs.commit_messages }}
## Docker
This version is now accessible through various Docker images. Each image creation corresponds to a unique snapshot of this version, while updating the image corresponds to using an updated Docker image tag.
### Images creation
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
### Images update
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ steps.docker_tag.outputs.tag }}
draft: true
prerelease: false

- name: Get last pre-release tag
if: steps.docker_tag.outputs.tag != 'latest'
id: get_last_unstable_release
run: |
RESPONSE=$(curl -s "https://api.github.com/repos/${{ github.repository }}/releases")
if [[ $(echo "$RESPONSE" | jq -r .message) == "Not Found" ]]; then
LAST_RELEASE_TAG=${{ github.event.before }}
else
LAST_RELEASE_TAG=$(echo "$RESPONSE" | jq -r '.[0].tag_name')
fi
echo "last_release_tag=${LAST_RELEASE_TAG}" >> $GITHUB_OUTPUT
- name: Create unstable Release
if: steps.docker_tag.outputs.tag != 'latest'
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.TOKEN_RELEASE }}
with:
tag_name: ${{ steps.docker_tag.outputs.tag_github }}-${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
release_name: Unstable release v${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
body: |
This has been deployed on the Discord bot `PyRamid PRÉ-PROD#6277`.
Feel free to put it to the test by joining the development server at https://discord.gg/pNrZp7U34d.
## Changes
${{ steps.get_commit_messages.outputs.commit_messages }}
## Docker
This version is now accessible through various Docker images. Each image creation corresponds to a unique snapshot of this version, while updating the image corresponds to using an updated Docker image tag.
### Images creation
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
### Images update
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ steps.docker_tag.outputs.tag }}
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}
draft: false
prerelease: true


docker_push:
name: "Docker Push"
needs: compile
needs: ["compile", "publish_release"]
runs-on: ubuntu-latest
if: github.event_name == 'push'

Expand All @@ -122,39 +269,28 @@ jobs:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set Docker Tag
run: |
if [ ${{ github.ref }} = 'refs/heads/main' ]; then
echo "tag=latest" >> $GITHUB_OUTPUT
elif [ ${{ github.ref }} = 'refs/heads/pre-prod' ]; then
echo "tag=pre-prod" >> $GITHUB_OUTPUT
else
echo "tag=dev" >> $GITHUB_OUTPUT
fi
id: set_tag

- name: Build and push PROD
if: steps.set_tag.outputs.tag == 'latest'
if: needs.publish_release.outputs.docker_tag == 'latest'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ steps.set_tag.outputs.tag }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.publish_release.outputs.docker_tag }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Build and push DEV
if: steps.set_tag.outputs.tag != 'latest'
if: needs.publish_release.outputs.docker_tag != 'latest'
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ steps.set_tag.outputs.tag }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.publish_release.outputs.docker_tag }},
${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }}
cache-from: type=gha
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,4 @@ songs/
config.yml
logs/
git_info.json
/test/
10 changes: 9 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"python.analysis.typeCheckingMode": "basic",
"python.tensorBoard.logDirectory": "./logs"
"python.testing.unittestArgs": [
"-v",
"-s",
"./src/pyramid-test",
"-p",
"*_test.py"
],
"python.testing.pytestEnabled": false,
"python.testing.unittestEnabled": true
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ spotify:
client_id: <client id of your spotify application>
client_secret: <client secret of your spotify application>

general:
default_limit_tracks: 100

# Available value: production, pre-production, development
# Change message level in logs
mode: production
Expand Down
9 changes: 9 additions & 0 deletions auto_update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Get the directory of the script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Change the working directory
cd "$DIR"

docker compose up --pull always -d
3 changes: 3 additions & 0 deletions config.exemple.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ spotify:
client_id: <client id of your spotify application>
client_secret: <client secret of your spotify application>

general:
default_limit_tracks: 100

# Available value: production, pre-production, development
# Change message level in logs
mode: production
Expand Down
4 changes: 4 additions & 0 deletions environnement.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ function Install-Requirement() {
pip install -r .\requirements.txt
}

function Update-Requirement() {
pip install --upgrade -r .\requirements.txt
}

function Add-Lib($lib) {
pip install $lib
pip freeze | grep -i $lib >> requirements.txt
Expand Down
Binary file modified requirements.txt
Binary file not shown.
6 changes: 6 additions & 0 deletions src/pyramid-test/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import unittest
import queue_test

if __name__ == "__main__":
suite = unittest.TestLoader().loadTestsFromModule(queue_test)
unittest.TextTestRunner(verbosity=2).run(suite)
Loading

0 comments on commit f160508

Please sign in to comment.