From 7217232cd29e28ee5b226a84ce081da1ad7e0e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Dachary?= Date: Sat, 5 Nov 2022 00:00:07 +0100 Subject: [PATCH] implementation: Woodpecker based CI Refs: https://codeberg.org/forgejo/forgejo/issues/73 Refs: https://codeberg.org/forgejo/forgejo/issues/101 Refs: https://codeberg.org/woodpecker-plugins/plugin-docker-buildx/issues/51 Refs: https://codeberg.org/forgejo/forgejo/issues/117 --- .woodpecker/compliance.yml | 74 +++++++++++++ .woodpecker/docker-release-version.yml | 72 +++++++++++++ .woodpecker/release-version.yml | 110 +++++++++++++++++++ .woodpecker/testing-amd64.yml | 141 +++++++++++++++++++++++++ Makefile | 2 +- 5 files changed, 398 insertions(+), 1 deletion(-) create mode 100644 .woodpecker/compliance.yml create mode 100644 .woodpecker/docker-release-version.yml create mode 100644 .woodpecker/release-version.yml create mode 100644 .woodpecker/testing-amd64.yml diff --git a/.woodpecker/compliance.yml b/.woodpecker/compliance.yml new file mode 100644 index 0000000000..c9d8857949 --- /dev/null +++ b/.woodpecker/compliance.yml @@ -0,0 +1,74 @@ +platform: linux/amd64 + +branches: + exclude: [ main, release/*, soft-fork/*/*, soft-fork/*/*/*, doc-* ] + +variables: + - &golang_image 'golang:1.19' + - &gitea_test_image 'gitea/test_env:linux-amd64' + - &goproxy_override '' + - &goproxy_setup |- + if [ -n "$${GOPROXY_OVERRIDE:-}" ]; then + export GOPROXY="$${GOPROXY_OVERRIDE}"; + echo "Using goproxy from goproxy_override \"$${GOPROXY}\""; + elif [ -n "$${GOPROXY_DEFAULT:-}" ]; then + export GOPROXY="$${GOPROXY_DEFAULT}"; + echo "Using goproxy from goproxy_default (secret) not displaying"; + else + export GOPROXY="https://proxy.golang.org,direct"; + echo "No goproxy overrides or defaults given, using \"$${GOPROXY}\""; + fi + +workspace: + base: /go + path: src/codeberg/gitea + +pipeline: + deps-backend: + image: *golang_image + pull: true + environment: + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + commands: + - *goproxy_setup + - make deps-backend + + security-check: + image: *golang_image + group: checks + pull: true + environment: + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + commands: + - *goproxy_setup + - make security-check + + lint-backend: + image: *gitea_test_image + group: checks + pull: true + environment: + GOPROXY_OVERRIDE: *goproxy_override + TAGS: 'bindata sqlite sqlite_unlock_notify' + GOSUMDB: 'sum.golang.org' + secrets: + - goproxy_default + commands: + - *goproxy_setup + - make lint-backend + + checks-backend: + image: *gitea_test_image + pull: true + group: checks + environment: + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + commands: + - *goproxy_setup + - make --always-make checks-backend diff --git a/.woodpecker/docker-release-version.yml b/.woodpecker/docker-release-version.yml new file mode 100644 index 0000000000..60ca56a81d --- /dev/null +++ b/.woodpecker/docker-release-version.yml @@ -0,0 +1,72 @@ +platform: linux/amd64 + +when: + event: tag + +depends_on: +- testing-amd64 + +variables: + - &git_image 'docker:git' + - &dind_image 'docker:20.10-dind' + - &buildx_image 'woodpeckerci/plugin-docker-buildx:2.0.0' + - &integration_image 'codeberg.org/forgejo-integration/forgejo' + +pipeline: + fetch-tags: + image: *git_image + pull: true + commands: + - git config --add safe.directory '*' + - git fetch --tags --force + + publish-integration: + image: *buildx_image + pull: true + settings: + platforms: linux/amd64,linux/arm64 + registry: + from_secret: domain + tag: ${CI_COMMIT_TAG##v} + repo: *integration_image + build_args: + - GOPROXY=https://proxy.golang.org,direct + password: + from_secret: releaseteamtoken + username: + from_secret: releaseteamuser + + publish: + image: *dind_image + environment: + INTEGRATION_IMAGE: *integration_image + commands: + - apk --update --no-cache add coredns + - ( echo ".:53 {" ; echo " forward . /etc/resolv.conf"; echo "}" ) > /etc/coredns/Corefile + - coredns -conf /etc/coredns/Corefile & + - /usr/local/bin/dockerd --data-root /var/lib/docker --host=unix:///var/run/docker.sock --dns 172.17.0.3 & + - for i in $$(seq 60) ; do DOCKER_HOST=unix:///var/run/docker.sock docker version && break ; sleep 1 ; done + - tag=${CI_COMMIT_TAG##v} + - docker login -p "$RELEASETEAMTOKEN" -u "$RELEASETEAMUSER" $DOMAIN + - tagged_image=$${INTEGRATION_IMAGE}':'$$tag + - manifests="" + - for arch in arm64 amd64 ; do + - arch_image=${CI_REPO_LINK##https://}':'$$tag-$$arch + - docker pull --platform linux/$$arch $$tagged_image + - docker run --platform linux/$$arch --rm $$tagged_image gitea --version | grep 'built with' + - docker tag $$tagged_image $$arch_image + - docker push $$arch_image + - manifests="$$manifests $$arch_image" + - docker image prune --all --force + - done + - published=${CI_REPO_LINK##https://}':'$$tag + - docker manifest create $$published $$manifests + - docker manifest push $$published + - short_tag=$${tag%.*-*} + - short_published=${CI_REPO_LINK##https://}':'$$short_tag + - docker manifest create $$short_published $$manifests + - docker manifest push $$short_published + secrets: + - releaseteamtoken + - releaseteamuser + - domain diff --git a/.woodpecker/release-version.yml b/.woodpecker/release-version.yml new file mode 100644 index 0000000000..21e4ea4af6 --- /dev/null +++ b/.woodpecker/release-version.yml @@ -0,0 +1,110 @@ +platform: linux/amd64 + +when: + event: tag + +depends_on: +- testing-amd64 + +variables: + - &git_image 'docker:git' + - &node_image 'node:18' + - &golang_image 'golang:1.19' + - &gpg_sign_image 'plugins/gpgsign:1' + - &xgo_image 'techknowlogick/xgo:go-1.19.x' + - &gpg_sign_image 'plugins/gpgsign:1' + - &goproxy_override '' + - &goproxy_setup |- + if [ -n "$${GOPROXY_OVERRIDE:-}" ]; then + export GOPROXY="$${GOPROXY_OVERRIDE}"; + echo "Using goproxy from goproxy_override \"$${GOPROXY}\""; + elif [ -n "$${GOPROXY_DEFAULT:-}" ]; then + export GOPROXY="$${GOPROXY_DEFAULT}"; + echo "Using goproxy from goproxy_default (secret) not displaying"; + else + export GOPROXY="https://proxy.golang.org,direct"; + echo "No goproxy overrides or defaults given, using \"$${GOPROXY}\""; + fi + +workspace: + base: /source + path: / + +pipeline: + fetch-tags: + image: *git_image + pull: true + group: deps + commands: + - git config --add safe.directory '*' + - git fetch --tags --force + + deps-frontend: + image: *node_image + pull: true + group: deps + commands: + - make deps-frontend + + deps-backend: + image: *golang_image + pull: true + group: deps + environment: + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + commands: + - *goproxy_setup + - make deps-backend + + static: + image: *xgo_image + pull: true + commands: + - *goproxy_setup + - curl -sL https://deb.nodesource.com/setup_16.x | bash - && apt-get -qqy install nodejs + - export PATH=$PATH:$GOPATH/bin + - make CI=true LINUX_ARCHS=linux/amd64,linux/arm64,linux/arm-6 release + environment: + TAGS: 'bindata sqlite sqlite_unlock_notify' + DEBIAN_FRONTEND: 'noninteractive' + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + + verifyruns: + image: *golang_image + commands: + - ./dist/release/forgejo-*-amd64 --version | grep 'built with' + - apt-get update + - apt-get install -y qemu-user-static + - /usr/bin/qemu-aarch64-static ./dist/release/forgejo-*-arm64 --version | grep 'built with' + - /usr/bin/qemu-arm-static ./dist/release/forgejo-*-arm-6 --version | grep 'built with' + + gpg-sign: + image: *gpg_sign_image + pull: true + settings: + detach_sign: true + excludes: + - "dist/release/*.sha256" + files: + - "dist/release/*" + key: + from_secret: releaseteamgpg + + release: + image: *golang_image + commands: + - curl -sL https://dl.gitea.io/tea/0.9.0/tea-0.9.0-linux-amd64 > /bin/tea && chmod +x /bin/tea + - REMOTE=$(echo $CI_REPO_LINK | sed -e 's|.*://||' -e 's|/.*||') + - GITEA_SERVER_URL=$CI_REPO_LINK GITEA_SERVER_TOKEN=$RELEASETEAMTOKEN tea login add --name $RELEASETEAMUSER --url $REMOTE + - ASSETS=$(ls dist/release/* | sed -e 's/^/-a /') + - echo "$${CI_COMMIT_TAG##v}" | grep -qi '\-rc' && export RELEASETYPE="--prerelease" && echo "Uploading as Pre-Release" + - echo "$${CI_COMMIT_TAG##v}" | grep -qi '\-test' && export RELEASETYPE="--draft" && echo "Uploading as Draft" + - test $${RELEASETYPE+false} || echo "Uploading as Stable" + - tea release create $ASSETS --tag $CI_COMMIT_TAG --title $CI_COMMIT_TAG $${RELEASETYPE} + secrets: + - releaseteamtoken + - releaseteamuser diff --git a/.woodpecker/testing-amd64.yml b/.woodpecker/testing-amd64.yml new file mode 100644 index 0000000000..656aa51fd0 --- /dev/null +++ b/.woodpecker/testing-amd64.yml @@ -0,0 +1,141 @@ +platform: linux/amd64 + +branches: + exclude: [ main, release/*, soft-fork/*/*, soft-fork/*/*/*, doc-* ] + +depends_on: +- compliance + +variables: + - &git_image 'docker:git' + - &golang_image 'golang:1.19' + - &gitea_test_image 'gitea/test_env:linux-amd64' + - &mysql_image 'mysql:8' + - &pgsql_image 'postgres:10' + - &goproxy_override '' + - &goproxy_setup |- + if [ -n "$${GOPROXY_OVERRIDE:-}" ]; then + export GOPROXY="$${GOPROXY_OVERRIDE}"; + echo "Using goproxy from goproxy_override \"$${GOPROXY}\""; + elif [ -n "$${GOPROXY_DEFAULT:-}" ]; then + export GOPROXY="$${GOPROXY_DEFAULT}"; + echo "Using goproxy from goproxy_default (secret) not displaying"; + else + export GOPROXY="https://proxy.golang.org,direct"; + echo "No goproxy overrides or defaults given, using \"$${GOPROXY}\""; + fi + +services: + mysql8: + image: *mysql_image + pull: true + environment: + MYSQL_ALLOW_EMPTY_PASSWORD: yes + MYSQL_DATABASE: testgitea + + pgsql: + image: *pgsql_image + pull: true + environment: + POSTGRES_DB: test + POSTGRES_PASSWORD: postgres + +workspace: + base: /go + path: src/codeberg/gitea + +pipeline: + fetch-tags: + image: *git_image + pull: true + commands: + - git config --add safe.directory '*' + - git fetch --tags --force + + deps-backend: + image: *golang_image + pull: true + environment: + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + commands: + - *goproxy_setup + - make deps-backend + + tag-pre-condition: + image: *git_image + pull: true + commands: + - git update-ref refs/heads/tag_test ${CI_COMMIT_SHA} + + prepare-test-env: + image: *gitea_test_image + pull: true + commands: + - ./build/test-env-prepare.sh + + build: + image: *gitea_test_image + environment: + GOSUMDB: sum.golang.org + TAGS: bindata sqlite sqlite_unlock_notify + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + commands: + - *goproxy_setup + - su gitea -c './build/test-env-check.sh' + - su gitea -c 'make backend' + + unit-test: + image: *gitea_test_image + environment: + TAGS: 'bindata sqlite sqlite_unlock_notify' + RACE_ENABLED: 'true' + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - github_read_token + - goproxy_default + commands: + - *goproxy_setup + - su gitea -c 'make unit-test-coverage test-check' + + test-mysql8: + group: integration + image: *gitea_test_image + commands: + - *goproxy_setup + - su gitea -c 'timeout -s ABRT 50m make test-mysql8-migration test-mysql8' + environment: + TAGS: 'bindata' + RACE_ENABLED: 'true' + USE_REPO_TEST_DIR: '1' + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + + test-pgsql: + group: integration + image: *gitea_test_image + commands: + - *goproxy_setup + - su gitea -c 'timeout -s ABRT 50m make test-pgsql-migration test-pgsql' + environment: + TAGS: 'bindata' + RACE_ENABLED: 'true' + USE_REPO_TEST_DIR: '1' + GOPROXY_OVERRIDE: *goproxy_override + secrets: + - goproxy_default + + test-sqlite: + group: integration + image: *gitea_test_image + environment: + - USE_REPO_TEST_DIR=1 + - GOPROXY=off + - TAGS=bindata gogit sqlite sqlite_unlock_notify + - TEST_TAGS=bindata gogit sqlite sqlite_unlock_notify + commands: + - su gitea -c 'timeout -s ABRT 120m make test-sqlite-migration test-sqlite' diff --git a/Makefile b/Makefile index 50121fe461..dc1d9f38cf 100644 --- a/Makefile +++ b/Makefile @@ -605,7 +605,7 @@ $(EXECUTABLE): $(GO_SOURCES) $(TAGS_PREREQ) CGO_CFLAGS="$(CGO_CFLAGS)" $(GO) build $(GOFLAGS) $(EXTRA_GOFLAGS) -tags '$(TAGS)' -ldflags '-s -w $(LDFLAGS)' -o $@ .PHONY: release -release: frontend generate release-windows release-linux release-darwin release-copy release-compress vendor release-sources release-docs release-check +release: frontend generate release-linux release-copy release-compress vendor release-sources release-check $(DIST_DIRS): mkdir -p $(DIST_DIRS)