From a90614f2e9fafa22fcb31e8c05069a58c53d0b92 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 13 Nov 2023 14:31:12 +0100 Subject: [PATCH 1/2] ci: Implement uploading build artifacts Closes #127. --- .ci/pipelines/base-pipeline.yml | 3 --- .ci/pipelines/pr.yml | 13 ++++++++++++- .ci/tasks/build.yml | 8 +++++--- .ci/tasks/upload.sh | 32 ++++++++++++++++++++++++++++++++ .ci/tasks/upload.yml | 24 ++++++++++++++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100755 .ci/tasks/upload.sh create mode 100644 .ci/tasks/upload.yml diff --git a/.ci/pipelines/base-pipeline.yml b/.ci/pipelines/base-pipeline.yml index 88052a5..48d5bb4 100644 --- a/.ci/pipelines/base-pipeline.yml +++ b/.ci/pipelines/base-pipeline.yml @@ -22,7 +22,6 @@ resources: source: uri: https://git.sclu1034.dev/bitsquid_dt/dtmt - jobs: - name: set-pipelines plan: @@ -42,5 +41,3 @@ jobs: gitea_api_key: ((gitea_api_key)) instance_vars: pr: ((.:pr.number)) - - diff --git a/.ci/pipelines/pr.yml b/.ci/pipelines/pr.yml index 6452c93..be1857d 100644 --- a/.ci/pipelines/pr.yml +++ b/.ci/pipelines/pr.yml @@ -1,3 +1,4 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/Config --- # The actual CI pipeline that is run per branch @@ -6,7 +7,7 @@ resources: - name: repo type: git source: - uri: https://git.sclu1034.dev/bitsquid_dt/dtmt + uri: http://forgejo:3000/bitsquid_dt/dtmt branch: ((pr.head.ref)) jobs: @@ -34,6 +35,7 @@ jobs: target: msvc output: artifact ref: ((.:ref)) + gitea_url: http://forgejo:3000 gitea_api_key: ((gitea_api_key)) - name: build-linux @@ -48,4 +50,13 @@ jobs: target: linux output: artifact ref: ((.:ref)) + 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 diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml index ab3a433..c58ed38 100644 --- a/.ci/tasks/build.yml +++ b/.ci/tasks/build.yml @@ -1,7 +1,9 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig --- platform: linux image_resource: + name: ctmt-bi-base-((target)) type: registry-image source: repository: registry.local:5000/dtmt-ci-base-((target)) @@ -11,14 +13,14 @@ inputs: - name: repo outputs: -- name: ((output)) +- name: artifacts params: - CI: true + CI: "true" TARGET: ((target)) GITEA_API_KEY: ((gitea_api_key)) REF: ((ref)) - OUTPUT: ((output)) + OUTPUT: artifacts run: path: .ci/util/run.sh diff --git a/.ci/tasks/upload.sh b/.ci/tasks/upload.sh new file mode 100755 index 0000000..5c0dd59 --- /dev/null +++ b/.ci/tasks/upload.sh @@ -0,0 +1,32 @@ +#!/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" + echo "$url" + 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 -- 2.45.3 From c2cdeedb2cae21ad85f999db2b84b268e70cd7d3 Mon Sep 17 00:00:00 2001 From: Lucas Schwiderski Date: Mon, 13 Nov 2023 15:00:32 +0100 Subject: [PATCH 2/2] ci: Add caches Closes #126. --- .ci/tasks/build.yml | 4 ++++ .ci/tasks/clippy.yml | 8 +++++++- .ci/tasks/upload.sh | 1 - 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.ci/tasks/build.yml b/.ci/tasks/build.yml index c58ed38..3dd4215 100644 --- a/.ci/tasks/build.yml +++ b/.ci/tasks/build.yml @@ -15,6 +15,10 @@ inputs: outputs: - name: artifacts +caches: + - path: repo/target + - path: /usr/local/cargo/registry + params: CI: "true" TARGET: ((target)) diff --git a/.ci/tasks/clippy.yml b/.ci/tasks/clippy.yml index 35735c3..cea0e76 100644 --- a/.ci/tasks/clippy.yml +++ b/.ci/tasks/clippy.yml @@ -1,7 +1,9 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/cappyzawa/concourse-pipeline-jsonschema/master/concourse_jsonschema.json#/definitions/TaskConfig --- platform: linux image_resource: + name: dtmt-ci-base-linux type: registry-image source: repository: registry.local:5000/dtmt-ci-base-linux @@ -10,8 +12,12 @@ image_resource: inputs: - name: repo +caches: + - path: repo/target + - path: /usr/local/cargo/registry + params: - CI: true + CI: "true" GITEA_API_KEY: ((gitea_api_key)) REF: ((ref)) diff --git a/.ci/tasks/upload.sh b/.ci/tasks/upload.sh index 5c0dd59..5e1103e 100755 --- a/.ci/tasks/upload.sh +++ b/.ci/tasks/upload.sh @@ -23,7 +23,6 @@ echo "ref: $ref" for f in dtmt dtmt.exe dtmm dtmm.exe; do if [ -f "$artifacts/$f" ]; then url="$base_url/$(basename -s .exe $f)/$ref/$f" - echo "$url" curl -i -X 'PUT' \ --user "concourse:$GITEA_API_KEY" \ --upload-file "$artifacts/$f" \ -- 2.45.3