Skip to content

Commit

Permalink
Add CI/CD (#3)
Browse files Browse the repository at this point in the history
* Publish mkdocs to github action on every update

* Publish mkdocs to github action on every update

* Run linters and tests for each push

* Add release flow with publishing to pypi

* Extend python matrix

* Add names for jobs

* Use script instead of direct run

* Remove fail-fast for matrix run

* Few fixes

Co-authored-by: Ivan Dmitrievsky <ivan.dmitrievsky@gmail.com>
  • Loading branch information
b0g3r and idmitrievsky authored May 3, 2021
1 parent 82aa126 commit 65a1bd2
Show file tree
Hide file tree
Showing 10 changed files with 231 additions and 3 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Checks
on:
push:

jobs:
run-checks:
name: Run checks 🧪
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python:
- '3.7'
- '3.8'
- '3.9'
env:
PYTHON_VERSION: ${{ matrix.python }}
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Set up Python 🐍
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Poetry virtualenv 💾
uses: actions/cache@v1
id: poetry-cache
with:
path: .venv
key: poetry-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry 📖
run: |
pip install poetry
poetry config virtualenvs.in-project true
- name: Install dependencies 📌
if: steps.poetry-cache.outputs.cache-hit != 'true'
run: |
poetry install
- name: Run checks 🧪
run: |
poetry run scripts/test.sh
108 changes: 108 additions & 0 deletions .github/workflows/docs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Docs
on:
push:
branches:
- master
pull_request:

env:
PYTHON_VERSION: 3.9

jobs:
build-docs:
name: Build docs 🏗
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Set up Python 🐍
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Poetry virtualenv 💾
uses: actions/cache@v1
id: poetry-cache
with:
path: .venv
key: poetry-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry 📖
run: |
pip install poetry
poetry config virtualenvs.in-project true
- name: Install dependencies 📌
if: steps.poetry-cache.outputs.cache-hit != 'true'
run: |
poetry install
- name: Build docs 🏗
run: |
poetry run scripts/docs-build.sh
- name: Upload build to artifact ☁️
uses: actions/upload-artifact@v2
with:
name: mkdocs-build
path: site
if-no-files-found: error

deploy-docs-prod:
name: Deploy docs to Pages 🧐
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/master'
needs:
- build-docs
steps:
- name: Download build from artifact 🌨
uses: actions/download-artifact@v1
with:
name: mkdocs-build

- name: Deploy docs to Pages 🧐
uses: JamesIves/github-pages-deploy-action@4.1.1
with:
branch: gh-pages
folder: mkdocs-build


deploy-docs-preview:
name: Deploy docs to Surge 🧐 [preview]
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
needs:
- build-docs
steps:
- name: Download build from artifact 🌨
uses: actions/download-artifact@v1
with:
name: mkdocs-build

- name: Publish to Surge 🧐 [preview]
id: publish-preview
env:
SURGE_LOGIN: dev@eventual.com
SURGE_TOKEN: 5ed7fcac90fac92170a28e638c01219b
run: |
pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
deploy_host="${pr_number}-eventual-review.surge.sh"
npx surge mkdocs-build $deploy_host
echo "::set-output name=deploy-url::https://$deploy_host"
- name: Find existing comment 🔎
id: find-comment
uses: peter-evans/find-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'github-actions[bot]'
body-includes: preview version of docs

- name: Comment PR ✨
if: steps.find-comment.outputs.comment-id == ''
uses: peter-evans/create-or-update-comment@v1
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
This is a preview version of docs: ${{ steps.publish-preview.outputs.deploy-url }}
56 changes: 56 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Release

on:
release:
types:
- 'published'

env:
PYTHON_VERSION: 3.9

jobs:
build-and-publish:
name: Build and publish package 📦
runs-on: ubuntu-latest
steps:
- name: Checkout 🛎️
uses: actions/checkout@v2

- name: Set up Python 🐍
uses: actions/setup-python@v2
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Cache Poetry virtualenv 💾
uses: actions/cache@v1
id: poetry-cache
with:
path: .venv
key: poetry-${{ env.PYTHON_VERSION }}-${{ hashFiles('**/poetry.lock') }}

- name: Install Poetry 📖
run: |
pip install poetry
poetry config virtualenvs.in-project true
- name: Install dependencies 📌
if: steps.poetry-cache.outputs.cache-hit != 'true'
run: |
poetry install
- name: Build package 📦
run: |
poetry run scripts/build.sh
- name: Upload package build to artifacts ☁️
uses: actions/upload-artifact@v2
with:
name: package
path: dist
if-no-files-found: error

- name: Publish package ⬆️
run: |
poetry run scripts/publish.sh
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
1 change: 0 additions & 1 deletion scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,3 @@
set -x

poetry build
mkdocs build
2 changes: 1 addition & 1 deletion scripts/coverage.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

set -x

coverage report --show-missing --skip-covered --fail-under=100
coverage report
5 changes: 5 additions & 0 deletions scripts/docs-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -e

set -x

mkdocs build
File renamed without changes.
5 changes: 5 additions & 0 deletions scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh -e

set -x

poetry publish
2 changes: 1 addition & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
set -ex

scripts/check.sh
coverage run -m pytest
coverage run -m pytest tests
scripts/coverage.sh
9 changes: 9 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,12 @@ max-line-length = 120
[mypy]
disallow_untyped_defs = True
ignore_missing_imports = True

[coverage:run]
source = eventual
branch = True

[coverage:report]
precision = 2
show_missing = True
skip_covered = True

0 comments on commit 65a1bd2

Please sign in to comment.