From 3456159e84b9a1c35aa1a97f6adbb7062ae0fd4c Mon Sep 17 00:00:00 2001 From: Wyatt Stanke Date: Mon, 26 Feb 2024 17:38:21 -0500 Subject: [PATCH] Universal setup action --- .github/{ => library/setup}/action.yml | 22 ++++++++++++++++------ .github/workflows/RELEASE.yml | 9 +-------- .github/workflows/docs.yml | 5 +---- .github/workflows/lint.yml | 8 +++----- .github/workflows/pylint.yml | 6 +----- .github/workflows/python-app.yml | 11 +---------- .github/workflows/python-package.yml | 10 +--------- .github/workflows/python-publish.yml | 10 +--------- .github/workflows/test.yml | 9 +-------- .github/workflows/test_pr.yml | 10 ++-------- .github/workflows/testing.yml | 7 +------ .github/workflows/unit-test.yml | 8 +------- 12 files changed, 30 insertions(+), 85 deletions(-) rename .github/{ => library/setup}/action.yml (66%) diff --git a/.github/action.yml b/.github/library/setup/action.yml similarity index 66% rename from .github/action.yml rename to .github/library/setup/action.yml index 9de56b99..b9f509c7 100644 --- a/.github/action.yml +++ b/.github/library/setup/action.yml @@ -1,15 +1,20 @@ ---- -name: "Init Environment" -description: "Initialize environment for tests" +name: "Setup" +description: Setup the environment for the project +inputs: + python-version: + description: "Python version to use" + required: false + default: "3.10" + runs: using: "composite" steps: - name: Checkout actions - uses: actions/checkout@v3 - - name: Set up Python ${{ matrix.python-version }} + uses: actions/checkout@v4 + - name: Set up Python ${{ inputs.python-version }} uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: ${{ inputs.python-version }} - name: Install and configure Poetry uses: snok/install-poetry@v1 with: @@ -31,3 +36,8 @@ runs: source .venv/bin/activate echo PATH=$PATH >> $GITHUB_ENV shell: bash + - name: "Install apt dependencies" + run: | + sudo apt-get update + sudo apt-get install -y python3-opencv + shell: bash diff --git a/.github/workflows/RELEASE.yml b/.github/workflows/RELEASE.yml index 0ca7dacd..af0886b5 100644 --- a/.github/workflows/RELEASE.yml +++ b/.github/workflows/RELEASE.yml @@ -17,14 +17,7 @@ jobs: && ${{ contains(github.event.pull_request.labels.*.name, 'release') }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install poetry - run: pipx install poetry==$POETRY_VERSION - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: "3.10" - cache: "poetry" + - uses: ./.github/library/setup - name: Build project for distribution run: poetry build - name: Check Version diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index b4b08dc4..7bc21b69 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,10 +10,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: 3.x + - uses: ./.github/library/setup - run: pip install mkdocs-material - run: pip install mkdocs-glightbox - run: pip install "mkdocstrings[python]" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 06d57c82..02aea862 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -5,21 +5,19 @@ jobs: yaml-lint: runs-on: ubuntu-latest steps: - - name: Check out source repository - uses: actions/checkout@v4 + - uses: ./.github/library/setup - name: yaml Lint uses: ibiqlik/action-yamllint@v3 flake8-lint: runs-on: ubuntu-latest name: flake8 Lint steps: - - name: Check out source repository - uses: actions/checkout@v4 + - uses: ./.github/library/setup - name: Set up Python environment uses: py-actions/flake8@v2 ruff-lint: runs-on: ubuntu-latest name: ruff Lint steps: - - uses: actions/checkout@v4 + - uses: ./.github/library/setup - uses: chartboost/ruff-action@v1 diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 8b8aa175..9f336274 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -8,11 +8,7 @@ jobs: matrix: python-version: ["3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.python-version }} + - uses: ./.github/library/setup - name: Install dependencies run: | python -m pip install --upgrade pip diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index f6aef90b..4a3b00b0 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -14,16 +14,7 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python 3.10 - uses: actions/setup-python@v5 - with: - python-version: "3.10" - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install flake8 pytest swarms - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - uses: ./.github/library/setup - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index 49e6b9a1..fc303c9a 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -16,17 +16,9 @@ jobs: matrix: python-version: ["3.10", "3.11", "3.12"] steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v5 + - uses: ./.github/library/setup with: python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - python -m pip install --upgrade pip - python -m pip install --upgrade swarms - python -m pip install flake8 pytest swarms - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - name: Lint with flake8 run: | # stop the build if there are Python syntax errors or undefined names diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index 429829f1..e2b9bdd7 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -9,15 +9,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - name: Install dependencies - run: | - python -m pip install --upgrade pip - pip install build + - uses: ./.github/library/setup - name: Build package run: python -m build - name: Publish package diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f0596c9b..ab4f4927 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -14,15 +14,8 @@ jobs: - "3.10" - "3.11" steps: - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.python-version }} - id: setup-python - uses: actions/setup-python@v4 + - uses: ./.github/library/setup with: python-version: ${{ matrix.python-version }} - - name: Set up Poetry - uses: "snok/install-poetry@v1" - - name: Install dependencies - run: poetry install --no-root --no-interaction - name: Run tests run: pytest diff --git a/.github/workflows/test_pr.yml b/.github/workflows/test_pr.yml index a6b12c7b..4e6a9e20 100644 --- a/.github/workflows/test_pr.yml +++ b/.github/workflows/test_pr.yml @@ -15,10 +15,7 @@ jobs: name: pytype 3.10 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.10" + - uses: ./.github/library/setup - name: Run pytype run: | python --version @@ -29,10 +26,7 @@ jobs: name: Check format with black runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - uses: actions/setup-python@v5 - with: - python-version: "3.11" + - uses: ./.github/library/setup - name: Check format run: | python --version diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index 554798ef..42ffb5bd 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -8,15 +8,10 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v4 + - uses: ./.github/library/setup - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.10" - - name: Install dependencies - run: | - pip install -r requirements.txt - pip install pytest - name: Run unit tests run: pytest diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index ac73b282..efd398c6 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -9,16 +9,10 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Setup Python - uses: actions/setup-python@v5 - with: - python-version: "3.10" + - uses: ./.github/library/setup - name: Install dependencies run: | - pip install -r requirements.txt pip install pytest - pip install swarms - name: Run Python unit tests run: pytest - name: Verify that the Docker image for the action builds