diff --git a/.ci/pipelines/base-pipeline.yml b/.ci/pipelines/base-pipeline.yml index 48d5bb4..ae9e323 100644 --- a/.ci/pipelines/base-pipeline.yml +++ b/.ci/pipelines/base-pipeline.yml @@ -40,4 +40,4 @@ jobs: pr: ((.:pr)) gitea_api_key: ((gitea_api_key)) instance_vars: - pr: ((.:pr.number)) + n: ((.:pr.number)) diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml index be1857d..267db09 100644 --- a/.ci/pipelines/pr.yml +++ b/.ci/pipelines/pr.yml @@ -2,6 +2,17 @@ --- # The actual CI pipeline that is run per branch +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 @@ -10,53 +21,179 @@ resources: uri: http://forgejo:3000/bitsquid_dt/dtmt branch: ((pr.head.ref)) +- name: gitea-package + type: gitea-package + source: + access_token: ((gitea_api_key)) + url: http://forgejo:3000 + owner: concourse + type: generic + name: dtmt + +- name: pr-status-lint-clippy + type: gitea-status + source: + access_token: ((gitea_api_key)) + url: http://forgejo:3000 + owner: bitsquid_dt + repo: dtmt + sha: ((pr.head.sha)) + context: lint/clippy + description: Checking for common mistakes and opportunities for code improvement + +- name: pr-status-build-msvc + type: gitea-status + source: + access_token: ((gitea_api_key)) + url: http://forgejo:3000 + owner: bitsquid_dt + repo: dtmt + sha: ((pr.head.sha)) + context: build/msvc + description: "Build for the target platform: msvc" + +- name: pr-status-build-linux + type: gitea-status + source: + access_token: ((gitea_api_key)) + url: http://forgejo:3000 + owner: bitsquid_dt + repo: dtmt + sha: ((pr.head.sha)) + context: build/linux + description: "Build for the target platform: linux" + + jobs: - name: clippy + on_success: + put: state-success + resource: pr-status-lint-clippy + no_get: true + params: + state: success + + on_failure: + put: state-success + resource: pr-status-lint-clippy + no_get: true + params: + state: failure + plan: + - put: state-pending + resource: pr-status-lint-clippy + no_get: true + params: + state: pending + - 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 + on_success: + put: state-success + resource: pr-status-build-msvc + no_get: true + params: + state: success + + on_failure: + put: state-success + resource: pr-status-build-msvc + no_get: true + params: + state: failure + plan: + - put: state-pending + resource: pr-status-build-msvc + no_get: true + params: + state: pending + - get: repo trigger: true - - load_var: ref - file: repo/.git/ref + - task: build file: repo/.ci/tasks/build.yml vars: target: msvc - output: artifact - ref: ((.:ref)) + pr: ((pr)) gitea_url: http://forgejo:3000 gitea_api_key: ((gitea_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/dtmt + - artifact/dtmm + - artifact/*.exe + - name: build-linux + on_success: + put: state-success + resource: pr-status-build-linux + no_get: true + params: + state: success + + on_failure: + put: state-success + resource: pr-status-build-linux + no_get: true + params: + state: failure + plan: + - put: state-pending + resource: pr-status-build-linux + no_get: true + params: + state: pending + - get: repo trigger: true - - load_var: ref - file: repo/.git/ref + - task: build file: repo/.ci/tasks/build.yml vars: target: linux - output: artifact - ref: ((.:ref)) + pr: ((pr)) gitea_url: http://forgejo:3000 gitea_api_key: ((gitea_api_key)) - - task: upload - file: repo/.ci/tasks/upload.yml - vars: - input: artifact - pr: ((.:pr)) - gitea_api_key: ((gitea_api_key)) - gitea_user: bitsquid_dt - gitea_url: http://forgejo:3000 + + - 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/dtmt + - artifact/dtmm + - artifact/*.exe diff --git a/.ci/tasks/build.sh b/.ci/tasks/build.sh index 7029f44..226f137 100755 --- a/.ci/tasks/build.sh +++ b/.ci/tasks/build.sh @@ -1,25 +1,48 @@ #!/bin/sh -set -eux +set -eu +if [ -n "$OUTPUT" ]; then + OUTPUT="$PWD/$OUTPUT" +else + OUTPUT=$(mktemp -d) +fi + +title() { + printf "\033[1m%s\033[0m\n" "$1" +} + +if [ -n "${PR:-}" ]; then + title "PR: $(echo "$PR" | jq '.number') - $(echo "$PR" | jq '.title')" + ref="pr-$(echo "$PR" | jq '.number')-$(git rev-parse --short HEAD 2>/dev/null || echo 'manual')" +else + ref=$(git describe --tags) +fi + +title "Version is '$ref'" +echo "$ref" > "$OUTPUT/version" + +cd "repo" case "$TARGET" in msvc) cp /src/*.lib ./lib/oodle/ + + title "Build project for target $TARGET" cargo build --color always --locked --release --target x86_64-pc-windows-msvc -Zbuild-std - if [ -d "$OUTPUT" ]; then - 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 + title "Install artifacts" + install -t "$OUTPUT/" target/x86_64-pc-windows-msvc/release/dtmt.exe + install -t "$OUTPUT/" target/x86_64-pc-windows-msvc/release/dtmm.exe ;; linux) cp /src/*.a ./lib/oodle/ + + title "Build project for target $TARGET" cargo build --color always --locked --profile release-lto - if [ -d "$OUTPUT" ]; then - install -t "$OUTPUT/" target/release/dtmt - install -t "$OUTPUT/" target/release/dtmm - fi + title "Install artifacts" + install -t "$OUTPUT/" target/release-lto/dtmt + install -t "$OUTPUT/" target/release-lto/dtmm ;; *) echo "Env var 'TARGET' must either be 'msvc' or 'linux'. Got '$TARGET'." >&2 diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml index 3dd4215..dce44d0 100644 --- a/.ci/tasks/build.yml +++ b/.ci/tasks/build.yml @@ -13,7 +13,7 @@ inputs: - name: repo outputs: -- name: artifacts +- name: artifact caches: - path: repo/target @@ -23,13 +23,8 @@ params: CI: "true" TARGET: ((target)) GITEA_API_KEY: ((gitea_api_key)) - REF: ((ref)) - OUTPUT: artifacts + PR: ((pr)) + OUTPUT: artifact run: - path: .ci/util/run.sh - dir: repo - args: - - .ci/tasks/build.sh - - build/((target)) - - "Build for the target platform: ((target))" + path: repo/.ci/tasks/build.sh diff --git a/.ci/tasks/clippy.yml b/.ci/tasks/clippy.yml index cea0e76..483cb30 100644 --- a/.ci/tasks/clippy.yml +++ b/.ci/tasks/clippy.yml @@ -19,13 +19,8 @@ caches: params: CI: "true" GITEA_API_KEY: ((gitea_api_key)) - REF: ((ref)) run: - path: .ci/util/run.sh + path: .ci/tasks/clippy.sh dir: repo - args: - - .ci/tasks/clippy.sh - - lint/clippy - - "Checking for common mistakes and opportunities for code improvement" diff --git a/.ci/tasks/upload.sh b/.ci/tasks/upload.sh deleted file mode 100755 index 5e1103e..0000000 --- a/.ci/tasks/upload.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/bin/bash - -set -eu - -artifacts="$PWD/artifacts" -repo="$PWD/repo" - -base_url="${GITEA_URL}/api/packages/${GITEA_USER}/generic" - -cd "$repo" - -if [ -n "$PR" ]; then - echo "PR: $(echo "$PR" | jq '.number') - $(echo "$PR" | jq '.title')" - ref="pr-$(echo "$PR" | jq '.number')-$(git rev-parse --short HEAD 2>/dev/null || echo 'manual')" -else - ref=$(git describe --tags) -fi - -echo "ref: $ref" - -# TODO: If this is a tag, check the tag name to determine which -# binary was affected and only upload that. -for f in dtmt dtmt.exe dtmm dtmm.exe; do - if [ -f "$artifacts/$f" ]; then - url="$base_url/$(basename -s .exe $f)/$ref/$f" - curl -i -X 'PUT' \ - --user "concourse:$GITEA_API_KEY" \ - --upload-file "$artifacts/$f" \ - "$url" - fi -done diff --git a/.ci/tasks/upload.yml b/.ci/tasks/upload.yml deleted file mode 100644 index de22cd2..0000000 --- a/.ci/tasks/upload.yml +++ /dev/null @@ -1,24 +0,0 @@ -# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig ---- -platform: linux - -image_resource: - name: python-script - type: registry-image - source: - repository: registry.local:5000/python-script - tag: latest - -inputs: -- name: repo -- name: ((input)) - -params: - CI: "true" - GITEA_API_KEY: ((gitea_api_key)) - GITEA_URL: ((gitea_url)) - GITEA_USER: ((user)) - PR: ((pr)) - -run: - path: repo/.ci/tasks/upload.sh diff --git a/Justfile b/Justfile index 09ce0a3..964dc1f 100644 --- a/Justfile +++ b/Justfile @@ -1,3 +1,5 @@ +fly_target := "main" + ci-build: ci-build-msvc ci-build-linux ci-build-msvc: @@ -25,3 +27,26 @@ ci-image-linux: docker build -t dtmt-ci-base-linux -f .ci/image/Dockerfile.linux .ci/image docker tag dtmt-ci-base-linux registry.sclu1034.dev/dtmt-ci-base-linux docker push registry.sclu1034.dev/dtmt-ci-base-linux + +set-base-pipeline: + fly -t ((fly_target)) set-pipeline \ + --pipeline dtmt-prs \ + --config .ci/pipelines/base-pipeline.yml \ + -v gitea_api_key=${GITEA_API_KEY} \ + -v owner=bitsquid_dt \ + -v repo=dtmt + +set-pr-pipeline pr: + curl \ + -H "Authorization: ${GITEA_API_KEY}" \ + -H 'Accept: application/json' \ + 'https://git.sclu1034.dev/api/v1/repos/bitsquid_dt/dtmt/pulls/{{pr}}' \ + | yq -y '.' - > 'pr-{{pr}}.yaml' + fly -t main set-pipeline \ + --pipeline dtmt-pr \ + --config .ci/pipelines/pr.yml \ + -v gitea_api_key=${GITEA_API_KEY} \ + -i n={{pr}} \ + -y branch="$(yq -y '.head.ref' 'pr-{{pr}}.yaml')" \ + -y pr="$(cat 'pr-{{pr}}.yaml')" +