From 6e2e38e6c8d1800d92aa00a61a484c8c95f2c2a2 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 19 Aug 2024 11:43:04 +0200 Subject: [PATCH] Implement CI pipelines --- .ci/Dockerfile | 10 ++ .ci/pipelines/pr.yml | 143 +++++++++++++++++++++++++++++ .ci/pipelines/set-pr-pipelines.yml | 132 ++++++++++++++++++++++++++ .ci/tasks/build.sh | 41 +++++++++ .ci/tasks/build.yml | 30 ++++++ .ci/tasks/clippy.sh | 16 ++++ .ci/tasks/clippy.yml | 25 +++++ 7 files changed, 397 insertions(+) create mode 100644 .ci/Dockerfile create mode 100644 .ci/pipelines/pr.yml create mode 100644 .ci/pipelines/set-pr-pipelines.yml create mode 100755 .ci/tasks/build.sh create mode 100644 .ci/tasks/build.yml create mode 100755 .ci/tasks/clippy.sh create mode 100644 .ci/tasks/clippy.yml diff --git a/.ci/Dockerfile b/.ci/Dockerfile new file mode 100644 index 0000000..919e80a --- /dev/null +++ b/.ci/Dockerfile @@ -0,0 +1,10 @@ +FROM rust-xwin + +RUN set -eux; \ + apt-get update; \ + apt-get install --no-install-recommends -y \ + git \ + ; \ + sh -c "git config --global --add safe.directory '*'"; \ + apt-get remove -y --auto-remove; \ + rm -rf /var/lib/apt/lists/*; diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml new file mode 100644 index 0000000..f21409c --- /dev/null +++ b/.ci/pipelines/pr.yml @@ -0,0 +1,143 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/Config +--- +resource_types: +- name: gitea-package + type: registry-image + source: + repository: registry.local:5000/gitea-package + +- name: gitea-status + type: registry-image + source: + repository: registry.local:5000/gitea-status + +resources: +- name: repo + type: git + source: + uri: ((forgejo_url))/((owner))/((repo)) + branch: ((pr.head.ref)) + +- name: gitea-package + type: gitea-package + source: + access_token: ((forgejo_api_key)) + url: ((forgejo_url)) + owner: ((owner)) + type: generic + name: ((repo)) + +- name: pr-status-lint-clippy + type: gitea-status + source: + access_token: ((forgejo_api_key)) + url: ((forgejo_url)) + owner: ((owner)) + repo: ((repo)) + context: lint/clippy + description: Check for common mistakes and opportunities for code improvement + +- name: pr-status-build + type: gitea-status + source: + access_token: ((forgejo_api_key)) + url: ((forgejo_url)) + owner: ((owner)) + repo: ((repo)) + context: build + description: "Build for the target platform" + + +jobs: +- name: clippy + on_success: + put: state-success + resource: pr-status-lint-clippy + no_get: true + params: + state: success + sha: ((.:git_sha)) + + on_failure: + put: state-failure + resource: pr-status-lint-clippy + no_get: true + params: + state: failure + sha: ((.:git_sha)) + + plan: + - get: repo + trigger: true + + - load_var: git_sha + file: repo/.git/ref + + - put: state-pending + resource: pr-status-lint-clippy + no_get: true + params: + state: pending + sha: ((.:git_sha)) + + - task: check + file: repo/.ci/tasks/clippy.yml + vars: + forgejo_api_key: ((forgejo_api_key)) + + +- name: build + on_success: + put: state-success + resource: pr-status-build + no_get: true + params: + state: success + sha: ((.:git_sha)) + + on_failure: + put: state-failure + resource: pr-status-build + no_get: true + params: + state: failure + sha: ((.:git_sha)) + + plan: + - get: repo + trigger: true + + - load_var: git_sha + file: repo/.git/ref + + - put: state-pending + resource: pr-status-build + no_get: true + params: + state: pending + sha: ((.:git_sha)) + + - task: build + file: repo/.ci/tasks/build.yml + vars: + target: msvc + pr: ((pr)) + forgejo_url: ((forgejo_url)) + forgejo_api_key: ((forgejo_api_key)) + + - load_var: version_number + reveal: true + file: artifact/version + + - put: package + resource: gitea-package + no_get: true + inputs: + - artifact + params: + version: ((.:version_number)) + fail_fast: true + override: true + globs: + - artifact/*.dll + - artifact/*.sha256 diff --git a/.ci/pipelines/set-pr-pipelines.yml b/.ci/pipelines/set-pr-pipelines.yml new file mode 100644 index 0000000..938e7e3 --- /dev/null +++ b/.ci/pipelines/set-pr-pipelines.yml @@ -0,0 +1,132 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/Config +--- + +resource_types: +- name: gitea-package + type: registry-image + source: + repository: registry.local:5000/gitea-package + +- name: gitea-status + type: registry-image + source: + repository: registry.local:5000/gitea-status + +- name: gitea-pr + type: registry-image + source: + repository: registry.local:5000/gitea-pr + + +resources: +- name: repo + type: git + source: + uri: ((forgejo_url))/((owner))/((repo)) + branch: master + +- name: repo-pr + type: gitea-pr + source: + access_token: ((forgejo_api_key)) + owner: ((owner)) + repo: ((repo)) + url: ((forgejo_url)) + +- name: gitea-package + type: gitea-package + source: + access_token: ((forgejo_api_key)) + url: ((fprgejo_url)) + owner: ((owner)) + type: generic + name: ((repo)) + + +- name: status-build + type: gitea-status + source: + access_token: ((forgejo_api_key)) + url: ((forgejo_url)) + owner: ((owner)) + repo: ((repo)) + context: build + description: "Build for the target platform" + +jobs: +- name: set-pipelines + plan: + - in_parallel: + - get: repo-pr + trigger: true + - get: repo + + - load_var: prs + file: repo-pr/prs.json + + - across: + - var: pr + values: ((.:prs)) + set_pipeline: ((repo))-pr + file: repo/.ci/pipelines/pr.yml + vars: + pr: ((.:pr)) + forgejo_api_key: ((forgejo_api_key)) + forgejo_url: ((forgejo_url)) + instance_vars: + number: ((.:pr.number)) + +- name: build + on_success: + put: state-success + resource: status-build + no_get: true + params: + state: success + sha: ((.:git_sha)) + + on_failure: + put: state-failure + resource: status-build + no_get: true + params: + state: failure + sha: ((.:git_sha)) + + plan: + - get: repo + trigger: true + + - load_var: git_sha + file: repo/.git/ref + + - put: state-pending + resource: status-build + no_get: true + params: + state: pending + sha: ((.:git_sha)) + + - task: build + file: repo/.ci/tasks/build.yml + vars: + pr: "" + forgejo_url: ((forgejo_url)) + forgejo_api_key: ((forgejo_api_key)) + + - load_var: version_number + reveal: true + file: artifact/version + + - put: package + resource: gitea-package + no_get: true + inputs: + - artifact + params: + version: ((.:version_number)) + fail_fast: true + override: true + globs: + - artifact/*.dll + - artifact/*.sha256 diff --git a/.ci/tasks/build.sh b/.ci/tasks/build.sh new file mode 100755 index 0000000..1b95440 --- /dev/null +++ b/.ci/tasks/build.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -eu + +if [ -n "$OUTPUT" ]; then + OUTPUT=$(realpath "$PWD/../$OUTPUT") +else + OUTPUT=$(mktemp -d) +fi + +title() { + printf "\033[1m%s\033[0m\n" "$1" +} + +install_artifact() { + for f in "$@"; do + echo "Installing: $f" + install -v -t "$OUTPUT/" "$f" + sha256sum "$f" > "$OUTPUT/$(basename "$f").sha256" + done +} + +PR=${PR:-} + +if [ -n "$PR" ]; then + title "PR: $(echo "$PR" | jq '.number') - $(echo "$PR" | jq '.title')" + ref="pr-$(echo "$PR" | jq '.number')-$(git rev-parse --short "$(cat .git/ref || echo "HEAD")" 2>/dev/null || echo 'manual')" +else + ref=$(git describe --tags --always) +fi + +title "Version: '$ref'" +echo "$ref" > "$OUTPUT/version" + +title "Building project" +cargo build --color always --locked --release --target x86_64-pc-windows-msvc -Zbuild-std + +title "Installing artifacts" +install_artifact target/x86_64-pc-windows-msvc/release/*.dll + +title "Done" diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml new file mode 100644 index 0000000..e8652c4 --- /dev/null +++ b/.ci/tasks/build.yml @@ -0,0 +1,30 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig +--- +platform: linux + +image_resource: + name: rust-xwin + type: registry-image + source: + repository: registry.local:5000/rust-xwin-ci + tag: latest + +inputs: + - name: repo + +outputs: + - name: artifact + +caches: + - path: repo/target + - path: /usr/local/cargo/registry + +params: + CI: "true" + FORGEJO_API_KEY: ((forgejo_api_key)) + PR: ((pr)) + OUTPUT: artifact + +run: + path: .ci/tasks/build.sh + dir: repo diff --git a/.ci/tasks/clippy.sh b/.ci/tasks/clippy.sh new file mode 100755 index 0000000..2d0aac7 --- /dev/null +++ b/.ci/tasks/clippy.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +set -eu + +title() { + printf "\033[1m%s\033[0m\n" "$1" +} + +title "Install clippy" +rustup component add clippy + +title "Run clippy" +cargo clippy --color always --no-deps --locked + +title "Done" + diff --git a/.ci/tasks/clippy.yml b/.ci/tasks/clippy.yml new file mode 100644 index 0000000..149ce54 --- /dev/null +++ b/.ci/tasks/clippy.yml @@ -0,0 +1,25 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig +--- +platform: linux + +image_resource: + name: rust-xwin-ci + type: registry-image + source: + repository: registry.local:5000/rust-xwin-ci + tag: latest + +inputs: +- name: repo + +caches: + - path: repo/target + - path: /usr/local/cargo/registry + +params: + CI: "true" + FORGEJO_API_KEY: ((forgejo_api_key)) + +run: + path: .ci/tasks/clippy.sh + dir: repo