Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor CI to reusable actions #78

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Build & Deploy

on:
workflow_call:
inputs:
sha-tag:
description: "A short-form SHA tag for the commit that triggered this workflow"
required: true
type: string

jobs:
build:
name: Build & Push Docker image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Login to Github Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
push: ${{ github.ref == 'refs/heads/main' }}
cache-from: type=registry,ref=ghcr.io/python-discord/quackstack:main
cache-to: type=inline
tags: |
ghcr.io/python-discord/quackstack:main
ghcr.io/python-discord/quackstack:${{ inputs.sha-tag }}

deploy:
name: Deploy to Kubernetes
runs-on: ubuntu-latest
if: ${{ github.ref == 'refs/heads/main' }}
steps:
- name: Checkout infra repo for deployment manifest
uses: actions/checkout@v4
with:
repository: python-discord/infra
path: infra

- uses: azure/setup-kubectl@v3

- name: Authenticate with Kubernetes
uses: azure/k8s-set-context@v3
with:
method: kubeconfig
kubeconfig: ${{ secrets.KUBECONFIG }}

- name: Deploy to Kubernetes
uses: azure/k8s-deploy@v4
with:
manifests: |
infra/kubernetes/namespaces/default/quackstack/deployment.yaml
images: 'ghcr.io/python-discord/quackstack:${{ inputs.sha-tag }}'
23 changes: 23 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Lint

on:
workflow_call

jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install Python Dependencies
uses: HassanAbouelela/actions/setup-python@setup-python_v1.4.1
with:
python_version: '3.10'

- name: Run pre-commit hooks
run: SKIP=ruff pre-commit run --all-files

# Run `ruff` using github formatting to enable automatic inline annotations.
- name: Run ruff
run: "ruff check --format=github ."
40 changes: 40 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: CI

on:
push:
branches:
- main
pull_request:


concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true


jobs:

lint:
uses: ./.github/workflows/lint.yml

generate-sha-tag:
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
outputs:
sha-tag: ${{ steps.sha-tag.outputs.sha-tag }}
steps:
- name: Create SHA Container tag
id: sha-tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "sha-tag=$tag" >> $GITHUB_OUTPUT


build:
uses: ./.github/workflows/build-deploy.yml
needs:
- lint
- generate-sha-tag
with:
sha-tag: ${{ needs.generate-sha-tag.outputs.sha-tag }}
secrets: inherit
99 changes: 0 additions & 99 deletions .github/workflows/quackstack.yml

This file was deleted.