Skip to content

Commit

Permalink
chore: Create new workflow file for backend code quality checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
naaive committed Nov 4, 2024
1 parent 3417c59 commit c51c29d
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 0 deletions.
121 changes: 121 additions & 0 deletions .github/workflows/build-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: build & push docker images

on:
push:
branches:
- main
tags:
- "*"
pull_request:

jobs:
build:
runs-on:
- self-hosted
- ${{ matrix.platform }}
strategy:
fail-fast: false
matrix:
platform:
- linux/amd64
# - linux/arm64 # Cannot build frontend (install apk packages) within acceptable time
steps:
- name: Prepare
run: |
platform=${{ matrix.platform }}
echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ matrix.platform }}
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: rss3/openagent
- name: Build and push by digest
id: build
uses: docker/build-push-action@v5
with:
context: .
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=rss3/openagent,push-by-digest=true,name-canonical=true,push=true
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v4
with:
name: digests-${{ env.PLATFORM_PAIR }}
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
needs:
- build
steps:
- name: Download digests
uses: actions/download-artifact@v4
with:
path: /tmp/digests
pattern: digests-*
merge-multiple: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: |
rss3/openagent
ghcr.io/${{ github.repository }}
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=${{ matrix.arch }},enable={{is_default_branch}}
type=ref,event=tag
type=ref,event=branch
type=ref,event=pr
type=sha,prefix={{branch}}-,enable=${{ !startsWith(github.ref, 'refs/tags') && github.event_name != 'pull_request' }},event=branch
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
if [ ${{ github.event_name }} == 'pull_request' ]; then
ARGS="--dry-run"
fi
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf 'rss3/openagent@sha256:%s ' *) $ARGS
- name: Inspect image
if: github.event_name != 'pull_request'
run: |
docker buildx imagetools inspect rss3/openagent:${{ steps.meta.outputs.version }}
19 changes: 19 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: backend code quality

on:
pull_request:
push:
branches:
- "main"
- "prod"

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- run: pip install flake8 mypy pydantic types-requests types-redis ruff
- uses: pre-commit/action@v3.0.0
with:
extra_args: --files ./src/*

0 comments on commit c51c29d

Please sign in to comment.