Fix: downloading tracks in chunks #109
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
name: Python CI | |
on: | |
push: | |
branches: | |
- "*" | |
paths: | |
- "src/**/*.py" | |
- "requirements.txt" | |
- "Dockerfile" | |
- ".github/workflows/compile.yml" | |
pull_request: | |
branches: | |
- "*" | |
paths: | |
- "src/**/*.py" | |
- "requirements.txt" | |
- "Dockerfile" | |
- ".github/workflows/compile.yml" | |
env: | |
SRC: "./src/pyramid" | |
TEST: "./src/pyramid-test" | |
TEST_FILES: "*_test.py" | |
jobs: | |
compile: | |
name: "Compile Python 3.11" | |
runs-on: ubuntu-latest | |
outputs: | |
json: ${{ steps.version.outputs.json }} | |
version: ${{ steps.version.outputs.version }} | |
commit_id: ${{ steps.version.outputs.commit_id }} | |
last_author: ${{ steps.version.outputs.last_author }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- 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: Test compilation | |
run: | | |
python -m compileall ${{ env.SRC }} | |
- name: Save version | |
run: | | |
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" | |
needs: compile | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.12"] | |
continue-on-error: true | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: "${{ matrix.python-version }}" | |
- name: Cache dependencies | |
uses: actions/cache@v3 | |
with: | |
path: ~/.cache/pip | |
key: ${{ runner.os }}-python_${{ matrix.python-version }}-pip-${{ hashFiles('**/requirements.txt') }}-${{ matrix.python-version }} | |
restore-keys: | | |
${{ runner.os }}-python_${{ matrix.python-version }}-pip | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi | |
- name: Test compilation | |
run: | | |
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 }}) | |
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.TOKEN_RELEASE }} | |
with: | |
tag_name: ${{ needs.compile.outputs.version }}-${{ needs.compile.outputs.commit_id }} | |
release_name: Stable Auto-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 }} | |
* ${{ secrets.DOCKERHUB_USERNAME }}/pyramid:${{ needs.compile.outputs.version }} | |
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 Auto-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 }} | |
draft: false | |
prerelease: true | |
docker_push: | |
name: "Docker Push" | |
needs: ["compile", "publish_release"] | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set git info | |
run: | | |
echo '${{ needs.compile.outputs.json }}' | jq -r '.git_info' > git_info.json | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Build and push PROD | |
if: needs.publish_release.outputs.docker_tag == 'latest' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ 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: needs.publish_release.outputs.docker_tag != 'latest' | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ 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 | |
cache-to: type=gha,mode=max |