From feff4b83bee0a1e6594650ce9d1d3d5f340a5748 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Wed, 29 Mar 2023 18:39:31 +0200 Subject: [PATCH 1/3] feat(ci): Implement pipeline for PRs This includes using Gitea's Commit Status API to add checks to the PR UI. --- .ci/image/Dockerfile.linux | 6 ++-- .ci/image/Dockerfile.msvc | 18 ++---------- .ci/pipelines/base-pipeline.yml | 37 +++++++++++++++--------- .ci/pipelines/pr.yml | 49 ++++++++++++++++++++++++++++++++ .ci/tasks/build.sh | 5 ---- .ci/tasks/build.yml | 9 ++++-- .ci/tasks/clippy.sh | 7 +++++ .ci/tasks/clippy.yml | 25 +++++++++++++++++ .ci/util/run.sh | 50 +++++++++++++++++++++++++++++++++ Justfile | 4 +-- 10 files changed, 170 insertions(+), 40 deletions(-) create mode 100644 .ci/pipelines/pr.yml create mode 100755 .ci/tasks/clippy.sh create mode 100644 .ci/tasks/clippy.yml create mode 100755 .ci/util/run.sh diff --git a/.ci/image/Dockerfile.linux b/.ci/image/Dockerfile.linux index 523d0ea..c4f955f 100644 --- a/.ci/image/Dockerfile.linux +++ b/.ci/image/Dockerfile.linux @@ -4,6 +4,9 @@ RUN set -eux; \ apt-get update; \ apt-get install --no-install-recommends -y \ build-essential \ + curl \ + gpg \ + jq \ libatk1.0-dev \ libclang-13-dev \ libglib2.0-dev \ @@ -18,5 +21,4 @@ RUN set -eux; \ WORKDIR /src/dtmt -COPY *.so /src - +COPY liboo2corelinux64.so /src diff --git a/.ci/image/Dockerfile.msvc b/.ci/image/Dockerfile.msvc index 4c09735..7a501eb 100644 --- a/.ci/image/Dockerfile.msvc +++ b/.ci/image/Dockerfile.msvc @@ -1,5 +1,5 @@ # https://jake-shadle.github.io/xwin/ -FROM rust:slim-bullseye +FROM dtmt-ci-base-linux ENV KEYRINGS /usr/local/share/keyrings ARG XWIN_VERSION=0.2.11 @@ -11,10 +11,6 @@ ADD https://github.com/Jake-Shadle/xwin/releases/download/$XWIN_VERSION/$XWIN_PR RUN set -eux; \ mkdir -p $KEYRINGS; \ - apt-get update; \ - apt-get install -y --no-install-recommends \ - gpg \ - curl; \ # clang/lld/llvm gpg --dearmor > $KEYRINGS/llvm.gpg < /root/llvm-snapshot.gpg.key; \ # wine @@ -24,17 +20,8 @@ RUN set -eux; \ dpkg --add-architecture i386; \ apt-get update; \ apt-get install --no-install-recommends -y \ - build-essential \ - libatk1.0-dev \ libclang-13-dev \ - libglib2.0-dev \ - libgtk-3-dev \ - libpango1.0-dev \ - libssl-dev \ - libzstd-dev \ - pkg-config \ gcc-mingw-w64-x86-64 \ - # g++-mingw-w64-x86-64 \ clang-13 \ llvm-13 \ lld-13 \ @@ -55,7 +42,6 @@ RUN set -eux; \ update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100; \ update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang++ 100; \ update-alternatives --install /usr/bin/ld ld /usr/bin/ld.lld 100; \ - rustup default nightly; \ rustup target add x86_64-pc-windows-msvc; \ rustup component add rust-src; \ # Install xwin to cargo/bin via github release. Note you could also just use `cargo install xwin`. @@ -100,4 +86,4 @@ RUN wine wineboot --init WORKDIR /src/dtmt -COPY *.lib /src +COPY oo2core_win32.lib oo2core_win64.lib /src diff --git a/.ci/pipelines/base-pipeline.yml b/.ci/pipelines/base-pipeline.yml index f6195fe..9a73737 100644 --- a/.ci/pipelines/base-pipeline.yml +++ b/.ci/pipelines/base-pipeline.yml @@ -4,34 +4,45 @@ # creates a new pipeline instance for each of them. resource_types: -- name: git-branches +- name: gitea-pr type: registry-image source: - repository: aoldershaw/git-branches-resource + repository: registry.local:5000/gitea-pr resources: -- name: repo-branches - type: git-branches +- name: repo-pr + type: gitea-pr source: - uri: https://git.sclu1034.dev/bitsquid_dt/dtmt + access_token: ((gitea_api_key)) + owner: ((owner)) + repo: ((repo)) + url: https://git.sclu1034.dev - name: repo type: git source: uri: https://git.sclu1034.dev/bitsquid_dt/dtmt + # DEBUG: + branch: feat/ci + jobs: - name: set-pipelines plan: - in_parallel: - - get: repo-branches + - get: repo-pr trigger: true - get: repo - - load_var: branches - file: repo-branches/branches.json + - load_var: prs + file: repo-pr/prs.json - across: - - var: branch - values: ((.:branches)) - set_pipeline: dtmt-check - file: repo/.ci/pipelines/check.yml + - var: pr + values: ((.:prs)) + set_pipeline: dtmt-pr + file: repo/.ci/pipelines/pr.yml + vars: + pr: ((.:pr)) + gitea_api_key: ((gitea_api_key)) instance_vars: - branch: ((.:branch.name)) + pr: ((.:pr.number)) + + diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml new file mode 100644 index 0000000..7b79abe --- /dev/null +++ b/.ci/pipelines/pr.yml @@ -0,0 +1,49 @@ +--- + +# The actual CI pipeline that is run per branch + +resources: +- name: repo + type: git + source: + uri: https://git.sclu1034.dev/bitsquid_dt/dtmt + branch: ((pr.head.ref)) + +jobs: +- name: clippy + plan: + - get: repo + trigger: true + - load_var: ref + file: repo/.git/ref + - task: check + file: repo/.ci/tasks/clippy.yml + vars: + ref: ((.:ref)) + gitea_api_key: ((gitea_api_key)) + +- name: build-msvc + plan: + - get: repo + trigger: true + - load_var: ref + file: repo/.git/ref + - task: build + file: repo/.ci/tasks/build.yml + vars: + target: msvc + ref: ((.:ref)) + gitea_api_key: ((gitea_api_key)) + +- name: build-linux + plan: + - get: repo + trigger: true + - load_var: ref + file: repo/.git/ref + - task: build + file: repo/.ci/tasks/build.yml + vars: + target: linux + ref: ((.:ref)) + gitea_api_key: ((gitea_api_key)) diff --git a/.ci/tasks/build.sh b/.ci/tasks/build.sh index 384c0a8..fd74937 100755 --- a/.ci/tasks/build.sh +++ b/.ci/tasks/build.sh @@ -2,8 +2,6 @@ set -eux -OUTPUT="$1" - case "$TARGET" in msvc) cp /src/*.lib ./lib/oodle/ @@ -13,7 +11,6 @@ case "$TARGET" in install -t "$OUTPUT/" target/x86_64-pc-windows-msvc/release/dtmt.exe install -t "$OUTPUT/" target/x86_64-pc-windows-msvc/release/dtmm.exe fi - ;; linux) cp /src/*.so ./lib/oodle/ @@ -23,10 +20,8 @@ case "$TARGET" in install -t "$OUTPUT/" target/release/dtmt install -t "$OUTPUT/" target/release/dtmm fi - ;; *) - set +x echo "Env var 'TARGET' must either be 'msvc' or 'linux'. Got '$TARGET'." >&2 exit 1 esac diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml index 935f81b..3b411bc 100644 --- a/.ci/tasks/build.yml +++ b/.ci/tasks/build.yml @@ -16,9 +16,14 @@ outputs: params: CI: true TARGET: ((target)) + GITEA_API_KEY: ((gitea_api_key)) + REF: ((ref)) + OUTPUT: artifact run: - path: .ci/tasks/build.sh + path: .ci/util/run.sh dir: repo args: - - /artifact + - .ci/tasks/build.sh + - build/((target)) + - "Build for the target platform: ((target))" diff --git a/.ci/tasks/clippy.sh b/.ci/tasks/clippy.sh new file mode 100755 index 0000000..a7b6e11 --- /dev/null +++ b/.ci/tasks/clippy.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +set -eux + +rustup component add clippy + +cargo clippy --color always --no-deps diff --git a/.ci/tasks/clippy.yml b/.ci/tasks/clippy.yml new file mode 100644 index 0000000..35735c3 --- /dev/null +++ b/.ci/tasks/clippy.yml @@ -0,0 +1,25 @@ +--- +platform: linux + +image_resource: + type: registry-image + source: + repository: registry.local:5000/dtmt-ci-base-linux + tag: latest + +inputs: +- name: repo + +params: + CI: true + GITEA_API_KEY: ((gitea_api_key)) + REF: ((ref)) + +run: + path: .ci/util/run.sh + dir: repo + args: + - .ci/tasks/clippy.sh + - lint/clippy + - "Checking for common mistakes and opportunities for code improvement" + diff --git a/.ci/util/run.sh b/.ci/util/run.sh new file mode 100755 index 0000000..1de3b1c --- /dev/null +++ b/.ci/util/run.sh @@ -0,0 +1,50 @@ +#!/bin/sh + +set -ux + +script="$1" +context="$2" +desc="$3" + +if [ -z "$script" ]; then + echo "No script to run" >&2 + exit 1 +fi + +if [ -z "$context" ]; then + echo "Missing 'context' for CI status report" >&2 + exit 1 +fi + +if [ -z "$REF" ]; then + echo "Environment variable 'REF' must be set to a valid Git ref." >&2 + exit 1 +fi + +if [ -z "$GITEA_API_KEY" ]; then + echo "Environment variable 'GITEA_API_KEY' must be set." >&2 + exit 1 +fi + +notify() { + curl -X 'POST' \ + -H 'Content-Type: application/json' \ + -H 'Accept: application/json' \ + -H "Authorization: token $GITEA_API_KEY" \ + "https://git.sclu1034.dev/api/v1/repos/bitsquid_dt/dtmt/statuses/$REF" \ + --data @- < Date: Thu, 30 Mar 2023 11:22:07 +0200 Subject: [PATCH 2/3] fix(ci): Remove debug value --- .ci/pipelines/base-pipeline.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.ci/pipelines/base-pipeline.yml b/.ci/pipelines/base-pipeline.yml index 9a73737..88052a5 100644 --- a/.ci/pipelines/base-pipeline.yml +++ b/.ci/pipelines/base-pipeline.yml @@ -21,8 +21,6 @@ resources: type: git source: uri: https://git.sclu1034.dev/bitsquid_dt/dtmt - # DEBUG: - branch: feat/ci jobs: -- 2.45.3 From c63aee4aefdf3e85e32c8a3e2cb9718c57ad9bc9 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Tue, 4 Apr 2023 15:44:15 +0200 Subject: [PATCH 3/3] feat(ci): Parameterize build task output Potentially useful when using the task for release artifact building later. --- .ci/pipelines/pr.yml | 2 ++ .ci/tasks/build.yml | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml index 7b79abe..6452c93 100644 --- a/.ci/pipelines/pr.yml +++ b/.ci/pipelines/pr.yml @@ -32,6 +32,7 @@ jobs: file: repo/.ci/tasks/build.yml vars: target: msvc + output: artifact ref: ((.:ref)) gitea_api_key: ((gitea_api_key)) @@ -45,5 +46,6 @@ jobs: file: repo/.ci/tasks/build.yml vars: target: linux + output: artifact ref: ((.:ref)) gitea_api_key: ((gitea_api_key)) diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml index 3b411bc..ab3a433 100644 --- a/.ci/tasks/build.yml +++ b/.ci/tasks/build.yml @@ -11,14 +11,14 @@ inputs: - name: repo outputs: -- name: artifact +- name: ((output)) params: CI: true TARGET: ((target)) GITEA_API_KEY: ((gitea_api_key)) REF: ((ref)) - OUTPUT: artifact + OUTPUT: ((output)) run: path: .ci/util/run.sh -- 2.45.3