Skip to content

Commit

Permalink
Add workflow (#32)
Browse files Browse the repository at this point in the history
* Add docker workflow

* Add CodeQL workflow

* Add Rust workflow

* Add python workflow
  • Loading branch information
RealHinome authored Aug 24, 2024
1 parent 04687a6 commit eb411d5
Show file tree
Hide file tree
Showing 6 changed files with 163 additions and 0 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/codeql.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: codeql

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
schedule:
- cron: '32 18 * * 3'

jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
permissions:
security-events: write
packages: read
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: python
build-mode: none
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
- if: matrix.build-mode == 'manual'
shell: bash
run: |
echo 'If you are using a "manual" build mode for one or more of the' \
'languages you are analyzing, replace this with the commands to build' \
'your code, for example:'
echo ' make bootstrap'
echo ' make release'
exit 1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{matrix.language}}"
53 changes: 53 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: news/docker

on:
workflow_run:
workflows: ["news/graphql", "news/machine_learning", "codeql"]
types:
- completed

env:
REGISTRY: ghcr.io

jobs:
deploy:
if: ${{ github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.head_branch == 'master' }}
name: Publish news
runs-on: ubuntu-latest
permissions: write-all
steps:
- uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get GraphQL tag
id: "get-graphql-tag"
shell: "bash"
run: |
echo PKG_VERSION=$(awk -F ' = ' '$1 ~ /version/ { gsub(/["]/, "", $2); printf("%s",$2) }' graphql/Cargo.toml) >> $GITHUB_OUTPUT
- name: Build GraphQL image
run: |
docker build . -f docker/api/Dockerfile -t ghcr.io/gravitalia/news-api:latest .
docker push ghcr.io/lubmminy/polymath:latest
docker tag ghcr.io/gravitalia/news-graphql:latest ghcr.io/gravitalia/news-api:${{ steps.get-graphql-tag.outputs.PKG_VERSION }}
docker push ghcr.io/lubmminy/polymath:${{ steps.get-graphql-tag.outputs.PKG_VERSION }}
- name: Get ML tag
id: "get-ml-tag"
shell: "bash"
run: |
echo PKG_VERSION=$(awk -F ' = ' '/^version/ { gsub(/["]/, "", $2); print $2 }' machine_learning/pyproject.toml) >> $GITHUB_OUTPUT
- name: Build ML API image
run: |
docker build . -f docker/ml/Dockerfile -t ghcr.io/gravitalia/news-ml:latest .
docker tag ghcr.io/gravitalia/news-ml:latest ghcr.io/gravitalia/news-ml:${{ steps.get-ml-tag.outputs.PKG_VERSION }}
- name: Publish images
run: |
docker push ghcr.io/gravitalia/news-api:latest
docker push ghcr.io/gravitalia/news-api:${{ steps.get-graphql-tag.outputs.PKG_VERSION }}
docker push ghcr.io/gravitalia/news-ml:latest
docker push ghcr.io/gravitalia/news-ml:${{ steps.get-ml-tag.outputs.PKG_VERSION }}
24 changes: 24 additions & 0 deletions .github/workflows/python.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: news/machine_learning

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.9"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: pip
- name: Install dependencies
working-directory: ./machine_learning
run: |
python -m pip install --upgrade pip setuptools wheel
python -m pip install .
#- name: Test
# Add test later.
32 changes: 32 additions & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: news/graphql

on: [push]

jobs:
graphql:
name: cargo build
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Cache Cargo registry
uses: actions/cache@v3
with:
path: |
~/.cargo
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install Protoc
uses: arduino/setup-protoc@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Initialize Rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Test GraphQL API
working-directory: ./graphql
run: cargo test --all-features
- name: Clippy
working-directory: ./graphql
run: cargo clippy
1 change: 1 addition & 0 deletions graphql/rank/src/squid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ mod squid {
}

/// Squid client structure.
#[derive(Clone, Debug)]
pub struct Squid {
client: SquidClient<Channel>,
}
Expand Down
7 changes: 7 additions & 0 deletions machine_learning/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from setuptools import setup, find_packages

setup(
name="news",
version="0.1.0",
packages=find_packages(include=["rest", "rest.*"]),
)

0 comments on commit eb411d5

Please sign in to comment.