diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000..9634a3d --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -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}}" diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..b1bd73d --- /dev/null +++ b/.github/workflows/docker.yaml @@ -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 }} diff --git a/.github/workflows/python.yaml b/.github/workflows/python.yaml new file mode 100644 index 0000000..f295287 --- /dev/null +++ b/.github/workflows/python.yaml @@ -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. diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml new file mode 100644 index 0000000..2067e91 --- /dev/null +++ b/.github/workflows/rust.yaml @@ -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 diff --git a/graphql/rank/src/squid.rs b/graphql/rank/src/squid.rs index 024dc68..7e2184b 100644 --- a/graphql/rank/src/squid.rs +++ b/graphql/rank/src/squid.rs @@ -12,6 +12,7 @@ mod squid { } /// Squid client structure. +#[derive(Clone, Debug)] pub struct Squid { client: SquidClient, } diff --git a/machine_learning/setup.py b/machine_learning/setup.py new file mode 100644 index 0000000..7a1b606 --- /dev/null +++ b/machine_learning/setup.py @@ -0,0 +1,7 @@ +from setuptools import setup, find_packages + +setup( + name="news", + version="0.1.0", + packages=find_packages(include=["rest", "rest.*"]), +)