diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml new file mode 100644 index 000000000..4a3ea885e --- /dev/null +++ b/.github/workflows/changelog.yml @@ -0,0 +1,19 @@ +name: auto changelog + +on: + push: + tags: + - '*' + +jobs: + changelog: + name: Create Release + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - run: npx changelogithub # or changelogithub@0.12 if ensure the stable result + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 74e4bbe14..000000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,50 +0,0 @@ -name: docker hub release - -# build master with multi-arch to docker hub - -on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -jobs: - buildx-dockerhub: - if: github.repository == 'jeessy2/ddns-go' - runs-on: ubuntu-latest - env: - DOCKER_REPO: ${{ secrets.DOCKER_USERNAME }}/ddns-go - DOCKER_PLATFORMS: linux/amd64,linux/arm,linux/arm64 - steps: - - name: Checkout - uses: actions/checkout@v3 - - name: Docker meta - id: meta - uses: docker/metadata-action@v4 - with: - images: | - ${{ env.DOCKER_REPO }} - ghcr.io/${{ github.repository }} - - 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 # login to Docker Hub, automatically logout at the end of job - 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.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Run buildx and push - uses: docker/build-push-action@v4 - with: - context: . - push: true # push to docker hub - platforms: ${{ env.DOCKER_PLATFORMS }} - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/dockerhub-description.yml b/.github/workflows/dockerhub-description.yml deleted file mode 100644 index 562ef26e5..000000000 --- a/.github/workflows/dockerhub-description.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Update Docker Hub Description -on: - push: - branches: - - master - paths: - - README.md - - .github/workflows/dockerhub-description.yml - -jobs: - dockerHubDescription: - runs-on: ubuntu-latest - if: github.repository == 'jeessy2/ddns-go' - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Docker Hub Description - uses: peter-evans/dockerhub-description@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - repository: ${{ secrets.DOCKER_USERNAME }}/ddns-go - short-description: ${{ github.event.repository.description }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2f1057432..9b8b23269 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,59 +1,47 @@ name: release on: - push: - # Sequence of patterns matched against refs/tags - tags: - - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 - -permissions: - contents: write + release: + types: [ published ] jobs: - goreleaser: - name: Build - runs-on: ubuntu-latest + release: + strategy: + matrix: + platform: [ ubuntu-latest ] + go-version: [ '1.20' ] + name: Release + runs-on: ${{ matrix.platform }} steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Prerelease + uses: irongut/EditRelease@v1.2.0 with: - fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + id: ${{ github.event.release.id }} + prerelease: true - - name: Set up Go + - name: Setup Go uses: actions/setup-go@v4 with: - go-version-file: 'go.mod' - - - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v4 - if: startsWith(github.ref, 'refs/tags/') - with: - distribution: goreleaser - version: latest - args: release --clean - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + go-version: ${{ matrix.go-version }} - homebrew: - needs: goreleaser - runs-on: ubuntu-latest - container: - image: ghcr.io/homebrew/ubuntu22.04:master - steps: - - name: Set up Homebrew - uses: Homebrew/actions/setup-homebrew@master + - name: Checkout + uses: actions/checkout@v3 with: - test-bot: false + fetch-depth: 0 - - name: Configure Git user - uses: Homebrew/actions/git-user-config@master + - name: Build + run: | + bash build.sh release - - name: Tap formulae repo - run: brew tap ivaquero/chinese + - name: Release latest + uses: irongut/EditRelease@v1.2.0 + with: + token: ${{ secrets.GITHUB_TOKEN }} + id: ${{ github.event.release.id }} + prerelease: false - - name: Bump formulae - uses: Homebrew/actions/bump-formulae@master + - name: Upload assets + uses: softprops/action-gh-release@v1 with: - # Custom GitHub access token with only the 'workflow' scope enabled - token: ${{ secrets.HOMEBREW_COMMITTER_TOKEN }} - formulae: ddns-go ivaquero/chinese/ddns-go + files: build/compress/* \ No newline at end of file diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml deleted file mode 100644 index c665211d4..000000000 --- a/.github/workflows/stale.yml +++ /dev/null @@ -1,24 +0,0 @@ -name: Close stale issues and PRs - -on: - schedule: - - cron: "30 1 * * *" - -jobs: - stale: - permissions: - issues: write # for actions/stale to close stale issues - pull-requests: write # for actions/stale to close stale PRs - runs-on: ubuntu-latest - steps: - - name: Stale - uses: actions/stale@v8 - with: - stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove Stale label or comment or this will be closed in 5 days.' - stale-pr-message: 'This PR is stale because it has been open 30 days with no activity. Remove Stale label or comment or this will be closed in 5 days.' - close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.' - close-pr-message: 'This PR was closed because it has been stalled for 5 days with no activity.' - exempt-issue-labels: 'bug,help wanted,question,documentation,keep' - exempt-pr-labels: 'bug,help wanted,question,documentation,keep' - days-before-stale: 30 - days-before-close: 5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index 748a09a26..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: test - -on: - push: - pull_request: - -jobs: - test: - runs-on: ubuntu-latest - strategy: - matrix: - goarch: [amd64, arm64] - steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version-file: 'go.mod' - - - name: Test - run: | - # Run tests only when GOARCH is amd64, otherwize run builds only. - if [ "${{ matrix.goarch }}" = "amd64" ]; then - make build test - else - GOARCH=${{ matrix.goarch }} make build - fi - - name: Upload artifact - uses: actions/upload-artifact@v3 - with: - name: ddns-go_${{ matrix.goarch }} - path: ddns-go diff --git a/build.sh b/build.sh new file mode 100644 index 000000000..45aa914ac --- /dev/null +++ b/build.sh @@ -0,0 +1,177 @@ +# appName="alist" +appName="ddns-go" +# builtAt="$(date +'%F %T %z')" +# goVersion=$(go version | sed 's/go version //') +# gitAuthor="Xhofe " +# gitCommit=$(git log --pretty=format:"%h" -1) +VERSION=$(shell git describe --tags `git rev-list --tags --max-count=1`) +BUILD_TIME=$(shell date -u +"%Y-%m-%dT%H:%M:%SZ") + +# if [ "$1" = "dev" ]; then + # version="dev" + # webVersion="dev" +# else + # version=$(git describe --abbrev=0 --tags) + # webVersion=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') +# fi + +# echo "backend version: $version" +# echo "frontend version: $webVersion" + +ldflags="\ +-w -s \ +# -X 'github.com/alist-org/alist/v3/internal/conf.BuiltAt=$builtAt' \ +# -X 'github.com/alist-org/alist/v3/internal/conf.GoVersion=$goVersion' \ +# -X 'github.com/alist-org/alist/v3/internal/conf.GitAuthor=$gitAuthor' \ +# -X 'github.com/alist-org/alist/v3/internal/conf.GitCommit=$gitCommit' \ +# -X 'github.com/alist-org/alist/v3/internal/conf.Version=$version' \ +# -X 'github.com/alist-org/alist/v3/internal/conf.WebVersion=$webVersion' \ +-X 'main.version=$(VERSION)' \ +-X 'main.buildTime=$(BUILD_TIME)' \ +" + +FetchWebDev() { + curl -L https://codeload.github.com/alist-org/web-dist/tar.gz/refs/heads/dev -o web-dist-dev.tar.gz + tar -zxvf web-dist-dev.tar.gz + rm -rf public/dist + mv -f web-dist-dev/dist public + rm -rf web-dist-dev web-dist-dev.tar.gz +} + +FetchWebRelease() { + curl -L https://github.com/alist-org/alist-web/releases/latest/download/dist.tar.gz -o dist.tar.gz + tar -zxvf dist.tar.gz + rm -rf public/dist + mv -f dist public + rm -rf dist.tar.gz +} + +BuildWinArm64() { + echo building for windows-arm64 + chmod +x ./wrapper/zcc-arm64 + chmod +x ./wrapper/zcxx-arm64 + export GOOS=windows + export GOARCH=arm64 + export CC=$(pwd)/wrapper/zcc-arm64 + export CXX=$(pwd)/wrapper/zcxx-arm64 + go build -o "$1" -ldflags="$ldflags" -tags=jsoniter . +} + +BuildDev() { + rm -rf .git/ + mkdir -p "dist" + muslflags="--extldflags '-static -fpic' $ldflags" + BASE="https://musl.nn.ci/" + FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross) + for i in "${FILES[@]}"; do + url="${BASE}${i}.tgz" + curl -L -o "${i}.tgz" "${url}" + sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local + done + OS_ARCHES=(linux-musl-amd64 linux-musl-arm64) + CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc) + for i in "${!OS_ARCHES[@]}"; do + os_arch=${OS_ARCHES[$i]} + cgo_cc=${CGO_ARGS[$i]} + echo building for ${os_arch} + export GOOS=${os_arch%%-*} + export GOARCH=${os_arch##*-} + export CC=${cgo_cc} + export CGO_ENABLED=1 + go build -o ./dist/$appName-$os_arch -ldflags="$muslflags" -tags=jsoniter . + done + xgo -targets=windows/amd64,darwin/amd64 -out "$appName" -ldflags="$ldflags" -tags=jsoniter . + mv alist-* dist + cd dist + cp ./alist-windows-amd64.exe ./alist-windows-amd64-upx.exe + upx -9 ./alist-windows-amd64-upx.exe + find . -type f -print0 | xargs -0 md5sum >md5.txt + cat md5.txt +} + +BuildDocker() { + go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter . +} + +BuildRelease() { + rm -rf .git/ + mkdir -p "build" + # muslflags="--extldflags '-static -fpic' $ldflags" + muslflags="--extldflags '-static -fpic' $ldflags" -trimpath + BASE="https://musl.nn.ci/" + # FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross arm-linux-musleabihf-cross mips-linux-musl-cross mips64-linux-musl-cross mips64el-linux-musl-cross mipsel-linux-musl-cross powerpc64le-linux-musl-cross s390x-linux-musl-cross) + FILES=(aarch64-linux-musl-cross) + for i in "${FILES[@]}"; do + url="${BASE}${i}.tgz" + curl -L -o "${i}.tgz" "${url}" + sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local + done + # OS_ARCHES=(linux-musl-amd64 linux-musl-arm64 linux-musl-arm linux-musl-mips linux-musl-mips64 linux-musl-mips64le linux-musl-mipsle linux-musl-ppc64le linux-musl-s390x) + OS_ARCHES=(linux-musl-arm64) + # CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc arm-linux-musleabihf-gcc mips-linux-musl-gcc mips64-linux-musl-gcc mips64el-linux-musl-gcc mipsel-linux-musl-gcc powerpc64le-linux-musl-gcc s390x-linux-musl-gcc) + CGO_ARGS=(aarch64-linux-musl-gcc) + for i in "${!OS_ARCHES[@]}"; do + os_arch=${OS_ARCHES[$i]} + cgo_cc=${CGO_ARGS[$i]} + echo building for ${os_arch} + export GOOS=${os_arch%%-*} + export GOARCH=${os_arch##*-} + export CC=${cgo_cc} + export GO_FLAGS="$muslflags" + # static compilation + export CGO_LDFLAGS="-static" + # export CGO_ENABLED=1 + export CGO_ENABLED=0 + go build -o ./build/$appName-$os_arch -ldflags="$muslflags" -tags=jsoniter . + done + # BuildWinArm64 ./build/alist-windows-arm64.exe + # xgo -out "$appName" -ldflags="$ldflags" -tags=jsoniter . + # why? Because some target platforms seem to have issues with upx compression + # upx -9 ./alist-linux-amd64 + # cp ./alist-windows-amd64.exe ./alist-windows-amd64-upx.exe + # upx -9 ./alist-windows-amd64-upx.exe + # mv ddns-go-* build +} + +MakeRelease() { + cd build + mkdir compress + for i in $(find . -type f -name "$appName-linux-*"); do + cp "$i" "$appName" + tar -czvf compress/"$i".tar.gz "$appName" + rm -f "$appName" + done + for i in $(find . -type f -name "$appName-darwin-*"); do + cp "$i" "$appName" + tar -czvf compress/"$i".tar.gz "$appName" + rm -f "$appName" + done + for i in $(find . -type f -name "$appName-windows-*"); do + cp "$i" "$appName.exe" + zip compress/$(echo $i | sed 's/\.[^.]*$//').zip "$appName.exe" + rm -f "$appName.exe" + done + cd compress + find . -type f -print0 | xargs -0 md5sum >md5.txt + cat md5.txt + cd ../.. +} + +if [ "$1" = "dev" ]; then + FetchWebDev + if [ "$2" = "docker" ]; then + BuildDocker + else + BuildDev + fi +elif [ "$1" = "release" ]; then + # FetchWebRelease + if [ "$2" = "docker" ]; then + BuildDocker + else + BuildRelease + MakeRelease + fi +else + echo -e "Parameter error" +fi diff --git a/config/domains.go b/config/domains.go index 04abf5fff..2b07402d9 100644 --- a/config/domains.go +++ b/config/domains.go @@ -45,7 +45,7 @@ func (d Domain) GetFullDomain() string { } // GetSubDomain 获得子域名,为空返回@ -// 阿里云/腾讯云/dnspod/namecheap 需要 +// 阿里云/腾讯云/dnspod/GoDaddy/namecheap 需要 func (d Domain) GetSubDomain() string { if d.SubDomain != "" { return d.SubDomain diff --git a/dns/godaddy.go b/dns/godaddy.go index ccf6606b9..b7516cdda 100644 --- a/dns/godaddy.go +++ b/dns/godaddy.go @@ -72,7 +72,7 @@ func (g *GoDaddyDNS) updateDomainRecord(recordType string, ipAddr string, domain for _, domain := range domains { err := g.sendReq(http.MethodPut, recordType, domain, &godaddyRecords{godaddyRecord{ Data: ipAddr, - Name: domain.SubDomain, + Name: domain.GetSubDomain(), TTL: g.ttl, Type: recordType, }}) @@ -107,7 +107,7 @@ func (g *GoDaddyDNS) sendReq(method string, rType string, domain *config.Domain, } } path := fmt.Sprintf("https://api.godaddy.com/v1/domains/%s/records/%s/%s", - domain.DomainName, rType, domain.SubDomain) + domain.DomainName, rType, domain.GetSubDomain()) req, err := http.NewRequest(method, path, body) if err != nil {