From bafeb20d856ab8bf650c2b968b1efc2bbfa1fd81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sch=C3=B6nfeldt?= Date: Tue, 8 Oct 2024 21:24:41 +0200 Subject: [PATCH] Copy GitHub workflows from solph Taken from oemof-solph commit 0b03a258fd6973ccd36bde9b4d1be285b87d81e7. --- .github/workflows/codeql.yml | 44 ++++++++++++++++++++++++ .github/workflows/lint.yml | 38 +++++++++++++++++++++ .github/workflows/packaging.yml | 40 ++++++++++++++++++++++ .github/workflows/tox_checks.yml | 57 +++++++++++++++++++++++++++++++ .github/workflows/tox_pytests.yml | 44 ++++++++++++++++++++++++ 5 files changed, 223 insertions(+) create mode 100644 .github/workflows/codeql.yml create mode 100644 .github/workflows/lint.yml create mode 100644 .github/workflows/packaging.yml create mode 100644 .github/workflows/tox_checks.yml create mode 100644 .github/workflows/tox_pytests.yml diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml new file mode 100644 index 00000000..624ae6f2 --- /dev/null +++ b/.github/workflows/codeql.yml @@ -0,0 +1,44 @@ +name: "CodeQL" + +on: + push: + branches: + - dev + - master + - 'release/**' + pull_request: + branches: [ "dev" ] + schedule: + - cron: "23 2 * * 2" + +jobs: + analyze: + name: Analyze + runs-on: ubuntu-latest + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ python ] + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v2 + with: + languages: ${{ matrix.language }} + queries: +security-and-quality + + - name: Autobuild + uses: github/codeql-action/autobuild@v2 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v2 + with: + category: "/language:${{ matrix.language }}" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..3e5f7315 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,38 @@ +name: Black + +on: + push: + branches: + - master + - dev + - 'release/**' + pull_request: + +jobs: + run-linters: + name: Run linters + runs-on: ubuntu-latest + + steps: + - name: Check out Git repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + + - name: Install Python dependencies + run: pip install black flake8 + + - name: Run linters + uses: samuelmeuli/lint-action@v1 + with: + github_token: ${{ secrets.github_token }} + # Enable linters + black: true + flake8: false + # Mark the following line true if you want linters to attempt to autocorrect your code + auto_fix: false + git_name: "Greene Lab Linter" + git_email: "csgreene@upenn.edu" diff --git a/.github/workflows/packaging.yml b/.github/workflows/packaging.yml new file mode 100644 index 00000000..a09540cf --- /dev/null +++ b/.github/workflows/packaging.yml @@ -0,0 +1,40 @@ +name: packaging + +on: + # Make sure packaging process is not broken + push: + branches: + - master + - dev + - 'release/**' + pull_request: + # Make a package for release + release: + types: [published] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.9] + + steps: + - uses: actions/checkout@v1 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip setuptools setuptools_scm twine wheel build + - name: Create packages + run: python -m build . + - name: Run twine check + run: twine check dist/* + - uses: actions/upload-artifact@v4 + with: + name: tox-gh-actions-dist + path: dist diff --git a/.github/workflows/tox_checks.yml b/.github/workflows/tox_checks.yml new file mode 100644 index 00000000..5553b0ac --- /dev/null +++ b/.github/workflows/tox_checks.yml @@ -0,0 +1,57 @@ +# NB: this name is used in the status badge +name: tox checks + +on: + push: + branches: + - master + - dev + - 'release/**' + pull_request: + + workflow_dispatch: + schedule: + - cron: "0 5 * * 6" # 5:00 UTC every Saturday + +jobs: + lint: + name: ${{ matrix.toxenv }} + runs-on: ubuntu-latest + + strategy: + matrix: + toxenv: + - clean + - check + - docs + + steps: + - name: Update package list + run: sudo apt update + - name: Install LaTeX + run: sudo apt install dvipng rubber texlive-latex-extra + - name: Git clone + uses: actions/checkout@v2 + + - name: Set up Python ${{ env.default_python || '3.9' }} + uses: actions/setup-python@v5 + with: + python-version: "${{ env.default_python || '3.9' }}" + + - name: Pip cache + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ matrix.toxenv }}-${{ hashFiles('tox.ini', 'setup.py') }} + restore-keys: | + ${{ runner.os }}-pip-${{ matrix.toxenv }}- + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install -U pip + python -m pip install -U setuptools wheel build + python -m pip install -U tox + + - name: Run ${{ matrix.toxenv }} + run: python -m tox -e ${{ matrix.toxenv }} diff --git a/.github/workflows/tox_pytests.yml b/.github/workflows/tox_pytests.yml new file mode 100644 index 00000000..a28cb482 --- /dev/null +++ b/.github/workflows/tox_pytests.yml @@ -0,0 +1,44 @@ +name: tox pytests + +on: + push: + branches: + - master + - dev + - 'release/**' + pull_request: + + workflow_dispatch: + schedule: + - cron: "0 5 * * 6" # 5:00 UTC every Saturday + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [3.9, "3.10", "3.11"] + + steps: + - uses: actions/checkout@v1 + - name: Install cbc + run: sudo apt install coinor-cbc + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install tox tox-gh-actions coverage coveralls + - name: Test with tox + run: tox + + - name: Check test coverage + run: coverage report -m --fail-under=${{ matrix.vcs == 'bzr' && 84 || 85 }} + + - name: Report to coveralls + run: coveralls + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COVERALLS_SERVICE_NAME: github