From 48864c4da2c5e041f2aef1a1db8243fd386bc49f Mon Sep 17 00:00:00 2001 From: lauralani Date: Thu, 6 Jul 2023 07:16:11 +0200 Subject: [PATCH] Add CI and test how it goes --- .woodpecker/binary-build.yaml | 56 +++++++++++++++++++++++++++++++++++ .woodpecker/docker-build.yaml | 30 +++++++++++++++++++ .woodpecker/lint.yaml | 7 +++++ 3 files changed, 93 insertions(+) create mode 100644 .woodpecker/binary-build.yaml create mode 100644 .woodpecker/docker-build.yaml create mode 100644 .woodpecker/lint.yaml diff --git a/.woodpecker/binary-build.yaml b/.woodpecker/binary-build.yaml new file mode 100644 index 0000000..ec83e84 --- /dev/null +++ b/.woodpecker/binary-build.yaml @@ -0,0 +1,56 @@ +matrix: + include: + - GOOS: linux + GOARCH: amd64 + - GOOS: linux + GOARCH: arm + GOARM: 6 + - GOOS: linux + GOARCH: arm64 + +steps: + build: + when: + event: tag + secrets: + - FORGEJO_APIKEY + image: golang:1.20-alpine + environment: + - APP_NAME=humble-bot + - FORGE=https://codeberg.org + commands: + - apk add --update --no-cache xz curl jq + - go mod download + - go build -o output/$APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM} main.go + - cd output + - xz --keep --compress $APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM} + - sha256sum $APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM} >> $APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM}.sha256 + - sha256sum $APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM}.xz >> $APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM}.xz.sha256 + - |- + export RELEASE_ID=`curl --location "$FORGE/api/v1/repos/$CI_REPO/releases?limit=10" \ + --header 'Accept: application/json' -s -S \ + --fail-with-body | jq -r ".[] | select (.tag_name==\"$CI_COMMIT_TAG\").id"` + - |- + curl --location "$FORGE/api/v1/repos/$CI_REPO/releases/$RELEASE_ID/assets" \ + --header "Authorization: token $FORGEJO_APIKEY" \ + --header 'Content-Type: multipart/form-data' -s -S \ + --form "attachment=@$APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM};type=application/octet-stream" \ + --fail-with-body + - |- + curl --location "$FORGE/api/v1/repos/$CI_REPO/releases/$RELEASE_ID/assets" \ + --header "Authorization: token $FORGEJO_APIKEY" \ + --header 'Content-Type: multipart/form-data' -s -S \ + --form "attachment=@$APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM}.xz;type=application/octet-stream" \ + --fail-with-body + - |- + curl --location "$FORGE/api/v1/repos/$CI_REPO/releases/$RELEASE_ID/assets" \ + --header "Authorization: token $FORGEJO_APIKEY" \ + --header 'Content-Type: multipart/form-data' -s -S \ + --form "attachment=@$APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM}.sha256;type=application/octet-stream" \ + --fail-with-body + - |- + curl --location "$FORGE/api/v1/repos/$CI_REPO/releases/$RELEASE_ID/assets" \ + --header "Authorization: token $FORGEJO_APIKEY" \ + --header 'Content-Type: multipart/form-data' -s -S \ + --form "attachment=@$APP_NAME-${CI_COMMIT_TAG##v}-${GOOS}-${GOARCH}${GOARM}.xz.sha256;type=application/octet-stream" \ + --fail-with-body \ No newline at end of file diff --git a/.woodpecker/docker-build.yaml b/.woodpecker/docker-build.yaml new file mode 100644 index 0000000..fd76a36 --- /dev/null +++ b/.woodpecker/docker-build.yaml @@ -0,0 +1,30 @@ +steps: + docker-deploy-push: + when: + - event: push + branch: main + image: woodpeckerci/plugin-docker-buildx + settings: + dockerfile: Dockerfile + platforms: linux/arm/v7,linux/arm64/v8,linux/amd64 + repo: codeberg.org/lauralani/ + registry: codeberg.org + tags: latest + username: lauralani + password: + from_secret: FORGEJO_APIKEY + + docker-deploy-tag: + when: + event: + - tag + image: woodpeckerci/plugin-docker-buildx + settings: + dockerfile: Dockerfile + platforms: linux/arm/v7,linux/arm64/v8,linux/amd64 + repo: codeberg.org/lauralani/humble-bot + registry: codeberg.org + auto_tag: true + username: lauralani + password: + from_secret: FORGEJO_APIKEY \ No newline at end of file diff --git a/.woodpecker/lint.yaml b/.woodpecker/lint.yaml new file mode 100644 index 0000000..d6d3e8c --- /dev/null +++ b/.woodpecker/lint.yaml @@ -0,0 +1,7 @@ +steps: + go-lint: + image: golangci/golangci-lint + commands: + - golangci-lint run + when: + event: ["push", "pull_request", "manual"] \ No newline at end of file