diff --git a/.chglog/CHANGELOG.tpl.md b/.chglog/CHANGELOG.tpl.md new file mode 100755 index 000000000..b13ed7edd --- /dev/null +++ b/.chglog/CHANGELOG.tpl.md @@ -0,0 +1,21 @@ +{{ range .Versions }} +## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }}) + +{{ range .CommitGroups -}} +### {{ .Title }} + +{{ range .Commits -}} +* {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }} +{{ end }} +{{ end -}} + +{{- if .NoteGroups -}} +{{ range .NoteGroups -}} +### {{ .Title }} + +{{ range .Notes }} +{{ .Body }} +{{ end }} +{{ end -}} +{{ end -}} +{{ end -}} \ No newline at end of file diff --git a/.chglog/config.yml b/.chglog/config.yml new file mode 100755 index 000000000..47aa346b8 --- /dev/null +++ b/.chglog/config.yml @@ -0,0 +1,32 @@ +style: github +template: CHANGELOG.tpl.md +info: + title: CHANGELOG + repository_url: https://github.com/ArtalkJS/Artalk +options: + tag_filter_pattern: '^v' + sort: "date" + commits: + filters: + Type: + - feat + - fix + - perf + - refactor + - docs + commit_groups: + title_maps: + feat: Features + fix: Bug Fixes + perf: Performance Improvements + refactor: Code Refactoring + docs: Documentation + header: + pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$" + pattern_maps: + - Type + - Scope + - Subject + notes: + keywords: + - BREAKING CHANGE diff --git a/.github/workflows/build-app.yml b/.github/workflows/build-app.yml new file mode 100644 index 000000000..034697238 --- /dev/null +++ b/.github/workflows/build-app.yml @@ -0,0 +1,77 @@ +name: Build App +run-name: Build Go App and Publish + +on: + repository_dispatch: + types: [artalk-release] + +env: + GO_VERSION: '1.19.4' + PKG_NAME: 'github.com/ArtalkJS/Artalk' + DOCKER_IMG: ghcr.io/goreleaser/goreleaser-cross + CACHE_DIR: /tmp/cache/docker-image + +jobs: + build_publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: master + + - name: Docker Image Cache + id: docker-cache + uses: actions/cache@v3 + with: + path: ${{ env.CACHE_DIR }} + key: docker-image-go-cross-${{ env.GO_VERSION }} + + - name: Pull Docker Image + if: steps.docker-cache.outputs.cache-hit != 'true' + run: | + docker pull "${DOCKER_IMG}:v${GO_VERSION}" + mkdir -p "${CACHE_DIR}" + docker save -o "${CACHE_DIR}/go-cross.tar" "${DOCKER_IMG}:v${GO_VERSION}" + + - name: Restore Docker Image from Cache + if: steps.docker-cache.outputs.cache-hit == 'true' + run: docker load -i ${CACHE_DIR}/go-cross.tar + + - name: Setup git-chglog + run: | + curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \ + | grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog + git-chglog --version + + - name: Pre Build + run: |- + # get latest version by tag + VERSION=$(git describe --tags --abbrev=0) + echo "VERSION=${VERSION}" >> $GITHUB_ENV + + # changelog + mkdir -p local + git-chglog ${VERSION} > local/release-notes.md + + # copy config file + cp conf/artalk.example.yml artalk.yml + + # github token + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" > local/.release-env + + - name: Build and Release + run: | + docker run \ + --rm \ + --privileged \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v $(pwd)/sysroot:/sysroot \ + -v $(pwd):/go/src/${PKG_NAME} \ + -w /go/src/${PKG_NAME} \ + -e CGO_ENABLED=1 \ + --env-file local/.release-env \ + ghcr.io/goreleaser/goreleaser-cross:v${GO_VERSION} \ + release --release-notes local/release-notes.md diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml new file mode 100644 index 000000000..dfdf8570f --- /dev/null +++ b/.github/workflows/build-docker.yml @@ -0,0 +1,116 @@ +name: Build Docker +run-name: Build Docker Image and Publish + +on: + repository_dispatch: + types: [artalk-release] + +env: + DOCKER_IMG: artalk/artalk-go + +jobs: + build_publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Checkout latest release tag + run: | + # fetch tags + git fetch --prune --unshallow --tags -f + + # checkout latest version + VERSION=$(git describe --tags --abbrev=0) + git checkout ${VERSION} + + VERSION_SHORT="$(cut -d '.' -f 1,2 <<< ${VERSION#v})" # (i.e "v1.2.3" -> "1.2") + COMMIT_HASH="$(git rev-parse --short HEAD)" + COMMIT_HASH_FULL="$(git rev-parse HEAD)" + + echo "VERSION=${VERSION}" >> $GITHUB_ENV + echo "VERSION_SHORT=${VERSION_SHORT}" >> $GITHUB_ENV + echo "COMMIT_HASH=${COMMIT_HASH}" >> $GITHUB_ENV + echo "COMMIT_HASH_FULL=${COMMIT_HASH_FULL}" >> $GITHUB_ENV + + # https://github.com/docker/login-action + - name: Login to DockerHub + if: github.event_name != 'pull_request' + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + # https://github.com/docker/setup-qemu-action + - name: Setup QEMU + id: qemu + uses: docker/setup-qemu-action@v2 + with: + platforms: 'amd64,arm64' + + # https://github.com/docker/setup-buildx-action + - name: Setup Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: Cache Docker layers + uses: actions/cache@v3 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- + + # TODO: https://github.com/docker/metadata-action/pull/248 + - name: Get Docker Tags and Labels + run: | + TAGS="${DOCKER_IMG}:latest,${DOCKER_IMG}:${VERSION#v},${DOCKER_IMG}:${VERSION_SHORT},${DOCKER_IMG}:sha-${COMMIT_HASH}" + echo "DOCKER_TAGS=${TAGS}" >> $GITHUB_ENV + + # https://github.com/docker/metadata-action + - name: Gen docker meta + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.DOCKER_IMG }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=sha + + # https://github.com/docker/build-push-action + - name: Build and Push + id: docker_build + uses: docker/build-push-action@v3 + with: + builder: ${{ steps.buildx.outputs.name }} + context: ./ + file: ./Dockerfile + platforms: 'linux/amd64,linux/arm64' + push: true + # tags: ${{ steps.meta.outputs.tags }} + tags: ${{ env.DOCKER_TAGS }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=local,src=/tmp/.buildx-cache + cache-to: type=local,dest=/tmp/.buildx-cache + + - name: Comment build info in commit + uses: actions/github-script@v6 + env: + STDOUT: "🐳 Published new docker image: [${{ env.DOCKER_IMG }}](https://hub.docker.com/r/${{ env.DOCKER_IMG }}) (${{ env.VERSION }} / sha-${{ env.COMMIT_HASH }})" + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + github.rest.repos.createCommitComment({ + owner: context.repo.owner, + repo: context.repo.repo, + commit_sha: process.env.COMMIT_HASH_FULL, // context.sha + body: process.env.STDOUT + }) + + - name: Print image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/build-frontend.yml b/.github/workflows/build-frontend.yml new file mode 100644 index 000000000..bfb795434 --- /dev/null +++ b/.github/workflows/build-frontend.yml @@ -0,0 +1,52 @@ +name: Build Frontend +run-name: Build Frontend and Publish + +on: + repository_dispatch: + types: [artalk-release] + +jobs: + build_publish: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: ./ui # set for building frontend + + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Use pnpm + uses: pnpm/action-setup@v2 + with: + version: 7 + + - name: Setup node + uses: actions/setup-node@v3 + with: + node-version: 16.x + registry-url: https://registry.npmjs.org/ + cache: 'pnpm' + + - name: Install dependencies + run: pnpm install + + - name: Build + run: pnpm build + + - name: Publish + run: pnpm publish -F artalk --no-git-checks + env: + NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + + # GitHub Packages + # + # Setup .npmrc file to publish to GitHub Packages + # - uses: actions/setup-node@v2 + # with: + # registry-url: 'https://npm.pkg.github.com' + # # Publish to GitHub Packages + # - run: npm publish + # env: + # NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml deleted file mode 100644 index 8788babf0..000000000 --- a/.github/workflows/docker.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: CI to Docker Hub - -on: - push: - # branches: - # - "master" - tags: - - "v*" - # pull_request: - # branches: - # - "master" - -jobs: - docker: - if: github.repository == 'ArtalkJS/Artalk' - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@master - - run: | - git fetch --prune --unshallow --tags -f - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@master - - # Docker tag 值生成 - # https://github.com/docker/metadata-action - - name: Docker meta - id: meta - uses: docker/metadata-action@v3 - with: - images: | - ${{ secrets.DOCKERHUB_USERNAME }}/artalk-go - tags: | - type=ref,event=branch - type=ref,event=pr - type=semver,pattern={{version}} - type=semver,pattern={{major}}.{{minor}} - type=sha - - # 编译多平台 - # https://github.com/docker/setup-qemu-action - - name: Set up QEMU - id: qemu - uses: docker/setup-qemu-action@v2 - with: - platforms: 'amd64,arm64' # 'all' - - # 缓存 Docker - - name: Cache Docker layers - uses: actions/cache@v2 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - # build docker image - # https://github.com/docker/build-push-action - - name: Build and push - id: docker_build - uses: docker/build-push-action@v2 - with: - builder: ${{ steps.buildx.outputs.name }} - context: ./ - file: ./Dockerfile - platforms: 'linux/amd64,linux/arm64' # ',linux/arm/v7' - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - # 缓存 - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache - - - name: Image digest - run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/.github/workflows/npm.yml b/.github/workflows/npm.yml deleted file mode 100644 index 9a246570c..000000000 --- a/.github/workflows/npm.yml +++ /dev/null @@ -1,80 +0,0 @@ -# https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages -name: NPM Publish - -on: - push: - tags: - - v* - -jobs: - publish: - # prevents this action from running on forks - if: github.repository == 'ArtalkJS/Artalk' - - runs-on: ubuntu-latest - - defaults: - run: - working-directory: ./ui # set for building UI - - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Use pnpm - uses: pnpm/action-setup@v2.2.4 - with: - version: 7.25.0 - - - name: Set node version to 16.x - uses: actions/setup-node@v3 - with: - node-version: 16.x - registry-url: https://registry.npmjs.org/ - cache: 'pnpm' - - - name: Install dependencies - run: pnpm install - - - name: Build - run: pnpm build - - - name: Publish - run: pnpm publish -F artalk --no-git-checks - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - # GitHub Packages - # - # Setup .npmrc file to publish to GitHub Packages - # - uses: actions/setup-node@v2 - # with: - # registry-url: 'https://npm.pkg.github.com' - # # Publish to GitHub Packages - # - run: npm publish - # env: - # NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - # Docs Update - docs-update: - runs-on: ubuntu-latest - steps: - - name: Get the version - id: get_version - run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/} - - - name: Checkout ArtalkDocs - uses: actions/checkout@v3 - with: - repository: ArtalkJS/Docs - token: ${{ secrets.PAT }} - - - name: Update CDN links - run: | - sed -i 's#artalk@.[^/]*#artalk@${{ steps.get_version.outputs.VERSION }}#g' docs/code/ArtalkCDN.json - perl -pi -e 's#"Artalk"(\W+)?:(\W+)?".*?"#"Artalk": "${{ steps.get_version.outputs.VERSION }}"#g' docs/code/ArtalkVersion.json - sed -i 's#artalk@.[^/]*#artalk@${{ steps.get_version.outputs.VERSION }}#g' docs/code/quick-start/cdn.html - - - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Update Artalk CDN link to v${{ steps.get_version.outputs.VERSION }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 65b3bcf08..f9e35002c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,50 +1,93 @@ -name: Release Build +name: 📦 Release New Version +run-name: 📦 Release ${{ inputs.custom || inputs.semver }} by @${{ github.actor }} on: - push: - tags: - - v* + workflow_dispatch: + inputs: + semver: + type: choice + description: Which version you want to increment? + options: + - patch + - minor + - major + required: true + # custom: + # description: 'Custom tag name (i.e v1.0.0-rc.1)' + # required: false + # default: '' + +env: + REPO_DISPATCH_EVENT_TYPE: 'artalk-release' + UI_NPM_PKG_FILE: 'ui/packages/artalk/package.json' jobs: release: runs-on: ubuntu-latest - steps: - - name: checkout code + - name: Checkout Code uses: actions/checkout@v3 - - run: git fetch --prune --unshallow --tags -f - - name: setup go - uses: actions/setup-go@v3 - with: - go-version: '^1.19.4' - - # docker `golang-cross` image cache - # `cache-go-cross-v1-19-4` - - run: mkdir -p ~/docker-cache - - name: docker image cache - id: cache-go-cross-v1-19-4 - uses: actions/cache@v2 + - name: Git Fetch + run: git fetch --prune --unshallow --tags -f + + - name: Setup Node + uses: actions/setup-node@v3 with: - path: ~/docker-cache - # Adjust key to meet your cache time requirements e.g. - # ${{ hashFiles(*) }} can be useful here to invalidate - # cache on file changes - key: cache-go-cross-v1-19-4 + node-version: 16.x + registry-url: https://registry.npmjs.org/ - - if: steps.cache-go-cross-v1-19-4.outputs.cache-hit != 'true' + - name: Handle Version Number run: | - docker pull ghcr.io/goreleaser/goreleaser-cross:v1.19.4 - docker save -o ~/docker-cache/golang-cross.tar ghcr.io/goreleaser/goreleaser-cross:v1.19.4 + if [ ! -z "${{ inputs.custom }}" ]; then + next_version="${{ inputs.custom }}" + else + npm install -g semver + prev_version="$(git describe --tags --abbrev=0)" + echo "prev_version: ${prev_version}" + next_version="v$(semver --increment ${{ inputs.semver }} ${prev_version})" + fi - - if: steps.cache-go-cross-v1-19-4.outputs.cache-hit == 'true' - run: docker load -i ~/docker-cache/golang-cross.tar + if [[ ! "${next_version}" =~ ^v.* ]]; then + echo "[err] custom tag name must be v*." + exit 1 + fi - # build - - name: setup release environment - run: |- - cp conf/artalk.example.yml artalk.yml - echo 'GITHUB_TOKEN=${{secrets.GORELEASER_ACCESS_TOKEN}}' > .release-env + echo "next_version: ${next_version}" + echo "VERSION=${next_version}" >> $GITHUB_ENV - - name: build and release publish - run: make release + - name: Setup git-chglog + run: | + curl -sL $(curl -s https://api.github.com/repos/git-chglog/git-chglog/releases/latest \ + | grep -oP '"https://.+linux_amd64.tar.gz"' | tr -d \") | tar -C /usr/local/bin -xz git-chglog + git-chglog --version + + - name: Version Changelog and Tagging + run: | + if [ ! $(git tag -l "${VERSION}") ]; then + # prepend changelog + changelog=$(git-chglog --next-tag "${VERSION}" "${VERSION}") + echo -e "${changelog}\n" | cat - CHANGELOG.md > temp && mv temp CHANGELOG.md + + # modify the version of `package.json` + perl -i -pe 's/"version": ".*?"/"version": "'${VERSION#v}'"/g' "${UI_NPM_PKG_FILE}" + + # modify the version in docs + perl -pi -e 's#"latest"(\W+)?:(\W+)?".*?"#"latest": "'${VERSION#v}'"#g' docs/code/ArtalkVersion.json + + # git commit and push + git config user.name github-actions[bot] + git config user.email 41898282+github-actions[bot]@users.noreply.github.com + git add CHANGELOG.md "${UI_NPM_PKG_FILE}" + git commit -m "chore: release ${VERSION}" + git tag "${VERSION}" + + git push origin master "${VERSION}" + else + echo "skipped because git tag already exists." + fi + + - name: Repository Dispatch + uses: peter-evans/repository-dispatch@v2 + with: + event-type: ${{ env.REPO_DISPATCH_EVENT_TYPE }} diff --git a/.goreleaser.yml b/.goreleaser.yml index 32b0eaf3b..f499079f7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,11 +17,12 @@ before: # install dependencies - make install - make build-frontend - - make update # build multi-platform builds: - ## Amd 64 + ## ---------------------- + ## Linux + ## ---------------------- # Linux (amd_64) - id: linux-amd64 @@ -30,8 +31,8 @@ builds: goarch: - amd64 env: - - CC=gcc - - CXX=g++ + - CC=x86_64-linux-gnu-gcc + - CXX=x86_64-linux-gnu-g++ binary: "{{.ProjectName}}" main: ./main.go ldflags: &common_ldflags | @@ -39,22 +40,37 @@ builds: -X github.com/ArtalkJS/Artalk/internal/config.CommitHash={{ .ShortCommit }} -s -w - # Windows (amd_64) - - id: windows-amd64 + # Linux (arm_64) + - id: linux-arm64 goos: - - windows + - linux goarch: - - amd64 + - arm64 env: - - CC=x86_64-w64-mingw32-gcc - - CXX=x86_64-w64-mingw32-g++ + - CC=aarch64-linux-gnu-gcc + - CXX=aarch64-linux-gnu-g++ + binary: "{{.ProjectName}}" + main: ./main.go + ldflags: *common_ldflags + + # Linux (arm_v7) + - id: linux-arm7 + goos: + - linux + goarch: + - arm + goarm: + - '7' + env: + - CC=arm-linux-gnueabihf-gcc + - CXX=arm-linux-gnueabihf-g++ binary: "{{.ProjectName}}" main: ./main.go ldflags: *common_ldflags - flags: - # https://go-review.googlesource.com/c/go/+/224588/ - # https://github.com/ArtalkJS/Artalk/issues/35 - - -tags=timetzdata + + ## ---------------------- + ## macOS + ## ---------------------- # Darwin (amd_64) - id: darwin-amd64 @@ -69,48 +85,54 @@ builds: main: ./main.go ldflags: *common_ldflags - ## Arm - - # Linux (arm_v7) - - id: linux-armhf + # Darwin (arm_64) + - id: darwin-arm64 goos: - - linux + - darwin goarch: - - arm - goarm: - - '7' + - arm64 env: - - CC=arm-linux-gnueabihf-gcc - - CXX=arm-linux-gnueabihf-g++ + - CC=oa64-clang + - CXX=oa64-clang++ binary: "{{.ProjectName}}" main: ./main.go ldflags: *common_ldflags - # Linux (arm_64) - - id: linux-arm64 + ## ---------------------- + ## Win + ## ---------------------- + + # Win (amd_64) + - id: windows-amd64 goos: - - linux + - windows goarch: - - arm64 + - amd64 env: - - CC=aarch64-linux-gnu-gcc - - CXX=aarch64-linux-gnu-g++ + - CC=x86_64-w64-mingw32-gcc + - CXX=x86_64-w64-mingw32-g++ binary: "{{.ProjectName}}" main: ./main.go ldflags: *common_ldflags + flags: + # https://go-review.googlesource.com/c/go/+/224588/ + # https://github.com/ArtalkJS/Artalk/issues/35 + &win_common_flags | + -tags=timetzdata - # Darwin (arm_64) - - id: darwin-arm64 + # Win (arm_64) + - id: windows-arm64 goos: - - darwin + - windows goarch: - arm64 env: - - CC=oa64-clang - - CXX=oa64-clang++ + - CC=/llvm-mingw/llvm-mingw/bin/aarch64-w64-mingw32-gcc + - CXX=/llvm-mingw/llvm-mingw/bin/aarch64-w64-mingw32-g++ binary: "{{.ProjectName}}" main: ./main.go ldflags: *common_ldflags + flags: *win_common_flags archives: - id: artalk @@ -118,7 +140,8 @@ archives: - linux-amd64 - darwin-amd64 - windows-amd64 - - linux-armhf + - windows-arm64 + - linux-arm7 - linux-arm64 - darwin-arm64 name_template: "{{.ProjectName}}_v{{.Version}}_{{.Os}}_{{.Arch}}{{.Arm}}" @@ -138,18 +161,17 @@ checksum: snapshot: name_template: "{{.Version}}-SNAPSHOT-{{.ShortCommit}}" -# changelog -changelog: - sort: asc - filters: - exclude: - - '^docs:' - - '^test:' - - '^chore:' +# changelog: +# sort: asc +# filters: +# exclude: +# - '^docs:' +# - '^test:' +# - '^chore:' release: github: owner: ArtalkJS name: Artalk prerelease: auto - draft: true + draft: false diff --git a/Makefile b/Makefile index 7a3cd8f49..93a5e1920 100644 --- a/Makefile +++ b/Makefile @@ -1,12 +1,12 @@ -PACKAGE_NAME := github.com/ArtalkJS/Artalk -BIN_NAME := ./bin/artalk -VERSION ?= $(shell git describe --tags --abbrev=0) -COMMIT_HASH := $(shell git rev-parse --short HEAD) -DEV_VERSION := dev-${COMMIT_HASH} -GO_VERSION ?= 1.19.4 +PKG_NAME := github.com/ArtalkJS/Artalk +BIN_NAME := ./bin/artalk +VERSION ?= $(shell git describe --tags --abbrev=0) +COMMIT_HASH := $(shell git rev-parse --short HEAD) +DEV_VERSION := dev-$(COMMIT_HASH) -HAS_RICHGO := $(shell which richgo) -GOTEST ?= $(if $(HAS_RICHGO), richgo test, go test) +HAS_RICHGO := $(shell which richgo) +GOTEST ?= $(if $(HAS_RICHGO), richgo test, go test) +ARGS ?= server all: install build @@ -15,32 +15,28 @@ install: build: build-frontend go build \ - -ldflags "-s -w -X github.com/ArtalkJS/Artalk/internal/config.Version=${VERSION} \ - -X github.com/ArtalkJS/Artalk/internal/config.CommitHash=${COMMIT_HASH}" \ + -ldflags "-s -w -X $(PKG_NAME)/internal/config.Version=$(VERSION) \ + -X $(PKG_NAME)/internal/config.CommitHash=$(COMMIT_HASH)" \ -o $(BIN_NAME) \ - github.com/ArtalkJS/Artalk + $(PKG_NAME) build-frontend: ./scripts/build-frontend.sh run: all - $(BIN_NAME) server $(ARGS) + $(BIN_NAME) $(ARGS) -debug-build: - @if [ ! -f "pkged/pkged.go" ]; then \ - make install; \ - fi - @echo "Building Artalk ${VERSION} for debugging..." +build-debug: + @echo "Building Artalk $(VERSION) for debugging..." @go build \ - -ldflags " \ - -X github.com/ArtalkJS/Artalk/internal/config.Version=${VERSION} \ - -X github.com/ArtalkJS/Artalk/internal/config.CommitHash=${COMMIT_HASH}" \ + -ldflags "-X $(PKG_NAME)/internal/config.Version=$(VERSION) \ + -X $(PKG_NAME)/internal/config.CommitHash=$(COMMIT_HASH)" \ -gcflags "all=-N -l" \ -o $(BIN_NAME) \ - github.com/ArtalkJS/Artalk + $(PKG_NAME) -dev: debug-build - $(BIN_NAME) server $(ARGS) +dev: build-debug + $(BIN_NAME) $(ARGS) test: $(GOTEST) -timeout 20m ./internal/... @@ -57,41 +53,6 @@ docker-build: docker-push: ./scripts/docker-build.sh --push -release-dry-run: - @docker run \ - --rm \ - --privileged \ - -e CGO_ENABLED=1 \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v `pwd`:/go/src/$(PACKAGE_NAME) \ - -v `pwd`/sysroot:/sysroot \ - -w /go/src/$(PACKAGE_NAME) \ - ghcr.io/goreleaser/goreleaser-cross:v${GO_VERSION} \ - --rm-dist --skip-validate --skip-publish - - -# https://hub.docker.com/r/troian/golang-cross -# https://github.com/troian/golang-cross -# https://goreleaser.com/cmd/goreleaser_release/ -# --skip-validate 参数跳过 git checks (由于 pkger 和 .release-env 文件生成) -release: - @if [ ! -f ".release-env" ]; then \ - echo "\033[91m.release-env is required for release\033[0m";\ - exit 1;\ - fi - docker run \ - --rm \ - --privileged \ - -e CGO_ENABLED=1 \ - --env-file .release-env \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -v `pwd`:/go/src/$(PACKAGE_NAME) \ - -v `pwd`/sysroot:/sysroot \ - -w /go/src/$(PACKAGE_NAME) \ - ghcr.io/goreleaser/goreleaser-cross:v${GO_VERSION} \ - release --rm-dist --skip-validate - -.PHONY: all install build debug-build build-frontend \ - run dev test test-coverage \ - docker-build docker-push \ - release-dry-run release; +.PHONY: all install build build-frontend build-debug \ + dev test test-coverage update-i18n \ + docker-build docker-push; diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 25a605cbb..b9ba9ff20 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -1,7 +1,6 @@ import { defineConfig } from 'vitepress' import iterator from 'markdown-it-for-inline' -import * as ArtalkCDN from '../code/ArtalkCDN.json' -import * as Versions from '../code/ArtalkVersion.json' +import * as Version from '../code/ArtalkVersion.json' export default defineConfig({ title: 'Artalk', @@ -12,7 +11,7 @@ export default defineConfig({ ['link', { rel: 'icon', href: '/favicon.png' }], ['meta', { name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no, target-densitydpi=device-dpi' }], // artalk - ['link', { href: ArtalkCDN.CSS, rel: 'stylesheet' }], + ['link', { href: `https://npm.elemecdn.com/artalk@${Version.latest}/dist/Artalk.css`, rel: 'stylesheet' }], // ['script', { src: ArtalkCDN.JS }], // light gallery ['link', { href: 'https://npm.elemecdn.com/lightgallery@2.3.0/css/lightgallery.css', rel: 'stylesheet' }], @@ -33,7 +32,11 @@ export default defineConfig({ }, config: (md) => { md.use(iterator, 'artalk_version', 'text', function (tokens, idx) { - tokens[idx].content = tokens[idx].content.replace(/:ArtalkVersion:/g, Versions.Artalk.replace(/^v/, '')); + tokens[idx].content = tokens[idx].content.replace(/:ArtalkVersion:/g, Version.latest) + }); + md.use(iterator, 'artalk_version_link', 'link_open', (tokens, idx) => { + const href = tokens[idx].attrGet('href') + tokens[idx].attrSet('href', href.replace(/:ArtalkVersion:/g, Version.latest)) }); }, }, diff --git a/docs/.vitepress/theme/Artalk.vue b/docs/.vitepress/theme/Artalk.vue index 101cf36a3..a7a6e44fa 100644 --- a/docs/.vitepress/theme/Artalk.vue +++ b/docs/.vitepress/theme/Artalk.vue @@ -5,7 +5,7 @@