diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 4f75ccb3..29137fed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -46,7 +46,7 @@ jobs: run: | python -m pip install --upgrade pip pip install build - - run: sed -i -e "s#\${BUILD_SOURCEBRANCHNAME}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py + - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py - name: Build package run: python -m build --sdist --wheel --outdir dist/ @@ -54,7 +54,7 @@ jobs: with: name: pypi path: dist/ - retention-days: 7 + retention-days: 5 pyinstaller: strategy: @@ -75,10 +75,10 @@ jobs: # Prepare build version and cert - name: Replace build version - run: sed -i${{ fromJSON('["",".temp"]')[matrix.os == 'macos'] }} -e "s#\${BUILD_SOURCEBRANCHNAME}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py + run: sed -i.tmp -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py && rm run.py.tmp shell: bash - name: Copy cert on ubuntu - if: ${{ matrix.os == 'ubuntu' }} + if: runner.os == 'Linux' run: cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem - run: python ./run.py -h @@ -94,14 +94,14 @@ jobs: with: name: ${{ matrix.os }}-py${{ matrix.python-version }} path: dist/ - retention-days: 14 + retention-days: 7 docker: runs-on: ubuntu-latest timeout-minutes: 5 steps: - uses: actions/checkout@v3 - - run: sed -i -e "s#\${BUILD_SOURCEBRANCHNAME}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py + - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py - uses: docker/build-push-action@v3 with: context: . @@ -143,7 +143,7 @@ jobs: packages: write steps: - uses: actions/checkout@v3 - - run: sed -i -e "s#\${BUILD_SOURCEBRANCHNAME}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py + - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py - uses: docker/setup-qemu-action@v2 - uses: docker/setup-buildx-action@v2 - uses: docker/login-action@v2 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 7b61e810..769ed065 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -18,7 +18,7 @@ jobs: packages: write steps: - uses: actions/checkout@v3 - - run: sed -i -e "s#\${BUILD_SOURCEBRANCHNAME}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py + - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py - uses: docker/setup-qemu-action@v2 - uses: docker/setup-buildx-action@v2 - uses: docker/login-action@v2 @@ -52,7 +52,7 @@ jobs: url: https://pypi.org/project/ddns/ steps: - uses: actions/checkout@v3 - - run: sed -i -e "s#\${BUILD_SOURCEBRANCHNAME}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py + - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py - uses: actions/setup-python@v4 with: python-version: "3.x" @@ -66,3 +66,55 @@ jobs: with: password: ${{ secrets.PYPI_API_TOKEN }} print_hash: true + + publish-binary: + strategy: + # fail-fast: false + matrix: + os: [windows, macos, ubuntu] + runs-on: ${{ matrix.os }}-latest + timeout-minutes: 8 + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + - name: Install dependencies + run: pip install pyinstaller + + - name: Replace build version + run: sed -i.tmp -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py && rm run.py.tmp + shell: bash + - name: Copy cert on ubuntu + if: ${{ matrix.os == 'ubuntu' }} + run: cp /etc/ssl/certs/ca-certificates.crt cert.pem && export SSL_CERT_FILE=${PWD}/cert.pem + + - run: pyinstaller --noconfirm --clean ./.build/ddns.spec + - run: ./dist/ddns || test -e config.json + - run: ./dist/ddns -h + + - uses: softprops/action-gh-release@v1 + with: + draft: true + generate_release_notes: false + files: dist/ + + github-release: + runs-on: ubuntu-latest + timeout-minutes: 5 + environment: + name: publish + url: https://github.com/NewFuture/DDNS/releases + permissions: + contents: write + needs: [publish-docker, publish-pypi, publish-binary] + steps: + - uses: actions/checkout@v3 + - run: sed -i -e "s#\${BUILD_VERSION}#${{ github.ref_name }}#" .release/README.md + - uses: softprops/action-gh-release@v1 + with: + draft: false + generate_release_notes: true + files: | + .release/*.sh + .release/*.bat diff --git a/.release/README.md b/.release/README.md index 2fdd5fe8..0e984c7a 100644 --- a/.release/README.md +++ b/.release/README.md @@ -1,32 +1,32 @@ -[![PyPI version](https://img.shields.io/badge/DDNS-${BUILD_SOURCEBRANCHNAME}-1abc9c.svg?style=social)](https://pypi.org/project/ddns/${BUILD_SOURCEBRANCHNAME}/) ![Deploy OK](https://img.shields.io/badge/release-success-brightgreen.svg?style=flat-square) +[![PyPI version](https://img.shields.io/badge/DDNS-${BUILD_VERSION}-1abc9c.svg?style=social)](https://pypi.org/project/ddns/${BUILD_VERSION}/) ![Deploy OK](https://img.shields.io/badge/release-success-brightgreen.svg?style=flat-square) ## 使用二进制文件 ![cross platform](https://img.shields.io/badge/platform-windows_%7C%20linux_%7C%20osx-success.svg?style=flat-square) -* Windows 下载 [ddns.exe](https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/ddns.exe) -* Ubuntu 下载 [ddns](https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/ddns) -* Mac OS X下载 [ddns-osx](https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/ddns-osx) +* Windows 下载 [ddns.exe](https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/ddns.exe) +* Ubuntu 下载 [ddns](https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/ddns) +* Mac OS X下载 [ddns-osx](https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/ddns-osx) 各平台下载/使用方式 * ### Windows - 1. 下载 [`ddns.exe`](https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/ddns.exe) 运行 - 2. [可选] 定时任务 下载 [`create-task.bat`](https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/create-task.bat) 于**相同目录**,以管理员权限运行 + 1. 下载 [`ddns.exe`](https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/ddns.exe) 运行 + 2. [可选] 定时任务 下载 [`create-task.bat`](https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/create-task.bat) 于**相同目录**,以管理员权限运行 * ### Ubuntu ```bash # 1. 下载ddns -curl https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/ddns -#SLo ddns && chmod +x ddns +curl https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/ddns -#SLo ddns && chmod +x ddns # 2. [可选] 定时任务(当前目录): -curl -sSL https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/create-task.sh | bash +curl -sSL https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/create-task.sh | bash ``` * ### Mac OSX ```sh # 命令行下载 -curl https://github.com/NewFuture/DDNS/releases/download/${BUILD_SOURCEBRANCHNAME}/ddns-osx -#SLo ddns && chmod +x ddns +curl https://github.com/NewFuture/DDNS/releases/download/${BUILD_VERSION}/ddns-osx -#SLo ddns && chmod +x ddns ``` ## 使用PIP 安装 ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/ddns.svg?style=flat-square) ![PyPI - Wheel](https://img.shields.io/pypi/wheel/ddns.svg?style=flat-square) Pypi 安装当前版本或者更新最新版本 -* 安装当前版本[current version]: `pip install ddns=${BUILD_SOURCEBRANCHNAME}` +* 安装当前版本[current version]: `pip install ddns=${BUILD_VERSION}` * 更新最新版[update latest version]: `pip install -U ddns` \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 828236f6..00000000 --- a/.travis.yml +++ /dev/null @@ -1,50 +0,0 @@ -language: python -python: - - "2.7" - - "3.7" - -os: - - linux -# - osx - -before_install: - - if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then export PYINSTALLER='pyinstaller==3.6';else export PYINSTALLER=pyinstaller;fi - -# command to install dependencies -install: - - pip install ${PYINSTALLER} - -# command to run tests -script: - - sed -i -e "s/\${BUILD_SOURCEBRANCHNAME}/${TRAVIS_BRANCH}/" -e "s/\${BUILD_DATE}/$(date --iso-8601=seconds)/" run.py - - cp /etc/ssl/certs/ca-certificates.crt cert.pem - - export SSL_CERT_FILE=${PWD}/cert.pem - - pyinstaller --onefile --noconfirm --clean ./.build/ddns.spec - - ./dist/ddns || test -e "config.json" - - ./dist/ddns -h - - -git: - depth: 2 - -deploy: - - provider: releases - token: "${GH_TOKEN}" - skip_cleanup: true - cleanup: false - file: - - "dist/ddns" - on: - tags: true - branch: master - python: '3.7' - - provider: pypi - username: newfuture-bot - password: "${PYPI_PWD}" - skip_cleanup: true - cleanup: false - distributions: "sdist bdist_wheel" # Your distributions here - on: - tags: true - branch: master - python: '3.7' diff --git a/README.md b/README.md index e7491981..1953a78c 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ > 代理模式,支持自动创建域名记录。 [![PyPI](https://img.shields.io/pypi/v/ddns.svg?label=DDNS&style=social)](https://pypi.org/project/ddns/) -[![Build Status](https://github.com/NewFuture/DDNS/actions/workflows/python-build.yml/badge.svg?event=push)](https://github.com/NewFuture/DDNS/actions/workflows/build.yml) +[![Build Status](https://github.com/NewFuture/DDNS/actions/workflows/build.yml/badge.svg?event=push)](https://github.com/NewFuture/DDNS/actions/workflows/build.yml) [![latest deploy](https://vsrm.dev.azure.com/NewFuture-CI/_apis/public/Release/badge/2ab09aad-c4b4-4c57-ab1b-2fb92c485664/1/1)](https://github.com/NewFuture/DDNS/releases/latest) --- diff --git a/run.py b/run.py index c2b9245e..0db1dcbf 100755 --- a/run.py +++ b/run.py @@ -18,7 +18,7 @@ from util.cache import Cache from util.config import init_config, get_config -__version__ = "${BUILD_SOURCEBRANCHNAME}@${BUILD_DATE}" # CI 时会被Tag替换 +__version__ = "${BUILD_VERSION}@${BUILD_DATE}" # CI 时会被Tag替换 __description__ = "automatically update DNS records to dynamic local IP [自动更新DNS记录指向本地IP]" __doc__ = """ ddns[%s] @@ -27,7 +27,7 @@ Copyright (c) New Future (MIT License) """ % (__version__) -environ["DDNS_VERSION"] = "${BUILD_SOURCEBRANCHNAME}" +environ["DDNS_VERSION"] = "${BUILD_VERSION}" if getattr(sys, 'frozen', False): # https://github.com/pyinstaller/pyinstaller/wiki/Recipe-OpenSSL-Certificate diff --git a/setup.py b/setup.py index 29bc877d..f808a93f 100644 --- a/setup.py +++ b/setup.py @@ -39,6 +39,8 @@ ref = environ['GITHUB_REF_NAME'] if ref == 'master' or ref == 'main': # CI version = '0.0.b' + str(int(time())) + elif ref.startswith('v') or ref.startswith('V'): # Tag + version = ref else: # PR version = '0.0.a1' else: