aboutsummaryrefslogtreecommitdiffstats
path: root/.github
diff options
context:
space:
mode:
authorGravatar Joe Banks <[email protected]>2021-07-17 20:10:11 +0100
committerGravatar Joe Banks <[email protected]>2021-07-17 20:10:11 +0100
commitd3d81582cd7005df16fe3f5306e6afbed75bdb74 (patch)
tree323a7441f6c4d32833fee922208121497c77a9de /.github
Initial commit
Diffstat (limited to '.github')
-rw-r--r--.github/workflows/lint-build-deploy.yaml155
1 files changed, 155 insertions, 0 deletions
diff --git a/.github/workflows/lint-build-deploy.yaml b/.github/workflows/lint-build-deploy.yaml
new file mode 100644
index 0000000..344b7ed
--- /dev/null
+++ b/.github/workflows/lint-build-deploy.yaml
@@ -0,0 +1,155 @@
+name: Lint, Build & Deploy
+
+on:
+ push:
+ branches:
+ - main
+ pull_request:
+
+
+jobs:
+ lint:
+ name: Lint
+ runs-on: ubuntu-latest
+ env:
+ # Configure pip to cache dependencies and do a user install
+ PIP_NO_CACHE_DIR: false
+ PIP_USER: 1
+
+ # Make sure package manager does not use virtualenv
+ POETRY_VIRTUALENVS_CREATE: false
+
+ # Specify explicit paths for python dependencies and the pre-commit
+ # environment so we know which directories to cache
+ POETRY_CACHE_DIR: ${{ github.workspace }}/.cache/py-user-base
+ PYTHONUSERBASE: ${{ github.workspace }}/.cache/py-user-base
+ PRE_COMMIT_HOME: ${{ github.workspace }}/.cache/pre-commit-cache
+
+ steps:
+ - name: Add custom PYTHONUSERBASE to PATH
+ run: echo '${{ env.PYTHONUSERBASE }}/bin/' >> $GITHUB_PATH
+
+ - name: Checkout repository
+ uses: actions/checkout@v2
+
+ - name: Setup python
+ id: python
+ uses: actions/setup-python@v2
+ with:
+ python-version: '3.9'
+
+ # This step caches our Python dependencies. To make sure we
+ # only restore a cache when the dependencies, the python version,
+ # the runner operating system, and the dependency location haven't
+ # changed, we create a cache key that is a composite of those states.
+ #
+ # Only when the context is exactly the same, we will restore the cache.
+ - name: Python Dependency Caching
+ uses: actions/cache@v2
+ id: python_cache
+ with:
+ path: ${{ env.PYTHONUSERBASE }}
+ key: "python-0-${{ runner.os }}-${{ env.PYTHONUSERBASE }}-\
+ ${{ steps.python.outputs.python-version }}-\
+ ${{ hashFiles('./pyproject.toml', './poetry.lock') }}"
+
+ # Install our dependencies if we did not restore a dependency cache
+ - name: Install dependencies using poetry
+ if: steps.python_cache.outputs.cache-hit != 'true'
+ run: |
+ pip install poetry
+ poetry install
+
+ # Run flake8 and have it format the linting errors in the format of
+ # the GitHub Workflow command to register error annotations. This
+ # means that our flake8 output is automatically added as an error
+ # annotation to both the run result and in the "Files" tab of a
+ # pull request.
+ #
+ # Format used:
+ # ::error file={filename},line={line},col={col}::{message}
+ - name: Run flake8
+ run: "flake8 \
+ --format='::error file=%(path)s,line=%(row)d,col=%(col)d::\
+ [flake8] %(code)s: %(text)s'"
+
+ build:
+ if: github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'push'
+ name: Build & Push
+ runs-on: ubuntu-latest
+
+ steps:
+ # Create a commit SHA-based tag for the container repositories
+ - name: Create SHA Container Tag
+ id: sha_tag
+ run: |
+ tag=$(cut -c 1-7 <<< $GITHUB_SHA)
+ echo "::set-output name=tag::$tag"
+ - name: Checkout code
+ uses: actions/checkout@v2
+
+ # The current version (v2) of Docker's build-push action uses
+ # buildx, which comes with BuildKit features that help us speed
+ # up our builds using additional cache features. Buildx also
+ # has a lot of other features that are not as relevant to us.
+ #
+ # See https://github.com/docker/build-push-action
+ - name: Set up Docker Buildx
+ uses: docker/setup-buildx-action@v1
+
+ - name: Login to Github Container Registry
+ uses: docker/login-action@v1
+ with:
+ registry: ghcr.io
+ username: ${{ github.repository_owner }}
+ password: ${{ secrets.GITHUB_TOKEN }}
+
+ # Build and push the container to the GitHub Container
+ # Repository. The container will be tagged as "latest"
+ # and with the short SHA of the commit.
+ - name: Build and push
+ uses: docker/build-push-action@v2
+ with:
+ context: .
+ file: ./Dockerfile
+ push: true
+ cache-from: type=registry,ref=ghcr.io/python-discord/king-arthur:latest
+ cache-to: type=inline
+ tags: |
+ ghcr.io/python-discord/king-arthur:latest
+ ghcr.io/python-discord/king-arthur:${{ steps.sha_tag.outputs.tag }}
+ build-args: |
+ git_sha=${{ github.sha }}
+
+ # build:
+ # environment: production
+ # if: github.event.workflow_run.conclusion == 'success'
+ # name: Build & Push
+ # runs-on: ubuntu-latest
+
+ # steps:
+ # - name: Create SHA Container Tag
+ # id: sha_tag
+ # run: |
+ # tag=$(cut -c 1-7 <<< $GITHUB_SHA)
+ # echo "::set-output name=tag::$tag"
+
+ # - name: Checkout code
+ # uses: actions/checkout@v2
+ # with:
+ # repository: python-discord/kubernetes
+ # token: ${{ secrets.REPO_TOKEN }}
+
+ # - name: Authenticate with Kubernetes
+ # uses: azure/k8s-set-context@v1
+ # with:
+ # method: kubeconfig
+ # kubeconfig: ${{ secrets.KUBECONFIG }}
+
+ # - name: Deploy to Kubernetes
+ # uses: Azure/k8s-deploy@v1
+ # with:
+ # manifests: |
+ # king-arthur/deployment.yaml
+ # images: 'ghcr.io/python-discord/king-arthur:${{ steps.sha_tag.outputs.tag }}'
+ # kubectl-version: 'latest'