diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c624351e..c99158d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,7 +25,17 @@ jobs: needs: ["build-ci-container"] container: image: ghcr.io/pluralkit/ci:${{ github.sha }} + volumes: + - /var/run/docker.sock:/var/run/docker.sock env: + DOCKER_HOST: unix:///var/run/docker.sock + + COMMIT_STATUS_TOKEN: ${{ secrets.COMMIT_STATUS_TOKEN }} + DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }} DISPATCH_DATA: ${{ inputs.dispatchData }} + + # these only work on the push/pull_request jobs + CUR_SHA: ${{ github.sha }} + OLD_SHA: ${{ github.event.before }} steps: - run: /run_ci.py diff --git a/ci/Dockerfile b/ci/Dockerfile index 5d9bb5e5..216781b0 100644 --- a/ci/Dockerfile +++ b/ci/Dockerfile @@ -1,3 +1,3 @@ FROM alpine:latest -RUN apk add python3 +RUN apk add python3 docker git COPY ci/run_ci.py /run_ci.py diff --git a/ci/run.sh b/ci/run.sh new file mode 100644 index 00000000..2da88f11 --- /dev/null +++ b/ci/run.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +set -euo pipefail + +notify_discord() { + todo +} + +# CI_PREV_COMMIT +# GH_BRANCH + +files_changed=$(git diff --name-only $CI_PREV_COMMIT) + +if [ ! -z "$(echo $files_changed | grep -E '.cs$')" ]; then + dotnet_format +fi + +if [ ! -z "$(echo $files_changed | grep -E '.rs$')" ]; then + rustfmt +fi + +### + +if PluralKit.Bot changed build bot +if PluralKit.Core changed build bot api +idk this should just be python diff --git a/ci/run_ci.py b/ci/run_ci.py index 56acdbd1..2da5122b 100755 --- a/ci/run_ci.py +++ b/ci/run_ci.py @@ -1,6 +1,76 @@ #!/usr/bin/env python3 -import os -print("hello from python!") -print(f"data: {os.environ.get("DISPATCH_DATA")}") +import os, json, subprocess + +dispatch_data = os.environ.get("DISPATCH_DATA") + +def must_get_env(name): + val = os.environ.get(name) + if val == "": + raise "meow" + return val + +def docker_build(data): + # file="", tags=[], root="/" + pass + +def create_jobs(): + modify_regexes = { + "^ci/": "all", + + "^docs/": "bin_docs", + "^dashboard/": "bin_dashboard", + + "\.rs$": "format_rs", + "\.cs$": "format_cs", + + "^Cargo.lock": "all_rs", + + "^services/api": "bin_api", + # dispatch doesn't use libpk + "^services/dispatch": "bin_dispatch", + "^services/scheduled_tasks": "bin_scheduled_tasks", + + # one image for all dotnet + "^PluralKit\.": "bin_dotnet", + "^Myriad": "bin_dotnet", + } + + aliases = { + "all": ["bin_dotnet", "bin_api", "bin_dispatch", "bin_scheduled_tasks", "bin_dashboard"], + "all_rs": ["bin_api", "bin_dispatch"], + } + + now = must_get_env("CUR_SHA") + before = must_get_env("OLD_SHA") + changed_files = subprocess.check_output(["git", "diff", "--name-only", before, now]) + + jobs = set([]) + for key in modify_regexes.keys(): + if regex matches: + jobs = jobs | modify_regexes[key] + + for key in changes: + if aliases.get(key) is not None: + jobs = jobs | aliases[key] + jobs = jobs - [key] + + pass + +if __name__ == "__main__": + print("hello from python!") + subprocess.run(["docker", "run", "--rm", "-it", "hello-world"], check=True) + + return + return create_jobs() if dispatch_data == "" + + data = json.loads(dispatch_data) + match data.get("action"): + case "docker_build": + return docker_build(data.get("data")) + case "rustfmt": + case "dotnet_format": + case _: + print (f"data unknown: {dispatch_data}") + os.exit(1)