Skip to content

Commit

Permalink
Update CI to support mono repo
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisLovering committed Aug 16, 2024
1 parent 71d1ea5 commit 4b5f2e2
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ on:
description: "A short-form SHA tag for the commit that triggered this flow"
required: true
type: string
lower-repo:
description: "The repository name in lowercase"
required: true
type: string
project:
description: "The project to build and push"
required: true
type: string

jobs:
build:
name: Build & Push
runs-on: ubuntu-latest

steps:

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

Expand All @@ -31,12 +30,14 @@ jobs:
# 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@v5
uses: docker/build-push-action@v6
with:
push: ${{ github.ref == github.event.repository.default_branch }}
cache-from: type=registry,ref=ghcr.io/${{ inputs.lower-repo }}:latest
context: thallium-${{ inputs.project }}
push: ${{ github.ref == 'refs/heads/main' }}
cache-from: type=registry,ref=ghcr.io/owl-corp/thallium-${{ inputs.project }}:latest
cache-to: type=inline
tags: |
ghcr.io/${{ inputs.lower-repo }}:latest
ghcr.io/${{ inputs.lower-repo }}:${{ inputs.sha-tag }}
build-args: git_sha=${{ github.sha }}
ghcr.io/owl-corp/thallium-${{ inputs.project }}:latest
ghcr.io/owl-corp/thallium-${{ inputs.project }}:${{ inputs.sha-tag }}
build-args: |
git_sha=${{ github.sha }}
4 changes: 2 additions & 2 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ jobs:
run: |
poetry export --output temp-requirements.txt -vvv
if ! cmp -s "requirements.txt" "temp-requirements.txt"; then
echo "::error file=requirements.txt,title=Requirements out of date!::Run 'poetry export --output requirements.txt'"
if ! cmp -s "thallium-backend/requirements.txt" "temp-requirements.txt"; then
echo "::error file=requirements.txt,title=Requirements out of date!::Run 'make lock'"
exit 1
fi
Expand Down
36 changes: 23 additions & 13 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,46 @@ concurrency:
cancel-in-progress: true

jobs:
changes:
runs-on: ubuntu-latest
outputs:
backend: ${{ steps.changes.outputs.backend }}
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
id: changes
with:
filters: |
automation: &automation
- '.github/workflows/**'
- 'deployments/**'
backend:
- *automation
- 'thallium-backend/**'
generate-inputs:
runs-on: ubuntu-latest
defaults:
run:
shell: bash

outputs:
sha-tag: ${{ steps.sha-tag.outputs.sha-tag }}
lower-repo: ${{ steps.lower-repo.outputs.lower-repo }}

steps:
- name: Create SHA Container Tag
id: sha-tag
run: |
tag=$(cut -c 1-7 <<< $GITHUB_SHA)
echo "sha-tag=$tag" >> $GITHUB_OUTPUT
# docker/build-push-action doesn't allow capital letters in the URL
- name: Get repo in lowercase
id: lower-repo
run: |
echo "lower-repo=${GITHUB_REPOSITORY,,}" >> $GITHUB_OUTPUT
lint:
uses: ./.github/workflows/lint.yaml

build:
uses: ./.github/workflows/build.yaml
needs:
- lint
- generate-inputs
build-backend:
if: ${{ needs.changes.outputs.backend == 'true' }}
needs: [changes, generate-inputs, lint]
uses: ./.github/workflows/build-deploy.yaml
with:
sha-tag: ${{ needs.generate-inputs.outputs.sha-tag }}
lower-repo: ${{ needs.generate-inputs.outputs.lower-repo }}
project: backend
secrets: inherit

0 comments on commit 4b5f2e2

Please sign in to comment.