From e9287244bf8b222e4e694a48d6733c0daa9b76a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Fri, 21 Jul 2023 13:10:49 +0100 Subject: [PATCH] fix workflows --- .github/workflows/build.yaml | 105 ++++++++++++++++------- .github/workflows/coverage_and_lint.yaml | 55 ++++++++---- 2 files changed, 112 insertions(+), 48 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 09c8da0..8c3dc15 100755 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -4,51 +4,84 @@ name: Build on: push: - branches: - - main tags: - - '*.*.*' - pull_request: - branches: - - main + - "*.*.*" + workflow_run: + workflows: ["Type Coverage and Linting"] + types: [completed] + branches: [main] jobs: build: - name: Build + if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest - strategy: + fail-fast: false matrix: - python-version: [ "3.11" ] + python-version: ["3.11", "3.x"] + name: "Build @ ${{ matrix.python-version }}" steps: - - name: Checkout source - uses: actions/checkout@v2 + - name: "Checkout Repository" + uses: actions/checkout@v3 + with: + fetch-depth: 0 - - name: "Set up Python ${{ matrix.python-version }}" - uses: actions/setup-python@v1 + - name: "Load cached poetry installation @ ${{ matrix.python-version }}" + id: cached-poetry + uses: actions/cache@v3 + with: + path: ~/.local + key: poetry-0 + + - name: "Setup Poetry @ ${{ matrix.python-version }}" + if: steps.cached-poetry.outputs.cache-hit != 'true' + uses: snok/install-poetry@v1 + with: + version: latest + virtualenvs-create: true + virtualenvs-in-project: true + virtualenvs-path: .venv + + - name: "Setup Python @ ${{ matrix.python-version }}" + id: setup-python + uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python-version }} + python-version: "${{ matrix.python-version }}" + cache: "poetry" - - name: "Set up Poetry ${{ matrix.python-version }}" - uses: Gr1N/setup-poetry@v7 + - name: "Load cached venv @ ${{ matrix.python-version }}" + id: cached-pip-wheels + uses: actions/cache@v3 with: - poetry-preview: true + path: .venv/ + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - - name: "Install Python deps ${{ matrix.python-version }}" + - name: "Install Python deps @ ${{ matrix.python-version }}" + if: ${{ steps.cached-pip-wheels.outputs.cache-hit != 'true' }} + id: install-deps run: | - poetry install --all-extras + poetry install --no-interaction - - name: "Check it imports ${{ matrix.python-version }}" + - name: Activate venv @ ${{ matrix.python-version }} + run: | + echo "$(poetry env info --path)/bin" >> $GITHUB_PATH + + - name: "Check it imports @ ${{ matrix.python-version }}" run: | poetry run python -c 'import mystbin' - - name: "Build wheels ${{ matrix.python-version }}" + - name: "Build wheels @ ${{ matrix.python-version}}" run: | poetry build - - name: "Upload artifacts ${{ matrix.python-version }}" - uses: actions/upload-artifact@v2 + - name: "Build docs @ ${{ matrix.python-version}}" + run: | + cd docs/ + poetry run sphinx-build -aETW --keep-going . build + + - name: "Upload artifacts @ ${{ matrix.python-version}}" + uses: actions/upload-artifact@v3 with: name: distributions path: dist/* @@ -56,13 +89,13 @@ jobs: # Credits to most of this step go to Gorialis (Devon R [https://github.com/Gorialis]) # as I found them in their Jishaku builds (https://github.com/Gorialis/jishaku/blob/d3f50749b5a977b544e5fd14894585f656247486/.github/workflows/deploy.yml#L82-L119) create_release: - needs: [ build ] + name: Create Release + needs: [build] runs-on: ubuntu-latest if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags/') steps: - - name: Checkout Repository - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 submodules: true @@ -73,10 +106,24 @@ jobs: name: distributions path: dist - - name: Set up Poetry - uses: Gr1N/setup-poetry@v7 + - name: Create GitHub release + shell: bash + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -x + assets=() + for asset in ./dist/*.{whl,tar.gz}; do + assets+=("-a" "$asset") + done + tag_name="${GITHUB_REF##*/}" + hub release create "${assets[@]}" -F "CHANGELOG.md" "$tag_name" + + - name: "Set up Poetry" + uses: snok/install-poetry@v1 with: - poetry-preview: true + virtualenvs-create: true + virtualenvs-in-project: false - name: Publish to PyPI env: diff --git a/.github/workflows/coverage_and_lint.yaml b/.github/workflows/coverage_and_lint.yaml index e14bd6a..39e2ec3 100755 --- a/.github/workflows/coverage_and_lint.yaml +++ b/.github/workflows/coverage_and_lint.yaml @@ -7,9 +7,7 @@ on: pull_request: branches: - main - types: - - opened - - synchronize + types: [opened, reopened, synchronize] jobs: job: @@ -26,37 +24,56 @@ jobs: with: fetch-depth: 0 + - name: "Load cached poetry installation @ ${{ matrix.python-version }}" + id: cached-poetry + uses: actions/cache@v3 + with: + path: ~/.local + key: poetry-0 + - name: "Setup Poetry @ ${{ matrix.python-version }}" + if: steps.cached-poetry.outputs.cache-hit != 'true' uses: snok/install-poetry@v1 with: - version: 1.2.0b2 + version: latest virtualenvs-create: true - virtualenvs-in-project: false + virtualenvs-in-project: true + virtualenvs-path: .venv - name: "Setup Python @ ${{ matrix.python-version }}" - uses: actions/setup-python@v3 + id: setup-python + uses: actions/setup-python@v4 with: python-version: "${{ matrix.python-version }}" + cache: "poetry" + + - name: "Load cached venv @ ${{ matrix.python-version }}" + id: cached-pip-wheels + uses: actions/cache@v3 + with: + path: .venv/ + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - name: "Install Python deps @ ${{ matrix.python-version }}" - env: - PY_VER: "${{ matrix.python-version }}" + if: ${{ steps.cached-pip-wheels.outputs.cache-hit != 'true' }} + id: install-deps run: | - poetry env use "$PY_VER" - poetry install --all-extras --no-interaction + poetry install --without=dev --no-interaction - - uses: actions/setup-node@v3 - with: - node-version: "17" - - run: npm install --location=global pyright@latest - - - name: "Type Coverage @ ${{ matrix.python-version }}" + - name: Activate venv @ ${{ matrix.python-version }} run: | - poetry run pyright - poetry run pyright --ignoreexternal --lib --verifytypes mystbin + echo "$(poetry env info --path)/bin" >> $GITHUB_PATH + + - name: "Run Pyright @ ${{ matrix.python-version }}" + uses: jakebailey/pyright-action@v1 + with: + warnings: false + verify-types: "mystbin" + ignore-external: true + no-comments: ${{ matrix.python-version != '3.x' }} - name: Lint - if: ${{ github.event_name != 'pull_request' }} + if: ${{ always() && steps.install-deps.outcome == 'success' }} uses: github/super-linter/slim@v4 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}