This repository has been archived by the owner on Jan 2, 2025. It is now read-only.
Bump the dependencies group in /admin-system/frontend with 9 updates … #251
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Admin Backend CI/CD | |
on: | |
push: | |
branches: [ "main" ] | |
pull_request: | |
branches: [ "main" ] | |
paths: | |
- "admin-system/backend/**" | |
- "machine-learning/**" | |
- ".github/**" | |
env: | |
REGISTRY: ghcr.io | |
IMAGE_NAME: '${{ github.repository_owner }}/3fa-backend' | |
permissions: | |
contents: read | |
jobs: | |
ml-model: | |
runs-on: ubuntu-latest | |
permissions: write-all | |
defaults: | |
run: | |
working-directory: machine-learning | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
cache: 'pip' | |
- name: Install Machine Learning Dependencies | |
run: pip install -r requirements.txt | |
- name: Generate Machine Learning Model | |
run: python model.py | |
- name: Delete Old Artifacts | |
uses: actions/github-script@v7 | |
id: artifact | |
with: | |
script: | | |
const res = await github.rest.actions.listArtifactsForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
}) | |
res.data.artifacts | |
.forEach(({ id }) => { | |
github.rest.actions.deleteArtifact({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
artifact_id: id, | |
}) | |
}) | |
- name: Save Machine Learning Model | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ml-model | |
path: machine-learning/model.pth | |
retention-days: 1 | |
build-test: | |
runs-on: ${{ matrix.os }} | |
needs: ml-model | |
defaults: | |
run: | |
working-directory: admin-system/backend | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Python 3.11 | |
uses: actions/setup-python@v5 | |
with: | |
python-version: '3.11' | |
- name: Install pipenv | |
run: curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python | |
- name: Install Backend Dependencies | |
run: | | |
pipenv lock --dev | |
pipenv sync --dev | |
- name: Download Machine Learning Model | |
uses: actions/download-artifact@v4 | |
with: | |
name: ml-model | |
path: admin-system/backend/instance/ | |
- name: Test with pytest | |
run: pipenv run pytest --cov=api --cov-branch | |
build-push-docker: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
packages: write | |
needs: ml-model | |
defaults: | |
run: | |
working-directory: admin-system/backend | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Download Machine Learning Model | |
uses: actions/download-artifact@v4 | |
with: | |
name: ml-model | |
path: admin-system/backend/instance/ | |
- name: Log in to the Container registry | |
if: ${{ github.event_name != 'pull_request' }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Extract metadata (tags, labels) for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} | |
tags: | | |
type=raw,value=latest | |
- name: Build Image | |
id: build | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./admin-system/backend | |
platforms: linux/amd64 | |
load: true | |
push: false | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: type=gha | |
- name: Run Tests | |
run: docker run --rm ${{ fromJSON(steps.build.outputs.metadata)['image.name'] }} /usr/src/.venv/bin/python -m pytest --cov=api --cov-branch | |
- name: Build & Push Image | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./admin-system/backend | |
platforms: linux/amd64 | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-to: type=gha,mode=max |