Skip to content

Commit

Permalink
feat: support to summarize by replying, introduce unstable docker ima…
Browse files Browse the repository at this point in the history
…ge build (#113)
  • Loading branch information
nekomeowww committed May 25, 2023
1 parent ba30375 commit 721dfc0
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 36 deletions.
35 changes: 5 additions & 30 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Building
name: Unstable Build

on:
push:
tags:
- '**'
workflow_dispatch:

jobs:
Expand All @@ -13,13 +10,6 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Fetch version
id: version
run: |
export LAST_TAGGED_COMMIT=$(git rev-list --tags --max-count=1)
export LAST_TAG=$(git describe --tags $LAST_TAGGED_COMMIT)
echo "version=${LAST_TAG#v}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
Expand All @@ -34,8 +24,7 @@ jobs:
- name: Create image tags
id: dockerinfo
run: |
echo "taglatest=${{ github.repository_owner }}/insights-bot:latest" >> $GITHUB_OUTPUT
echo "tag=${{ github.repository_owner }}/insights-bot:${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT
echo "tagunstable=${{ github.repository_owner }}/insights-bot:unstable" >> $GITHUB_OUTPUT
- name: Build and Push
uses: docker/build-push-action@v4
Expand All @@ -45,24 +34,14 @@ jobs:
push: true
no-cache: false
tags: |
${{ steps.dockerinfo.outputs.taglatest }}
${{ steps.dockerinfo.outputs.tag }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
${{ steps.dockerinfo.outputs.tagunstable }}
ghcr_build:
name: Build for GitHub Container Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Fetch version
id: version
run: |
export LAST_TAGGED_COMMIT=$(git rev-list --tags --max-count=1)
export LAST_TAG=$(git describe --tags $LAST_TAGGED_COMMIT)
echo "version=${LAST_TAG#v}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
Expand All @@ -78,8 +57,7 @@ jobs:
- name: Create image tags
id: dockerinfo
run: |
echo "taglatest=ghcr.io/${{ github.repository_owner }}/insights-bot:latest" >> $GITHUB_OUTPUT
echo "tag=ghcr.io/${{ github.repository_owner }}/insights-bot:${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT
echo "tagunstable=ghcr.io/${{ github.repository_owner }}/insights-bot:unstable" >> $GITHUB_OUTPUT
- name: Build and Push
uses: docker/build-push-action@v4
Expand All @@ -89,8 +67,5 @@ jobs:
push: true
no-cache: false
tags: |
${{ steps.dockerinfo.outputs.taglatest }}
${{ steps.dockerinfo.outputs.tag }}
build-args: |
VERSION=${{ steps.version.outputs.version }}
${{ steps.dockerinfo.outputs.tagunstable }}
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ jobs:
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.4.0
with:
timeout: 10m

unittest:
name: Unit Test
Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Release Build

on:
push:
tags:
- '**'
workflow_dispatch:

jobs:
hub_build:
name: Build for Docker Hub
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Fetch version
id: version
run: |
export LAST_TAGGED_COMMIT=$(git rev-list --tags --max-count=1)
export LAST_TAG=$(git describe --tags $LAST_TAGGED_COMMIT)
echo "version=${LAST_TAG#v}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64

- name: Sign in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}

- name: Create image tags
id: dockerinfo
run: |
echo "taglatest=${{ github.repository_owner }}/insights-bot:latest" >> $GITHUB_OUTPUT
echo "tag=${{ github.repository_owner }}/insights-bot:${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
push: true
no-cache: false
tags: |
${{ steps.dockerinfo.outputs.taglatest }}
${{ steps.dockerinfo.outputs.tag }}
ghcr_build:
name: Build for GitHub Container Registry
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

- name: Fetch version
id: version
run: |
export LAST_TAGGED_COMMIT=$(git rev-list --tags --max-count=1)
export LAST_TAG=$(git describe --tags $LAST_TAGGED_COMMIT)
echo "version=${LAST_TAG#v}" >> $GITHUB_OUTPUT
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
platforms: linux/amd64,linux/arm64

- name: Sign in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Create image tags
id: dockerinfo
run: |
echo "taglatest=ghcr.io/${{ github.repository_owner }}/insights-bot:latest" >> $GITHUB_OUTPUT
echo "tag=ghcr.io/${{ github.repository_owner }}/insights-bot:${{ steps.version.outputs.version }}" >> $GITHUB_OUTPUT
- name: Build and Push
uses: docker/build-push-action@v4
with:
context: ./
file: ./Dockerfile
push: true
no-cache: false
tags: |
${{ steps.dockerinfo.outputs.taglatest }}
${{ steps.dockerinfo.outputs.tag }}
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# 设定构建步骤所使用的来源镜像为基于 Debian 发行版的 Go 1.20 版本镜像
FROM golang:1.20 as builder

ARG VERSION

# 设定 Go 使用 模块化依赖 管理方式:GO111MODULE
RUN GO111MODULE=on

Expand Down
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

<p align="center">
<img src="https://github.com/nekomeowww/insights-bot/workflows/Testing/badge.svg">
<img src="https://github.com/nekomeowww/insights-bot/workflows/Building/badge.svg" />
<img src="https://github.com/nekomeowww/insights-bot/workflows/UnstableBuild/badge.svg" />
<img src="https://github.com/nekomeowww/insights-bot/workflows/ReleasingBuild/badge.svg" />
<a href="https://goreportcard.com/badge/github.com/nekomeowww/insights-bot"><img src="https://goreportcard.com/badge/github.com/nekomeowww/insights-bot" /></a>
<a href="https://hub.docker.com/r/nekomeowww/insights-bot">
<img src="https://img.shields.io/docker/pulls/nekomeowww/insights-bot" />
Expand Down Expand Up @@ -45,15 +46,19 @@ Insights Bot ships with a set of commands, you can use `/help` to get a list of

Command: `/smr`

Arguments: URL
Arguments: URL, Replied message with only URL

Usage:

```txt
/smr https://www.example.com
```

By sending `/smr` command with a URL, the bot will try to summarize the webpage and return the result.
```txt
/smr [Reply to a message with only URL]
```

By sending `/smr` command with a URL or replying to a message that only contains a URL, the bot will try to summarize the webpage and return the result.

#### Enable chat history recapturing

Expand Down
6 changes: 5 additions & 1 deletion internal/bots/telegram/handlers/summarize/smr_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ func (h Handlers) CommandHelp() string {
func (h *Handlers) Handle(c *tgbot.Context) (tgbot.Response, error) {
urlString := c.Update.Message.CommandArguments()
if urlString == "" {
return nil, tgbot.NewMessageError("没有找到链接,可以发送一个有效的链接吗?用法:/smr <链接>").WithReply(c.Update.Message)
if c.Update.Message.ReplyToMessage != nil && c.Update.Message.ReplyToMessage.Text != "" {
urlString = c.Update.Message.ReplyToMessage.Text
} else {
return nil, tgbot.NewMessageError("没有找到链接,可以发送一个有效的链接吗?用法:/smr <链接>").WithReply(c.Update.Message)
}
}

parsedURL, err := url.Parse(urlString)
Expand Down

0 comments on commit 721dfc0

Please sign in to comment.