Skip to content

Commit

Permalink
Refactor CI to reusable actions
Browse files Browse the repository at this point in the history
This also removes deprecated set-output calls
  • Loading branch information
ChrisLovering committed Sep 5, 2023
1 parent 846e47b commit 3ec6591
Show file tree
Hide file tree
Showing 4 changed files with 128 additions and 99 deletions.
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-test:
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-deploy:
uses: ./.github/workflows/build-deploy.yml
needs:
- lint-test
- 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.

0 comments on commit 3ec6591

Please sign in to comment.