Exit all processes gracefully #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: Main Workflow | |
on: | |
push: | |
branches: | |
- test | |
env: | |
IMAGE_NAME: "thepromidius/fmd3-api" | |
BUMP_TYPE: ${{ github.event.ref == 'refs/heads/main' && 'minor' || | |
github.event.ref == 'refs/heads/test' && 'dev' || | |
github.event.ref == 'refs/heads/dev' && 'dev' || | |
github.event.ref == 'refs/heads/develop' && 'patch' || | |
github.event.ref == 'refs/heads/release/alpha' && 'alpha' || | |
'patch' }} | |
DOCKER_TAG: ${{ github.event.ref == 'refs/heads/main' && 'latest' || | |
github.event.ref == 'refs/heads/develop' && 'nightly' || | |
github.event.ref == 'refs/heads/dev' && 'dev' || | |
github.event.ref == 'refs/heads/test' && 'dev' }} | |
jobs: | |
# run_workflow_tests: | |
# runs-on: ubuntu-latest | |
# steps: | |
# - name: Checkout repository | |
# uses: actions/checkout@v4 | |
# | |
# - name: Set up Python 3.11 | |
# uses: actions/setup-python@v5 | |
# with: | |
# python-version: 3.11 | |
# cache: 'pip' | |
# - name: Install dependencies | |
# run: | | |
# python -m pip install --upgrade pip | |
# pip install -r requirements.txt | |
# - name: Run the tests | |
# run: python .github/workflows/workflow_helpers_tests/__main__.py | |
run_tests: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Run the tests | |
run: | | |
python -m tests | |
bump_version: | |
runs-on: ubuntu-latest | |
needs: [run_tests] | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.ref }} | |
fetch-depth: 0 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: 3.11 | |
cache: 'pip' | |
- name: Install dependencies | |
run: | | |
pip install packaging promidius-versioning-utils | |
- name: Store Original Versions | |
id: store_original_versions | |
run: | | |
original_versions=$(jq -r '.[] | "\(.version)"' versions_metadata.json) | |
echo "::set-output name=original_versions::$original_versions" | |
- name: Bump packages | |
run: python .github/workflows/bump_packages.py | |
# Compare versions and detect bump | |
- name: Compare Versions and Detect Bump | |
id: detect_bump | |
run: | | |
original_versions="${{ steps.store_original_versions.outputs.original_versions }}" | |
current_versions=$(jq -r '.[] | "\(.version)"' versions_metadata.json) | |
# Logic to compare original versions with current versions and detect bump | |
bumped_packages=() | |
# For example: | |
for package in $current_versions; do | |
if [[ "$package" != *"$original_versions"* ]]; then | |
# Package has been bumped | |
bumped_packages+=("$package") | |
fi | |
done | |
echo "::set-output name=bumped_packages::${bumped_packages[*]}" | |
- name: Bump version and build | |
run: | | |
export BUMP_TYPE=${BUMP_TYPE:-patch} | |
git add src/*/__version__.py | |
git add versions_metadata.json | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Actions" | |
git commit -m "Bump version" | |
git push | |
run-pyinstaller-matrix: | |
strategy: | |
# super important if you want to see all results, even if one fails | |
# fail-fast is true by default | |
fail-fast: false | |
matrix: | |
os: [ubuntu-latest, windows-latest, macOS-latest] | |
# os: [windows-latest] | |
needs: bump_version | |
uses: ./.github/workflows/os_pyinstaller.yaml | |
with: | |
os: ${{ matrix.os }} | |
create-release: | |
runs-on: ubuntu-latest | |
needs: run-pyinstaller-matrix | |
permissions: | |
contents: write | |
steps: | |
# - name: Download | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: 'ubuntu-latestFMD3-API_SingleExe--dist' | |
# path: 'ubuntu/' | |
# continue-on-error: true | |
# - name: Download | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: 'ubuntu-latestFMD3-Client_SingleExe--dist' | |
# path: 'ubuntu/' | |
# continue-on-error: true | |
# - name: Download | |
# uses: actions/download-artifact@v4 | |
# with: | |
# name: 'ubuntu-latestFMD3-WebClient_SingleExe--dist' | |
# path: 'ubuntu/' | |
# continue-on-error: true | |
# windows artifacts | |
- name: Checkout repository | |
uses: actions/checkout@v3 | |
- name: Set outputs | |
id: vars | |
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'windows-latestFMD3-API_SingleExe--dist' | |
path: 'windows/' | |
continue-on-error: true | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'windows-latestFMD3-Client_SingleExe--dist' | |
path: 'windows/' | |
continue-on-error: true | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'windows-latestFMD3-WebClient_SingleExe--dist' | |
path: 'windows/' | |
continue-on-error: true | |
# Linux | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'ubuntu-latestFMD3-API_SingleExe--dist' | |
path: 'ubuntu/' | |
continue-on-error: true | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'ubuntu-latestFMD3-Client_SingleExe--dist' | |
path: 'ubuntu/' | |
continue-on-error: true | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'ubuntu-latestFMD3-WebClient_SingleExe--dist' | |
path: 'ubuntu/' | |
continue-on-error: true | |
# Mac | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'ubuntu-latestFMD3-API_SingleExe--dist' | |
path: 'ubuntu/' | |
continue-on-error: true | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'ubuntu-latestFMD3-Client_SingleExe--dist' | |
path: 'ubuntu/' | |
continue-on-error: true | |
- name: Download | |
uses: actions/download-artifact@v4 | |
with: | |
name: 'macOS-latestFMD3-WebClient_SingleExe--dist' | |
path: 'macOS/' | |
continue-on-error: true | |
- name: Make release | |
uses: ncipollo/release-action@v1 | |
with: | |
prerelease: true | |
artifacts: "windows/*" | |
tag: ${{ steps.vars.outputs.sha_short }} | |
docker: | |
name: Build and push docker image | |
needs: bump_version | |
runs-on: ubuntu-latest | |
if: ${{ github.ref == 'refs/heads/test' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release/alpha') && contains(needs.bump_version.outputs.bumped_packages, 'FMD3_API') }} | |
steps: | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v2 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to DockerHub | |
uses: docker/login-action@v2 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Extract FMD3_API version | |
id: extract_fmd3_api_version | |
run: | | |
fmd3_api_version=$(jq -r '.FMD3_API.version' versions_metadata.json) | |
echo "::set-output name=fmd3_api_version::$fmd3_api_version" | |
- name: Build and push | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
push: true | |
tags: | | |
${{ env.IMAGE_NAME }}:${{ steps.extract_fmd3_api_version.outputs.fmd3_api_version }}, ${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} | |