From faca84025a5f83a38c3c4acf0c9ae4403083d3b4 Mon Sep 17 00:00:00 2001 From: Xinwei Xiong <3293172751@qq.com> Date: Mon, 31 Jul 2023 10:53:13 +0800 Subject: [PATCH] feat: test actions (#71) * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * feat: test actions Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> * fix: docker images Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --------- Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com> --- .github/workflows/build-docker-image.yml | 17 +++ .github/workflows/docker-buildx.yml | 46 +++----- .github/workflows/release.yml | 40 ++++++- .github/workflows/scripts-test.yml | 2 +- .github/workflows/test_2.yml | 47 ++++++++ .github/workflows/test_buildx.yml | 37 +++++++ .goreleaser.yaml | 135 ++++++++++++++--------- 7 files changed, 238 insertions(+), 86 deletions(-) create mode 100644 .github/workflows/test_2.yml create mode 100644 .github/workflows/test_buildx.yml diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index 9a497ff52..40de5a953 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -34,6 +34,12 @@ jobs: - name: Check out the repo uses: actions/checkout@v3 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Setup Golang with cache uses: magnetikonline/action-golang-cache@v3 with: @@ -51,6 +57,15 @@ jobs: uses: docker/metadata-action@v4.6.0 with: images: openim/openim-chat + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha - name: Log in to Docker Hub uses: docker/login-action@v2 @@ -62,6 +77,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} @@ -107,6 +123,7 @@ jobs: uses: docker/build-push-action@v4 with: context: . + platforms: linux/amd64,linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta3.outputs.tags }} labels: ${{ steps.meta3.outputs.labels }} diff --git a/.github/workflows/docker-buildx.yml b/.github/workflows/docker-buildx.yml index e3b2c170b..ce7b301ee 100644 --- a/.github/workflows/docker-buildx.yml +++ b/.github/workflows/docker-buildx.yml @@ -51,11 +51,10 @@ jobs: uses: docker/metadata-action@v4 with: # list of Docker images to use as base name for tags - # registry.cn-hangzhou.aliyuncs.com/${{github.repository_owner}}/${{env.IMAGE_NAME}} - # ghcr.io/${{github.repository_owner}}/${{env.IMAGE_NAME}} - images: | openim/${{env.IMAGE_NAME}} + registry.cn-hangzhou.aliyuncs.com/${{github.repository_owner}}/${{env.IMAGE_NAME}} + ghcr.io/${{github.repository_owner}}/${{env.IMAGE_NAME}} # generate Docker tags based on the following events/attributes tags: | @@ -73,33 +72,24 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to AliYun Docker Hub + uses: docker/login-action@v2 + with: + registry: registry.cn-hangzhou.aliyuncs.com + username: ${{ secrets.ALIREGISTRY_USERNAME }} + password: ${{ secrets.ALIREGISTRY_TOKEN }} + - name: Build and release Docker images uses: docker/build-push-action@v4 with: context: . - platforms: linux/amd64,linux/arm64 + # platforms: linux/amd64,linux/arm64 tags: ${{ steps.meta.outputs.tags }},latest - push: ${{ github.event_name != 'pull_request' }} - labels: ${{ steps.meta.outputs.labels }} - - # - name: Log in to GitHub Container Registry - # uses: docker/login-action@v2 - # with: - # registry: ghcr.io - # username: ${{ github.actor }} - # password: ${{ secrets.GITHUB_TOKEN }} - - # - name: Log in to AliYun Docker Hub - # uses: docker/login-action@v2 - # with: - # registry: registry.cn-hangzhou.aliyuncs.com - # username: ${{ secrets.ALIREGISTRY_USERNAME }} - # password: ${{ secrets.ALIREGISTRY_TOKEN }} - - # - name: Build and release Docker images - # uses: docker/build-push-action@v4 - # with: - # context: . - # platforms: linux/amd64,linux/arm64 - # tags: ${{ steps.meta.outputs.tags }},latest - # push: ${{ github.event_name != 'pull_request' }} \ No newline at end of file + push: ${{ github.event_name != 'pull_request' }} \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 32bf70d99..d60e33ce5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,14 +14,43 @@ permissions: jobs: goreleaser: runs-on: ubuntu-latest + env: + DOCKER_CLI_EXPERIMENTAL: "enabled" steps: - - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v3 with: fetch-depth: 0 - - run: git fetch --force --tags + + - name: setup-snapcraft + # FIXME: the mkdirs are a hack for https://github.com/goreleaser/goreleaser/issues/1715 + run: | + sudo apt-get update + sudo apt-get -yq --no-install-suggests --no-install-recommends install snapcraft + mkdir -p $HOME/.cache/snapcraft/download + mkdir -p $HOME/.cache/snapcraft/stage-packages + - uses: actions/setup-go@v4 with: go-version: stable + + - name: set action env cache + uses: actions/cache@v3 + with: + path: | + ./_output/dist/*.deb + ./_output/dist/*.rpm + ./_output/dist/*.apk + key: ${{ github.ref }} + + - uses: sigstore/cosign-installer@v3.1.1 + - uses: anchore/sbom-action/download-syft@v0.14.3 + - uses: crazy-max/ghaction-upx@v2 + with: + install-only: true + - uses: cachix/install-nix-action@v22 + with: + github_access_token: ${{ secrets.GITHUB_TOKEN }} # More assembly might be required: Docker logins, GPG, etc. It all depends # on your needs. - name: Set up QEMU @@ -31,12 +60,14 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Log in to Docker Hub + if: startsWith(github.ref, 'refs/tags/v') uses: docker/login-action@v2 with: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - name: Log in to GitHub Container Registry + if: startsWith(github.ref, 'refs/tags/v') uses: docker/login-action@v2 with: registry: ghcr.io @@ -44,12 +75,17 @@ jobs: password: ${{ secrets.GITHUB_TOKEN }} - name: Log in to AliYun Docker Hub + if: startsWith(github.ref, 'refs/tags/v') uses: docker/login-action@v2 with: registry: registry.cn-hangzhou.aliyuncs.com username: ${{ secrets.ALIREGISTRY_USERNAME }} password: ${{ secrets.ALIREGISTRY_TOKEN }} + # - name: snapcraft-login + # if: startsWith(github.ref, 'refs/tags/v') + # run: snapcraft login --with <(echo "${{ secrets.SNAPCRAFT_TOKEN }}") + - uses: goreleaser/goreleaser-action@v4 with: # either 'goreleaser' (default) or 'goreleaser-pro': diff --git a/.github/workflows/scripts-test.yml b/.github/workflows/scripts-test.yml index 6d254973a..fd62aba9f 100644 --- a/.github/workflows/scripts-test.yml +++ b/.github/workflows/scripts-test.yml @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -name: OpenIM Start Execute Scripts +name: OpenIM Chat Start Execute Scripts on: push: diff --git a/.github/workflows/test_2.yml b/.github/workflows/test_2.yml new file mode 100644 index 000000000..c947e41d2 --- /dev/null +++ b/.github/workflows/test_2.yml @@ -0,0 +1,47 @@ +name: ci2 + +on: + push: + branches: + - main + tags: + - v* + workflow_dispatch: +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - + name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - + name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + platforms: linux/amd64,linux/arm64 + push: true + tags: | + openim/openim-chat:latest + openim/openim-chat:1.0.0 + ghcr.io/openimsdk/openim-chat:latest + ghcr.io/openimsdk/openim-chat:1.0.0 \ No newline at end of file diff --git a/.github/workflows/test_buildx.yml b/.github/workflows/test_buildx.yml new file mode 100644 index 000000000..2d9aa620a --- /dev/null +++ b/.github/workflows/test_buildx.yml @@ -0,0 +1,37 @@ +name: ci + + +on: + push: + branches: + - main + tags: + - v* + workflow_dispatch: + +jobs: + docker: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + - + name: Build and push + uses: docker/build-push-action@v4 + with: + context: . + push: true + tags: openim/openim-chat:latest \ No newline at end of file diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 59ef132e1..564942288 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -198,48 +198,54 @@ changelog: - title: Other work order: 9999 -dockers: - - image_templates: - - "openim/openim-chat:{{ .Tag }}-amd64" - - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-amd64" - - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-amd64" - dockerfile: Dockerfile - use: buildx - build_flag_templates: - - "--pull" - - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/chat/main/README.md" - - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/chat/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" - goarch: amd64 - - - image_templates: - - "openim/openim-chat:{{ .Tag }}-arm64" - - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-arm64" - - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-arm64" - dockerfile: Dockerfile - use: buildx - build_flag_templates: - - "--pull" - - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/chat/main/README.md" - - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/chat/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 +# dockers: +# - image_templates: +# - "openim/openim-chat:{{ .Tag }}-amd64" +# - "ghcr.io/{{ .Env.USERNAME }}/openim-chat:{{ .Tag }}-amd64" +# - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-amd64" +# build_flag_templates: +# - "--pull" +# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/chat/main/README.md" +# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/chat/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" +# ids: | +# - chat +# goos: linux +# goarch: amd64 +# dockerfile: Dockerfile +# use: buildx + +# - image_templates: +# - "openim/openim-chat:{{ .Tag }}-arm64" +# - "ghcr.io/openimsdk/openim-chat:{{ .Tag }}-arm64" +# - "registry.cn-hangzhou.aliyuncs.com/openimsdk/openim-chat:{{ .Tag }}-arm64" +# build_flag_templates: +# - "--pull" +# - "--label=io.artifacthub.package.readme-url=https://raw.githubusercontent.com/OpenIMSDK/chat/main/README.md" +# - "--label=io.artifacthub.package.logo-url=hhttps://github.com/OpenIMSDK/chat/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" +# ids: | +# - chat +# goos: linux +# goarch: arm64 +# dockerfile: Dockerfile +# use: buildx # docker_manifests: # - name_template: "openim/openim-chat:{{ .Tag }}" @@ -323,24 +329,37 @@ milestones: # 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' +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/openim/ + else + echo "Skipping deployment: Non-production release detected" + fi' + +# snapcrafts: +# - name_template: "{{ .ProjectName }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" +# summary: openim is open source instant messaging +# description: | +# OpenIM yyds +# grade: stable +# confinement: classic +# publish: true checksum: name_template: "{{ .ProjectName }}_checksums.txt" algorithm: sha256 +snapshot: + name_template: "{{ .Tag }}-next" + release: + prerelease: auto footer: | ## Welcome to the {{ .Tag }} release of [chat](https://github.com/OpenIMSDK/chat)!🎉🎉! @@ -380,4 +399,10 @@ release: 📱 **WeChat**: Add us on WeChat (QR Code) and indicate that you are a user or developer of chat. 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 + Remember, your contributions play a vital role in making OpenIM successful, and we look forward to your active participation in our community! 🙌 + +# webhook +# announce: +# slack: +# enabled: false +# message_template: "slack {{ .Tag }} is out! Check it out: https://github.com/OpenIMSDK/Open-IM-Server/releases/tag/{{ .Tag }}" \ No newline at end of file