diff --git a/build/goreleaser.yaml b/build/goreleaser.yaml new file mode 100644 index 000000000..184949283 --- /dev/null +++ b/build/goreleaser.yaml @@ -0,0 +1,531 @@ +# This is an example .goreleaser.yml file with some sensible defaults. +# Make sure to check the documentation at https://goreleaser.com + +before: + hooks: + # You may remove this if you don't use go modules. + - make tidy + - make copyright.add + # you may remove this if you don't need go generate + - go generate ./... + +snapshot: + name_template: "{{ incpatch .Version }}-next" + +# gomod: +# proxy: true + +report_sizes: true + +# metadata: +# mod_timestamp: "{{ .CommitTimestamp }}" + +builds: + - binary: openim-api + id: openim-api + main: ./cmd/openim-api/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-cmdutils + id: openim-cmdutils + main: ./cmd/openim-cmdutils/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-crontask + id: openim-crontask + main: ./cmd/openim-crontask/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-msggateway + id: openim-msggateway + main: ./cmd/openim-msggateway/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-msgtransfer + id: openim-msgtransfer + main: ./cmd/openim-msgtransfer/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-push + id: openim-push + main: ./cmd/openim-push/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-auth + id: openim-rpc-auth + main: ./cmd/openim-rpc/openim-rpc-auth/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-conversation + id: openim-rpc-conversation + main: ./cmd/openim-rpc/openim-rpc-conversation/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-friend + id: openim-rpc-friend + main: ./cmd/openim-rpc/openim-rpc-friend/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-group + id: openim-rpc-group + main: ./cmd/openim-rpc/openim-rpc-group/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-msg + id: openim-rpc-msg + main: ./cmd/openim-rpc/openim-rpc-msg/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-third + id: openim-rpc-third + main: ./cmd/openim-rpc/openim-rpc-third/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + + - binary: openim-rpc-user + id: openim-rpc-user + main: ./cmd/openim-rpc/openim-rpc-user/main.go + goos: + - darwin + - windows + - linux + goarch: + - s390x + - mips64 + - mips64le + - amd64 + - ppc64le + - arm64 + goarm: + - "6" + - "7" + +archives: + - format: tar.gz + # this name template makes the OS and Arch compatible with the results of uname. + name_template: >- + {{ .ProjectName }}_ + {{- title .Os }}_ + {{- if eq .Arch "amd64" }}x86_64 + {{- else if eq .Arch "386" }}i386 + {{- else }}{{ .Arch }}{{ end }} + {{- if .Arm }}v{{ .Arm }}{{ end }} + # use zip for windows archives + files: + - LICENSE + - README.md + - CHANGELOG/* + - CONTRIBUTING.md + - docs/* + - src: "*.md" + dst: docs + + # Strip parent folders when adding files to the archive. + strip_parent: true + + # File info. + # Not all fields are supported by all formats available formats. + # + # Default: copied from the source file + info: + # Templates: allowed (since v1.14) + owner: root + + # Templates: allowed (since v1.14) + group: root + + # Must be in time.RFC3339Nano format. + # + # Templates: allowed (since v1.14) + mtime: "{{ .CommitDate }}" + + # File mode. + mode: 0644 + + format_overrides: + - goos: windows + format: zip + +changelog: + sort: asc + use: github + filters: + exclude: + - "^test:" + - "^chore" + - "merge conflict" + - Merge pull request + - Merge remote-tracking branch + - Merge branch + - go mod tidy + groups: + - title: Dependency updates + regexp: '^.*?(feat|fix)\(deps\)!?:.+$' + order: 300 + - title: "New Features" + regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$' + order: 100 + - title: "Security updates" + regexp: '^.*?sec(\([[:word:]]+\))??!?:.+$' + order: 150 + - title: "Bug fixes" + regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$' + order: 200 + - title: "Documentation updates" + regexp: ^.*?doc(\([[:word:]]+\))??!?:.+$ + order: 400 + - title: "Build process updates" + regexp: ^.*?build(\([[:word:]]+\))??!?:.+$ + order: 400 + - title: Other work + order: 9999 + +# dockers: +# - image_templates: +# - "openimsdk/open-im-server:{{ .Tag }}-amd64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" +# dockerfile: Dockerfile +# use: buildx +# build_flag_templates: +# - "--pull" +# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md" +# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png" +# - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]' +# - "--label=io.artifacthub.package.license=Apace-2.0" +# - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system" +# - "--label=org.opencontainers.image.created={{.Date}}" +# - "--label=org.opencontainers.image.name={{.ProjectName}}" +# - "--label=org.opencontainers.image.revision={{.FullCommit}}" +# - "--label=org.opencontainers.image.version={{.Version}}" +# - "--label=org.opencontainers.image.source={{.GitURL}}" +# - "--platform=linux/amd64" +# extra_files: +# - scripts/entrypoint.sh +# - image_templates: +# - "goreleaser/goreleaser:{{ .Tag }}-arm64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" +# dockerfile: Dockerfile +# use: buildx +# build_flag_templates: +# - "--pull" +# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/Open-IM-Server/main/README.md" +# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/Open-IM-Server/blob/main/assets/logo/openim-logo-green.png" +# - '--label=io.artifacthub.package.maintainers=[{"name":"Xinwei Xiong","email":"3293172751nss@gmail.com"}]' +# - "--label=io.artifacthub.package.license=Apace-2.0" +# - "--label=org.opencontainers.image.description=OpenIM Open source top instant messaging system" +# - "--label=org.opencontainers.image.created={{.Date}}" +# - "--label=org.opencontainers.image.name={{.ProjectName}}" +# - "--label=org.opencontainers.image.revision={{.FullCommit}}" +# - "--label=org.opencontainers.image.version={{.Version}}" +# - "--label=org.opencontainers.image.source={{.GitURL}}" +# - "--platform=linux/arm64" +# goarch: arm64 +# extra_files: +# - scripts/entrypoint.sh + +# docker_manifests: +# - name_template: "goreleaser/goreleaser:{{ .Tag }}" +# image_templates: +# - "goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "goreleaser/goreleaser:{{ .Tag }}-arm64" +# - name_template: "ghcr.io/goreleaser/goreleaser:{{ .Tag }}" +# image_templates: +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" +# - name_template: "goreleaser/goreleaser:latest" +# image_templates: +# - "goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "goreleaser/goreleaser:{{ .Tag }}-arm64" +# - name_template: "ghcr.io/goreleaser/goreleaser:latest" +# image_templates: +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-amd64" +# - "ghcr.io/goreleaser/goreleaser:{{ .Tag }}-arm64" + +nfpms: + - id: packages + builds: + - openim-api + - openim-cmdutils + - openim-crontask + - openim-msggateway + - openim-msgtransfer + - openim-push + - openim-rpc-auth + - openim-rpc-conversation + - openim-rpc-friend + - openim-rpc-group + - openim-rpc-msg + - openim-rpc-third + - openim-rpc-user + # Your app's vendor. + vendor: OpenIMSDK + homepage: https://github.com/OpenIMSDK/Open-IM-Server + maintainer: kubbot + description: |- + Auto sync github labels + kubbot && openimbot + license: MIT + formats: + - apk + - deb + - rpm + - termux.deb # Since: v1.11 + - archlinux # Since: v1.13 + dependencies: + - git + recommends: + - golang + + +# The lines beneath this are called `modelines`. See `:help modeline` +# Feel free to remove those if you don't want/use them. +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# vim: set ts=2 sw=2 tw=0 fo=cnqoj + +# Default: './dist' +dist: ./_output/dist + +# .goreleaser.yaml +milestones: + # You can have multiple milestone configs + - + # Repository for the milestone + # Default is extracted from the origin remote URL + repo: + owner: OpenIMSDK + name: Open-IM-Server + + # Whether to close the milestone + close: true + + # Fail release on errors, such as missing milestone. + fail_on_error: false + + # Name of the milestone + # + # Default: '{{ .Tag }}' + name_template: "Current Release" + +# publishers: +# - name: "fury.io" +# ids: +# - packages +# dir: "{{ dir .ArtifactPath }}" +# cmd: | +# bash -c ' +# if [[ "{{ .Tag }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then +# curl -F package=@{{ .ArtifactName }} https://{{ .Env.FURY_TOKEN }}@push.fury.io/{{ .Env.USERNAME }}/ +# else +# echo "Skipping deployment: Non-production release detected" +# fi' + +checksum: + name_template: "{{ .ProjectName }}_checksums.txt" + algorithm: sha256 + +release: + + prerelease: auto + + footer: | + + ## Welcome to the {{ .Tag }} release of [chat](https://github.com/OpenIMSDK/chat)!🎉🎉! + + **Full Changelog**: https://github.com/OpenIMSDK/Open-IM-Server/compare/{{ .PreviousTag }}...{{ .Tag }} + + ## Helping out + + + We release logs are recorded on [✨CHANGELOG](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CHANGELOG/CHANGELOG.md) + + + For information on versions of OpenIM and how to maintain branches, read [📚this article](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/version.md) + + + If you wish to use mirroring, read OpenIM's [image management policy](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/docs/conversions/images.md) + + **Want to be one of them 😘?** + +

+ + + + + + + + + +

+ + > **Note** + > @openimbot and @kubbot have made great contributions to the community as community 🤖robots(@openimsdk/bot), respectively. + > Thanks to the @openimsdk/openim team for all their hard work on this release. + > Thank you to all the [💕developers and contributors](https://github.com/OpenIMSDK/Open-IM-Server/graphs/contributors), people from all over the world, OpenIM brings us together + > Contributions to this project are welcome! Please see [CONTRIBUTING.md](https://github.com/OpenIMSDK/Open-IM-Server/blob/main/CONTRIBUTING.md) for details. + + ## Get Involved with OpenIM! + + **Here are some ways to get involved with the OpenIM community:** + + 📢 **Slack Channel**: Join our Slack channels for discussions, communication, and support. Click [here](https://join.slack.com/t/openimsdk/shared_invite/zt-1tmoj26uf-_FDy3dowVHBiGvLk9e5Xkg) to join the Open-IM-Server Slack team channel. + + 📧 **Gmail Contact**: If you have any questions, suggestions, or feedback for our open-source projects, please feel free to [contact us via email](https://mail.google.com/mail/?view=cm&fs=1&tf=1&to=winxu81@gmail.com). + + 📖 **Blog**: Stay up-to-date with OpenIM-Server projects and trends by reading our [blog](https://doc.rentsoft.cn/). We share the latest developments, tech trends, and other interesting information related to OpenIM. + + 📱 **WeChat**: Add us on WeChat (QR Code) and indicate that you are a user or developer of Open-IM-Server. We'll process your request as soon as possible. + + Remember, your contributions play a vital role in making OpenIM successful, and we look forward to your active participation in our community! 🙌 \ No newline at end of file diff --git a/scripts/lib/chat.sh b/scripts/lib/chat.sh new file mode 100644 index 000000000..33268cee6 --- /dev/null +++ b/scripts/lib/chat.sh @@ -0,0 +1,165 @@ +# A set of helpers for starting/running chat for tests + +CHAT_VERSION=${CHAT_VERSION:-1.1.0} +CHAT_HOST=${CHAT_HOST:-127.0.0.1} +CHAT_PORT=${CHAT_PORT:-2379} +# This is intentionally not called CHAT_LOG_LEVEL: +# chat checks that and compains when it is set in addition +# to the command line argument, even when both have the same value. +CHAT_LOGLEVEL=${CHAT_LOGLEVEL:-warn} +export OPENIM_INTEGRATION_CHAT_URL="http://${CHAT_HOST}:${CHAT_PORT}" + +openim::chat::validate() { + # validate if in path + command -v chat >/dev/null || { + openim::log::usage "chat must be in your PATH" + openim::log::info "You can use 'hack/install-chat.sh' to install a copy in third_party/." + exit 1 + } + + # validate chat port is free + local port_check_command + if command -v ss &> /dev/null && ss -Version | grep 'iproute2' &> /dev/null; then + port_check_command="ss" + elif command -v netstat &>/dev/null; then + port_check_command="netstat" + else + openim::log::usage "unable to identify if chat is bound to port ${CHAT_PORT}. unable to find ss or netstat utilities." + exit 1 + fi + if ${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}" >/dev/null 2>&1; then + openim::log::usage "unable to start chat as port ${CHAT_PORT} is in use. please stop the process listening on this port and retry." + openim::log::usage "$(${port_check_command} -nat | grep "LISTEN" | grep "[\.:]${CHAT_PORT:?}")" + exit 1 + fi + + # need set the env of "CHAT_UNSUPPORTED_ARCH" on unstable arch. + arch=$(uname -m) + if [[ $arch =~ arm* ]]; then + export CHAT_UNSUPPORTED_ARCH=arm + fi + # validate installed version is at least equal to minimum + version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3) + if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then + export PATH=${OPENIM_ROOT}/third_party/chat:${PATH} + hash chat + echo "${PATH}" + version=$(chat --version | grep Version | head -n 1 | cut -d " " -f 3) + if [[ $(openim::chat::version "${CHAT_VERSION}") -gt $(openim::chat::version "${version}") ]]; then + openim::log::usage "chat version ${CHAT_VERSION} or greater required." + openim::log::info "You can use 'hack/install-chat.sh' to install a copy in third_party/." + exit 1 + fi + fi +} + +openim::chat::version() { + printf '%s\n' "${@}" | awk -F . '{ printf("%d%03d%03d\n", $1, $2, $3) }' +} + +openim::chat::start() { + # validate before running + openim::chat::validate + + # Start chat + CHAT_DIR=${CHAT_DIR:-$(mktemp -d 2>/dev/null || mktemp -d -t test-chat.XXXXXX)} + if [[ -d "${ARTIFACTS:-}" ]]; then + CHAT_LOGFILE="${ARTIFACTS}/chat.$(uname -n).$(id -un).log.DEBUG.$(date +%Y%m%d-%H%M%S).$$" + else + CHAT_LOGFILE=${CHAT_LOGFILE:-"/dev/null"} + fi + openim::log::info "chat --advertise-client-urls ${OPENIM_INTEGRATION_CHAT_URL} --data-dir ${CHAT_DIR} --listen-client-urls http://${CHAT_HOST}:${CHAT_PORT} --log-level=${CHAT_LOGLEVEL} 2> \"${CHAT_LOGFILE}\" >/dev/null" + chat --advertise-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --data-dir "${CHAT_DIR}" --listen-client-urls "${OPENIM_INTEGRATION_CHAT_URL}" --log-level="${CHAT_LOGLEVEL}" 2> "${CHAT_LOGFILE}" >/dev/null & + CHAT_PID=$! + + echo "Waiting for chat to come up." + openim::util::wait_for_url "${OPENIM_INTEGRATION_CHAT_URL}/health" "chat: " 0.25 80 + curl -fs -X POST "${OPENIM_INTEGRATION_CHAT_URL}/v3/kv/put" -d '{"key": "X3Rlc3Q=", "value": ""}' +} + +openim::chat::start_scraping() { + if [[ -d "${ARTIFACTS:-}" ]]; then + CHAT_SCRAPE_DIR="${ARTIFACTS}/chat-scrapes" + else + CHAT_SCRAPE_DIR=$(mktemp -d -t test.XXXXXX)/chat-scrapes + fi + openim::log::info "Periodically scraping chat to ${CHAT_SCRAPE_DIR} ." + mkdir -p "${CHAT_SCRAPE_DIR}" + ( + while sleep 30; do + openim::chat::scrape + done + ) & + CHAT_SCRAPE_PID=$! +} + +openim::chat::scrape() { + curl -s -S "${OPENIM_INTEGRATION_CHAT_URL}/metrics" > "${CHAT_SCRAPE_DIR}/next" && mv "${CHAT_SCRAPE_DIR}/next" "${CHAT_SCRAPE_DIR}/$(date +%s).scrape" +} + + +openim::chat::stop() { + if [[ -n "${CHAT_SCRAPE_PID:-}" ]] && [[ -n "${CHAT_SCRAPE_DIR:-}" ]] ; then + kill "${CHAT_SCRAPE_PID}" &>/dev/null || : + wait "${CHAT_SCRAPE_PID}" &>/dev/null || : + openim::chat::scrape || : + ( + # shellcheck disable=SC2015 + cd "${CHAT_SCRAPE_DIR}"/.. && \ + tar czf chat-scrapes.tgz chat-scrapes && \ + rm -rf chat-scrapes || : + ) + fi + if [[ -n "${CHAT_PID-}" ]]; then + kill "${CHAT_PID}" &>/dev/null || : + wait "${CHAT_PID}" &>/dev/null || : + fi +} + +openim::chat::clean_chat_dir() { + if [[ -n "${CHAT_DIR-}" ]]; then + rm -rf "${CHAT_DIR}" + fi +} + +openim::chat::cleanup() { + openim::chat::stop + openim::chat::clean_chat_dir +} + +openim::chat::install() { + ( + local os + local arch + + os=$(openim::util::host_os) + arch=$(openim::util::host_arch) + + cd "${OPENIM_ROOT}/third_party" || return 1 + if [[ $(readlink chat) == chat-v${CHAT_VERSION}-${os}-* ]]; then + openim::log::info "chat v${CHAT_VERSION} already installed. To use:" + openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\"" + return #already installed + fi + + if [[ ${os} == "darwin" ]]; then + download_file="chat-v${CHAT_VERSION}-${os}-${arch}.zip" + url="https://github.com/chat-io/chat/releases/download/v${CHAT_VERSION}/${download_file}" + openim::util::download_file "${url}" "${download_file}" + unzip -o "${download_file}" + ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat + rm "${download_file}" + elif [[ ${os} == "linux" ]]; then + url="https://github.com/coreos/chat/releases/download/v${CHAT_VERSION}/chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz" + download_file="chat-v${CHAT_VERSION}-${os}-${arch}.tar.gz" + openim::util::download_file "${url}" "${download_file}" + tar xzf "${download_file}" + ln -fns "chat-v${CHAT_VERSION}-${os}-${arch}" chat + rm "${download_file}" + else + openim::log::info "${os} is NOT supported." + fi + openim::log::info "chat v${CHAT_VERSION} installed. To use:" + openim::log::info "export PATH=\"$(pwd)/chat:\${PATH}\"" + ) +} \ No newline at end of file