diff --git a/.ci/pipelines/base-pipeline.yml b/.ci/pipelines/base-pipeline.yml index ae9e323..48d5bb4 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: - n: ((.:pr.number)) + pr: ((.:pr.number)) diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml index 267db09..be1857d 100644 --- a/.ci/pipelines/pr.yml +++ b/.ci/pipelines/pr.yml @@ -2,17 +2,6 @@ --- # 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 @@ -21,179 +10,53 @@ 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 - pr: ((pr)) + output: artifact + ref: ((.:ref)) 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 - pr: ((pr)) + output: artifact + ref: ((.:ref)) 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 + - 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 diff --git a/.ci/tasks/build.sh b/.ci/tasks/build.sh index 226f137..7029f44 100755 --- a/.ci/tasks/build.sh +++ b/.ci/tasks/build.sh @@ -1,48 +1,25 @@ #!/bin/sh -set -eu +set -eux -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 - 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 + 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 ;; linux) cp /src/*.a ./lib/oodle/ - - title "Build project for target $TARGET" cargo build --color always --locked --profile release-lto - title "Install artifacts" - install -t "$OUTPUT/" target/release-lto/dtmt - install -t "$OUTPUT/" target/release-lto/dtmm + if [ -d "$OUTPUT" ]; then + install -t "$OUTPUT/" target/release/dtmt + install -t "$OUTPUT/" target/release/dtmm + fi ;; *) 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 dce44d0..3dd4215 100644 --- a/.ci/tasks/build.yml +++ b/.ci/tasks/build.yml @@ -13,7 +13,7 @@ inputs: - name: repo outputs: -- name: artifact +- name: artifacts caches: - path: repo/target @@ -23,8 +23,13 @@ params: CI: "true" TARGET: ((target)) GITEA_API_KEY: ((gitea_api_key)) - PR: ((pr)) - OUTPUT: artifact + REF: ((ref)) + OUTPUT: artifacts run: - path: repo/.ci/tasks/build.sh + path: .ci/util/run.sh + dir: repo + args: + - .ci/tasks/build.sh + - build/((target)) + - "Build for the target platform: ((target))" diff --git a/.ci/tasks/clippy.yml b/.ci/tasks/clippy.yml index 483cb30..cea0e76 100644 --- a/.ci/tasks/clippy.yml +++ b/.ci/tasks/clippy.yml @@ -19,8 +19,13 @@ caches: params: CI: "true" GITEA_API_KEY: ((gitea_api_key)) + REF: ((ref)) run: - path: .ci/tasks/clippy.sh + 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/tasks/upload.sh b/.ci/tasks/upload.sh new file mode 100755 index 0000000..5e1103e --- /dev/null +++ b/.ci/tasks/upload.sh @@ -0,0 +1,31 @@ +#!/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 new file mode 100644 index 0000000..de22cd2 --- /dev/null +++ b/.ci/tasks/upload.yml @@ -0,0 +1,24 @@ +# 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 964dc1f..09ce0a3 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,3 @@ -fly_target := "main" - ci-build: ci-build-msvc ci-build-linux ci-build-msvc: @@ -27,26 +25,3 @@ 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')" -