From e088ad6990369f76ee2f9ffb3de35ee8d8507c01 Mon Sep 17 00:00:00 2001 From: huoxue Date: Fri, 29 Dec 2023 19:19:40 +0800 Subject: [PATCH] add ci --- .gitea/workflows/ci.yml | 84 +++++++++++++++++++++------ .gitea/workflows/push-to-docker.yml | 89 ----------------------------- .gitea/workflows/release.yml | 31 ---------- .goreleaser.yml | 27 ++------- Dockerfile | 4 +- 5 files changed, 71 insertions(+), 164 deletions(-) delete mode 100644 .gitea/workflows/push-to-docker.yml delete mode 100644 .gitea/workflows/release.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 6ff12c5..29fdda7 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -3,13 +3,11 @@ name: CI on: [push, pull_request] env: - BINARY_PREFIX: "qinglong-go_" - BINARY_SUFFIX: "" + + BINARY_Name: "qinglong-go" COMMIT_ID: "${{ github.sha }}" PR_PROMPT: "::warning:: Build artifact will not be uploaded due to the workflow is trigged by pull request." LD_FLAGS: "-w -s" - HTTP_PROXY: "http://172.17.0.1:7890" - HTTPS_PROXY: "http://172.17.0.1:7890" GOPROXY: "https://goproxy.cn,direct" jobs: @@ -17,31 +15,79 @@ jobs: name: Build binary CI runs-on: ubuntu-latest container: - image: node:16-bullseye + image: ghcr.io/catthehacker/ubuntu:act-latest # 持久化工具目录 steps: - name: Checkout - uses: actions/checkout@v3 + uses: https://gh.huoxue.store/actions/checkout@v3 with: fetch-depth: 0 - name: setup go - uses: https://github.com/actions/setup-go@v4 - with: - go-version: '1.20' + run: | + wget https://studygolang.com/dl/golang/go1.21.3.linux-amd64.tar.gz + tar -xzf ./go1.21.3.linux-amd64.tar.gz -C /usr/local + echo 'export GOROOT=/usr/local/go' >> $GITHUB_ENV + ln -s /usr/local/go/bin/go /usr/bin/go + wget https://huoxue.link:12300/api/packages/huoxue1/generic/goreleaser/amd64_latest/goreleaser.tar.gz + tar -xzvf ./goreleaser.tar.gz -C /usr/local + rm ./go1.21.3.linux-amd64.tar.gz + rm ./goreleaser.tar.gz + ln -s /usr/local/goreleaser /usr/bin/goreleaser - name: Fetch all tags run: git fetch --force --tags - - name: Run GoReleaser - uses: https://huoxue.link:12300/huoxue1/goreleaser-action@master - with: - version: latest - args: build --snapshot + - name: Check snapshot + if: "!startsWith(github.ref, 'refs/tags/')" + id: snapshot + run: echo '::set-output name=ARG::--snapshot' + - name: push release + if: "startsWith(github.ref, 'refs/tags/')" + run: | + export GITEA_TOKEN=${{ secrets.TOKEN }} + goreleaser release --timeout 5h30m --clean env: GITEA_TOKEN: ${{ secrets.TOKEN }} - # - name: upload-artifact - # uses: actions/upload-artifact@v3 - # with: - # name: my-artifact - # path: dist/*/* + - name: Run GoReleaser + if: "!startsWith(github.ref, 'refs/tags/')" + run: | + export GITEA_TOKEN=${{ secrets.TOKEN }} + goreleaser build --snapshot --timeout 5h30m --clean + env: + GITEA_TOKEN: ${{ secrets.TOKEN }} + - name: Set up QEMU + id: qemu + uses: https://gh.huoxue.store/docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + id: buildx + uses: https://gh.huoxue.store/docker/setup-buildx-action@v2 + - name: Docker meta + id: meta + uses: https://gh.huoxue.store/docker/metadata-action@v4 + with: + images: huoxue.link:12300/huoxue1/qinglong-go + tags: | + type=raw,value=latest + type=ref,event=tag + - name: Docker Login + if: github.event_name != 'pull_request' + uses: https://gh.huoxue.store/docker/login-action@v2 + with: + registry: huoxue.link:12300 + username: ${{ secrets.USERNAME }} + password: ${{ secrets.PASSWORD }} + - name: Build and push + id: docker_build + uses: https://gh.huoxue.store/docker/build-push-action@v3 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + platforms: linux/amd64,linux/arm64 + tags: ${{ steps.meta.outputs.tags }} + cache-from: type=gha + cache-to: type=gha,mode=max + shm-size: 2g + ulimit: core=0:0 + + diff --git a/.gitea/workflows/push-to-docker.yml b/.gitea/workflows/push-to-docker.yml deleted file mode 100644 index 405ce84..0000000 --- a/.gitea/workflows/push-to-docker.yml +++ /dev/null @@ -1,89 +0,0 @@ -name: docker build - -on: - push: - branches: - - 'Main' - tags: - - '*' - pull_request: - branches: - - 'Main' - -jobs: - build: - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Fetch all tags - run: git fetch --force --tags - - - name: Set up Go - uses: actions/setup-go@v3 - with: - go-version: "1.20" - - - name: Cache Go modules - uses: actions/cache@v3 - with: - path: | - ~/.cache/go-build - ~/go/pkg/mod - key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-go- - - - name: Set up QEMU - id: qemu - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@v2 - - - name: Check snapshot - if: "!startsWith(github.ref, 'refs/tags/')" - id: snapshot - run: echo '::set-output name=ARG::--snapshot' - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v3 - with: - distribution: goreleaser - version: latest - args: build --rm-dist --id docker ${{ steps.snapshot.outputs.ARG }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: huoxue1/qinglong-go - tags: | - type=raw,value=latest - type=ref,event=tag - - - name: Docker Login - if: github.event_name != 'pull_request' - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v3 - with: - context: . - push: ${{ github.event_name != 'pull_request' }} - platforms: linux/amd64,linux/arm64,linux/386,linux/arm - tags: ${{ steps.meta.outputs.tags }} - cache-from: type=gha - cache-to: type=gha,mode=max - ulimit: core=0:0 diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml deleted file mode 100644 index 82fd6a6..0000000 --- a/.gitea/workflows/release.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: release - -on: - push: - tags: - - 'v*' - -jobs: - goreleaser: - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v2.3.4 - with: - fetch-depth: 0 - - - name: Set up Go - uses: actions/setup-go@v2 - with: - go-version: '1.20' - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v2 - with: - version: latest - args: release --rm-dist - env: - GITHUB_TOKEN: ${{ secrets.TOKEN }} - - - diff --git a/.goreleaser.yml b/.goreleaser.yml index a908eec..c221725 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,7 +5,7 @@ before: - go mod tidy builds: - - id: nowin + - id: docker env: - CGO_ENABLED=0 - GO111MODULE=on @@ -19,19 +19,7 @@ builds: - -trimpath ldflags: - -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION=v{{.Version}} - - id: win - env: - - CGO_ENABLED=0 - - GO111MODULE=on - goos: - - windows - goarch: - - amd64 - mod_timestamp: "{{ .CommitTimestamp }}" - flags: - - -trimpath - ldflags: - - -s -w -X github.com/huoxue1/qinglong-go/service/config.VERSION.VERSION=v{{.Version}} + checksum: name_template: "{{ .ProjectName }}_checksums.txt" changelog: @@ -47,17 +35,10 @@ changelog: - go mod tidy archives: - - id: binary - builds: - - win - name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" - format_overrides: - - goos: windows - format: binary + - id: nowin builds: - - nowin - - win + - docker name_template: "{{ .ProjectName }}_{{ .Os }}_{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}" format_overrides: - goos: windows diff --git a/Dockerfile b/Dockerfile index a0c9901..c30c4f4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,8 +46,8 @@ RUN set -x \ && rm -rf /root/.npm \ && mkdir -p ${QL_DIR}/data \ && cd ${QL_DIR} \ - && wget https://github.com/huoxue1/qinglong/releases/download/v1.0.1/static.tar.gz \ - && tar -xzvf static.tar.gz + && wget https://huoxue.link:12300/api/packages/huoxue1/generic/front-qinglong-go/latest/front-qinglong-go.tar.gz \ + && tar -xzvf front-qinglong-go.tar.gz COPY ./dist/docker_linux_$TARGETARCH*/qinglong-go ${QL_DIR}/ql