diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index e7aaf9e2..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,82 +0,0 @@ -name: build - -on: - push: - paths-ignore: - - "**.md" - pull_request: - paths-ignore: - - "**.md" - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} - cancel-in-progress: ${{ github.event_name == 'pull_request' }} - -jobs: - build-targets: - name: Build - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - targets: - - Target: linux/386 - - Target: linux/amd64 - - Target: linux/arm - - Target: linux/arm64 - - Target: linux/loong64 - - Target: linux/ppc64le - - Target: linux/riscv64 - - Target: linux/s390x - - Target: linux/mips - CGO: true - - Target: linux/mips64 - CGO: true - - Target: linux/mips64le - CGO: true - - Target: linux/mipsle - CGO: true - - Target: darwin/amd64 - - Target: darwin/arm64 - - Target: windows/386 - - Target: windows/amd64 - - Target: windows/arm64 - - Target: freebsd/386 - - Target: freebsd/amd64 - - Target: freebsd/arm - - Target: freebsd/arm64 - - Target: openbsd/amd64 - - Target: openbsd/arm64 - - Target: netbsd/amd64 - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: true - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: "1.23" - - - name: Build targets - uses: zijiren233/go-build-action@v1 - env: - SUBMICRO_ARM_DISABLED: true - MICRO_ARM64_DISABLED: true - with: - targets: ${{ matrix.targets.Target }} - cgo-enabled: ${{ matrix.targets.CGO }} - enable-micro: true - config-args: --skip-init-web - - - name: Get artifact name - id: get_artifact_name - run: | - echo "ARTIFACT_NAME=$(echo ${{ matrix.targets.Target }} | tr ':' '-' | tr '/' '-')" >> $GITHUB_OUTPUT - - - name: Upload artifacts - uses: actions/upload-artifact@v4 - with: - name: ${{ steps.get_artifact_name.outputs.ARTIFACT_NAME }} - path: build/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0ef7e022..d9669d45 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,13 +2,85 @@ name: release on: push: + branches: + - "**" tags: - - "v*" + - "v*.*.*" + pull_request: jobs: + release-web: + name: Release Web + runs-on: ubuntu-latest + outputs: + version: ${{ steps.release_meta.outputs.VERSION }} + prerelease: ${{ steps.release_meta.outputs.PRERELEASE }} + release_name: ${{ steps.release_meta.outputs.RELEASE_NAME }} + tag_name: ${{ steps.release_meta.outputs.TAG_NAME }} + steps: + - uses: actions/checkout@v4 + with: + submodules: true + + - name: Use Node.js 18 + uses: actions/setup-node@v4 + with: + node-version: 18.x + + - name: Build + working-directory: synctv-web + run: | + npm install + npm run build + + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: synctv-web + path: synctv-web/dist + + - name: Create dist.zip + run: zip -r dist.zip dist + + - name: Create dist.tar.gz + run: tar -zcvf dist.tar.gz dist + + - name: Get release meta + if: ${{ startsWith(github.ref, 'refs/tags/') }} + id: release_meta + run: | + version=${GITHUB_REF/refs\/tags\/v/} + prerelease=$(echo ${version} | grep -E 'rc|beta|alpha') + release_name="Version ${version}" + if [ -n "${prerelease}" ]; then + release_name="${release_name} (Prerelease)" + fi + tag_name="v${version}" + + echo ::set-output name=VERSION::${version} + echo ::set-output name=PRERELEASE::${prerelease} + echo ::set-output name=RELEASE_NAME::${release_name} + echo ::set-output name=TAG_NAME::${tag_name} + + - name: Release + uses: softprops/action-gh-release@v2 + if: ${{ startsWith(github.ref, 'refs/tags/') }} + with: + token: ${{ secrets.GITHUB_TOKEN }} + draft: false + prerelease: ${{ steps.release_meta.outputs.PRERELEASE }} + append_body: false + fail_on_unmatched_files: true + name: ${{ steps.release_meta.outputs.RELEASE_NAME }} + tag_name: ${{ steps.release_meta.outputs.TAG_NAME }} + files: | + dist.zip + dist.tar.gz + release: name: Release runs-on: ubuntu-latest + needs: release-web strategy: fail-fast: false matrix: @@ -47,15 +119,22 @@ jobs: with: submodules: true + - name: Download Web + uses: actions/download-artifact@v4 + with: + name: synctv-web + path: synctv-web/dist + + - name: Move to public + run: | + rm -rf public/dist/* + cp -r synctv-web/dist/* public/dist/ + - name: Setup Go uses: actions/setup-go@v5 with: go-version: "1.23" - - name: Get version - id: get_version - run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT - - name: Build targets uses: zijiren233/go-build-action@v1 env: @@ -65,17 +144,93 @@ jobs: targets: ${{ matrix.targets.Target }} cgo-enabled: ${{ matrix.targets.CGO }} enable-micro: true - config-args: --version="v${{ steps.get_version.outputs.VERSION }}" + config-args: --version="${{ github.ref.outputs.jobs.release-web.outputs.tag_name }}" - name: Release uses: softprops/action-gh-release@v2 + if: ${{ startsWith(github.ref, 'refs/tags/') }} with: token: ${{ secrets.GITHUB_TOKEN }} draft: false - prerelease: ${{ contains(steps.get_version.outputs.VERSION, 'rc') || contains(steps.get_version.outputs.VERSION, 'beta') || contains(steps.get_version.outputs.VERSION, 'alpha') }} + prerelease: ${{ github.ref.outputs.jobs.release-web.outputs.prerelease }} append_body: false fail_on_unmatched_files: true - name: "Version ${{ steps.get_version.outputs.VERSION }}" - tag_name: "v${{ steps.get_version.outputs.VERSION }}" + name: ${{ github.ref.outputs.jobs.release-web.outputs.release_name }} + tag_name: ${{ github.ref.outputs.jobs.release-web.outputs.tag_name }} files: | build/* + + release-docker: + name: Release Docker + runs-on: ubuntu-latest + needs: release-web + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - name: Download Web + uses: actions/download-artifact@v4 + with: + name: synctv-web + path: synctv-web/dist + + - name: Move to public + run: | + rm -rf public/dist/* + cp -r synctv-web/dist/* public/dist/ + + - name: Has DockerHub + id: has_docker_hub + run: | + echo ::set-output name=HAS_DOCKER_HUB::${{ secrets.DOCKERHUB_USERNAME != '' }} + echo ::set-output name=DOCKERHUB_REPO::${{ secrets.DOCKERHUB_USERNAME != '' && format('{0}/{1}', secrets.DOCKERHUB_USERNAME, 'synctv') || '' }} + + - name: Login to GitHub Container Registry + if: ${{ github.event_name != 'pull_request' }} + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to DockerHub + uses: docker/login-action@v3 + if: ${{ github.event_name != 'pull_request' && steps.has_docker_hub.outputs.HAS_DOCKER_HUB }} + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: | + ${{ steps.has_docker_hub.outputs.DOCKERHUB_REPO }} + ghcr.io/${{ github.repository }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=ref,event=tag + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + type=sha + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v6 + with: + context: . + build-args: VERSION=${{ github.ref.outputs.jobs.release-web.outputs.tag_name }} + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/release_dev.yml b/.github/workflows/release_dev.yml deleted file mode 100644 index f90bd83a..00000000 --- a/.github/workflows/release_dev.yml +++ /dev/null @@ -1,74 +0,0 @@ -name: release_dev - -on: - workflow_dispatch: - -jobs: - release_dev: - name: Release dev - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - targets: - - Target: linux/386 - - Target: linux/amd64 - - Target: linux/arm - - Target: linux/arm64 - - Target: linux/loong64 - - Target: linux/ppc64le - - Target: linux/riscv64 - - Target: linux/s390x - - Target: linux/mips - CGO: true - - Target: linux/mips64 - CGO: true - - Target: linux/mips64le - CGO: true - - Target: linux/mipsle - CGO: true - - Target: darwin/amd64 - - Target: darwin/arm64 - - Target: windows/386 - - Target: windows/amd64 - - Target: windows/arm64 - - Target: freebsd/386 - - Target: freebsd/amd64 - - Target: freebsd/arm - - Target: freebsd/arm64 - - Target: openbsd/amd64 - - Target: openbsd/arm64 - - Target: netbsd/amd64 - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: true - - - name: Setup Go - uses: actions/setup-go@v5 - with: - go-version: "1.23" - - - name: Build targets - uses: zijiren233/go-build-action@v1 - env: - SUBMICRO_ARM_DISABLED: true - MICRO_ARM64_DISABLED: true - with: - targets: ${{ matrix.targets.Target }} - cgo-enabled: ${{ matrix.targets.CGO }} - enable-micro: true - - - name: Release - uses: softprops/action-gh-release@v2 - with: - token: ${{ secrets.GITHUB_TOKEN }} - draft: false - prerelease: true - append_body: false - fail_on_unmatched_files: true - name: "Dev Build" - tag_name: dev - files: | - build/* diff --git a/.github/workflows/release_docker.yml b/.github/workflows/release_docker.yml deleted file mode 100644 index 78c3d7dc..00000000 --- a/.github/workflows/release_docker.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: release_docker - -on: - push: - tags: - - "v*" - -jobs: - release_docker: - name: Release Docker - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - submodules: true - - - name: Docker meta - id: meta - uses: docker/metadata-action@v5 - with: - images: synctvorg/synctv - tags: | - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Login to DockerHub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Get version - id: get_version - run: echo "VERSION=${GITHUB_REF/refs\/tags\/v/}" >> $GITHUB_OUTPUT - - - name: Build and push - id: docker_build - uses: docker/build-push-action@v5 - with: - context: . - build-args: - VERSION=v${{ steps.get_version.outputs.VERSION }} - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 diff --git a/.gitmodules b/.gitmodules index 7fd40282..2ae2d21f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "vendors"] path = vendors url = https://github.com/synctv-org/vendors +[submodule "synctv-web"] + path = synctv-web + url = https://github.com/synctv-org/synctv-web diff --git a/Dockerfile b/Dockerfile index 21bc128c..5756e5f7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,6 @@ FROM golang:1.23-alpine AS builder -ARG VERSION=dev - -ARG SKIP_INIT_WEB - -ENV SKIP_INIT_WEB=${SKIP_INIT_WEB} +ARG VERSION WORKDIR /synctv @@ -16,9 +12,7 @@ RUN curl -sL \ https://raw.githubusercontent.com/zijiren233/go-build-action/refs/tags/v1/build.sh | \ bash -s -- \ --version=${VERSION} \ - --bin-name-no-suffix \ - --force-gcc='gcc -static --static' \ - --force-gxx='g++ -static --static' + --bin-name-no-suffix FROM alpine:latest diff --git a/cmd/version.go b/cmd/version.go index 581a664f..01325fd5 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -15,7 +15,6 @@ var VersionCmd = &cobra.Command{ Long: `All software has versions. This is Sync TV Server's`, Run: func(cmd *cobra.Command, args []string) { fmt.Printf("synctv %s\n", version.Version) - fmt.Printf("- web/version: %s\n", version.WebVersion) fmt.Printf("- git/commit: %s\n", version.GitCommit) fmt.Printf("- os/platform: %s\n", runtime.GOOS) fmt.Printf("- os/arch: %s\n", runtime.GOARCH) diff --git a/internal/version/version.go b/internal/version/version.go index facbf14e..cffc0d7d 100644 --- a/internal/version/version.go +++ b/internal/version/version.go @@ -21,10 +21,9 @@ const ( ) var ( - Version = "dev" - WebVersion = "dev" - GitCommit string - _ = settings.NewStringSetting("version", "placeholder string", model.SettingGroupServer, settings.WithBeforeInitString(func(ss settings.StringSetting, s string) (string, error) { + Version = "dev" + GitCommit string + _ = settings.NewStringSetting("version", "placeholder string", model.SettingGroupServer, settings.WithBeforeInitString(func(ss settings.StringSetting, s string) (string, error) { return Version, nil }), settings.WithBeforeSetString(func(ss settings.StringSetting, s string) (string, error) { return "", errors.New("version can not be set") diff --git a/script/build.config.sh b/script/build.config.sh index 3a4cff93..a6e5432d 100644 --- a/script/build.config.sh +++ b/script/build.config.sh @@ -5,18 +5,6 @@ function parseDepArgs() { VERSION="${1#*=}" shift ;; - --skip-init-web) - SKIP_INIT_WEB="true" - shift - ;; - --web-version=*) - WEB_VERSION="${1#*=}" - shift - ;; - --web-repo=*) - WEB_REPO="${1#*=}" - shift - ;; *) return 1 ;; @@ -26,46 +14,26 @@ function parseDepArgs() { function printDepHelp() { echo -e " ${COLOR_LIGHT_YELLOW}--version=${COLOR_RESET} - Set the build version (default: 'dev')" - echo -e " ${COLOR_LIGHT_YELLOW}--web-version=${COLOR_RESET} - Set the web dependency version (default: same as build version)" - echo -e " ${COLOR_LIGHT_YELLOW}--web-repo=${COLOR_RESET} - Set the web repository (default: '/synctv-web')" - echo -e " ${COLOR_LIGHT_YELLOW}--skip-init-web${COLOR_RESET} - Skip initializing the web dependency" } function printDepEnvHelp() { echo -e " ${COLOR_LIGHT_GREEN}VERSION${COLOR_RESET} - Set the build version (default: 'dev')" - echo -e " ${COLOR_LIGHT_GREEN}WEB_VERSION${COLOR_RESET} - Set the web dependency version (default: same as build version)" - echo -e " ${COLOR_LIGHT_GREEN}WEB_REPO${COLOR_RESET} - Set the web repository (default: '/synctv-web')" - echo -e " ${COLOR_LIGHT_GREEN}SKIP_INIT_WEB${COLOR_RESET} - Skip initializing the web dependency (set to any non-empty value to enable)" } function initDep() { - setDefault "VERSION" "dev" + local git_commit + git_commit="$(git rev-parse --short HEAD)" || git_commit="dev" + setDefault "VERSION" "${git_commit}" + + # replace space, newline, and double quote VERSION="$(echo "$VERSION" | sed 's/ //g' | sed 's/"//g' | sed 's/\n//g')" echo -e "${COLOR_LIGHT_BLUE}Version:${COLOR_RESET} ${COLOR_LIGHT_CYAN}${VERSION}${COLOR_RESET}" - if [[ "${VERSION}" != "dev" ]] && [[ ! "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-beta.*|-rc.*|-alpha.*)?$ ]]; then + if [[ "${VERSION}" != "dev" ]] && [[ "${VERSION}" != "${git_commit}" ]] && [[ ! "${VERSION}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-beta.*|-rc.*|-alpha.*)?$ ]]; then echo -e "${COLOR_LIGHT_RED}Version format error: ${VERSION}${COLOR_RESET}" return 1 fi - setDefault "WEB_VERSION" "${VERSION}" - # 使用 git 命令获取仓库所有者,如果失败则使用默认值 "synctv-org" - local repo_owner - repo_owner=$(git config user.name 2>/dev/null || echo "synctv-org") - setDefault "WEB_REPO" "${repo_owner}/synctv-web" - setDefault "SKIP_INIT_WEB" "" addLDFLAGS "-X 'github.com/synctv-org/synctv/internal/version.Version=${VERSION}'" - setDefault "WEB_VERSION" "${VERSION}" - addLDFLAGS "-X 'github.com/synctv-org/synctv/internal/version.WebVersion=${WEB_VERSION}'" - - local git_commit - git_commit="$(git log --pretty=format:"%h" -1)" || git_commit="unknown" addLDFLAGS "-X 'github.com/synctv-org/synctv/internal/version.GitCommit=${git_commit}'" - - if [[ -z "${SKIP_INIT_WEB}" ]] && [[ -n "${WEB_VERSION}" ]]; then - echo -e "${COLOR_LIGHT_BLUE}Web repository:${COLOR_RESET} ${COLOR_LIGHT_CYAN}${WEB_REPO}${COLOR_RESET}" - echo -e "${COLOR_LIGHT_BLUE}Web version:${COLOR_RESET} ${COLOR_LIGHT_CYAN}${WEB_VERSION}${COLOR_RESET}" - downloadAndUnzip "https://github.com/${WEB_REPO}/releases/download/${WEB_VERSION}/dist.tar.gz" "${SOURCE_DIR}/public/dist" - fi - addTags "jsoniter" } diff --git a/synctv-web b/synctv-web new file mode 160000 index 00000000..f0866f78 --- /dev/null +++ b/synctv-web @@ -0,0 +1 @@ +Subproject commit f0866f78518cb2321665742c81bea71ae49ea3da