From 28a134ea856e6a1b20966e4329da67e7bb08f65c Mon Sep 17 00:00:00 2001 From: Rasmus Handberg Date: Tue, 29 Jun 2021 11:58:21 +0200 Subject: [PATCH] Updates to CI/CD --- .github/workflows/deploy.yml | 62 ------------------ .github/workflows/tests.yml | 124 +++++++++++++++++++++++++++++++---- 2 files changed, 113 insertions(+), 73 deletions(-) delete mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml deleted file mode 100644 index 4c21af7..0000000 --- a/.github/workflows/deploy.yml +++ /dev/null @@ -1,62 +0,0 @@ -# GitHub Actions workflow for Flows's deployment. - -name: Deploy - -# Run this action every time a tagged push is done. -# TODO: Only run this action after testing has completed -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -jobs: - release: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Setup Python 3.7 - uses: actions/setup-python@v2 - with: - python-version: 3.7 - - - name: Cache pip - uses: actions/cache@v2 - with: - path: ~/.cache/pip - key: ${{ runner.os }}-pip-py3.7-${{ hashFiles('requirements.txt') }} - restore-keys: | - ${{ runner.os }}-pip-py3.7- - ${{ runner.os }}-pip- - - - name: Install dependencies - run: | - python -m pip install --upgrade pip - grep "numpy" requirements.txt | xargs -I {} pip install "{}" - pip install -r requirements.txt - - - name: Update VERSION file - run: python -c "from flows import version; version.update_release_version();" - - - name: Generate changelog - id: changelog - uses: metcalfc/changelog-generator@v1.0.0 - with: - myToken: ${{ secrets.GITHUB_TOKEN }} - - - name: Create Release - id: create_release - uses: actions/create-release@v1 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - with: - tag_name: ${{ github.ref }} - release_name: Version ${GITHUB_REF##*/} - body: | - Version ${GITHUB_REF##*/} - ${{ steps.changelog.outputs.changelog }} - draft: true diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 74d0130..a1d3c0d 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -12,13 +12,57 @@ on: - cron: '0 6 1 * *' # once a month in the morning jobs: + # Use the `flake8` tool to check for syntax errors + flake8: + name: Flake8 + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup Python 3.7 + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-py3.7-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-py3.7- + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip wheel + grep "numpy" requirements.txt | xargs -I {} pip install "{}" + pip install -r requirements.txt + + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + # For some reason we have to specifically ignore G001 as well + flake8 --select=E9,F63,F7,F82 --ignore=G001 --show-source + # exit-zero treats all errors as warnings. + flake8 --exit-zero + # Run unit tests on Linux, OSX and Windows pytest: + needs: flake8 strategy: fail-fast: false matrix: os: [ubuntu-latest, macos-latest, windows-latest] python-version: [3.6, 3.7, 3.8] + include: + - os: ubuntu-latest + pippath: ~/.cache/pip + - os: macos-latest + pippath: ~/Library/Caches/pip + - os: windows-latest + pippath: ~\AppData\Local\pip\Cache name: Python ${{ matrix.python-version }} on ${{ matrix.os }} runs-on: ${{ matrix.os }} @@ -33,11 +77,33 @@ jobs: with: fetch-depth: 0 + - name: Create LFS file list + run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id + + - name: Restore LFS cache + uses: actions/cache@v2 + id: lfs-cache + with: + path: .git/lfs + key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1 + + - name: Git LFS Pull + run: git lfs pull + - name: Setup Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} + - name: Cache pip + uses: actions/cache@v2 + with: + path: ${{ matrix.pippath }} + key: ${{ runner.os }}-pip-py${{ matrix.python-version }}-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-py${{ matrix.python-version }}- + ${{ runner.os }}-pip- + - name: Install dependencies run: | python -m pip install --upgrade pip wheel @@ -53,30 +119,66 @@ jobs: with: env_vars: OS,PYTHON - - # Use the `flake8` tool to check for syntax errors - flake8: - name: Flake8 + # Release tagged commits to: + release: + name: Create release + if: startsWith( github.ref, 'refs/tags/v' ) + needs: pytest runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Create LFS file list + run: git lfs ls-files -l | cut -d' ' -f1 | sort > .lfs-assets-id + + - name: Restore LFS cache + uses: actions/cache@v2 + id: lfs-cache + with: + path: .git/lfs + key: ${{ runner.os }}-lfs-${{ hashFiles('.lfs-assets-id') }}-v1 + + - name: Git LFS Pull + run: git lfs pull - name: Setup Python 3.7 uses: actions/setup-python@v2 with: python-version: 3.7 + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-py3.7-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip-py3.7- + ${{ runner.os }}-pip- + - name: Install dependencies run: | python -m pip install --upgrade pip wheel grep "numpy" requirements.txt | xargs -I {} pip install "{}" pip install -r requirements.txt - - name: Lint with flake8 - run: | - # stop the build if there are Python syntax errors or undefined names - # For some reason we have to specifically ignore G001 as well - flake8 --select=E9,F63,F7,F82 --ignore=G001 --show-source - # exit-zero treats all errors as warnings. - flake8 --exit-zero + - name: Update VERSION file + run: python -c "from flows import version; version.update_release_version();" + + - name: Set env + id: vars + run: echo ::set-output name=tag::${GITHUB_REF#refs/tags/v} + + - name: Create Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: Version ${{ steps.vars.outputs.tag }} + body: | + Version ${{ steps.vars.outputs.tag }} + draft: true