From 91ebfaa95651b0dcec544375026eace393481864 Mon Sep 17 00:00:00 2001 From: wuwei Date: Sun, 29 Sep 2024 17:53:02 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E8=87=AA=E5=8A=A8=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=B7=E5=B9=B6=E6=8E=A8=E9=80=81=E6=9B=B4?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build-and-deploy.yml | 30 ++++++++++++++++++++++---- VERSION | 1 + 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 VERSION diff --git a/.github/workflows/build-and-deploy.yml b/.github/workflows/build-and-deploy.yml index adc7cc7..5299fb4 100644 --- a/.github/workflows/build-and-deploy.yml +++ b/.github/workflows/build-and-deploy.yml @@ -12,6 +12,8 @@ jobs: steps: - name: 检出仓库 uses: actions/checkout@v2 + with: + fetch-depth: 0 # 需要获取所有历史记录以创建标签 - name: 设置Node.js uses: actions/setup-node@v2 @@ -36,14 +38,34 @@ jobs: username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} - - name: 清除Docker缓存 + - name: 获取最新的Git标签 + id: tag + run: | + echo "::set-output name=latest-tag::$(git describe --tags --abbrev=0)" + + - name: 计算新版本号 + id: version + run: | + latest=$(echo ${{ steps.tag.outputs.latest-tag }} | cut -d. -f1-2) + minor=$(( $(echo ${{ steps.tag.outputs.latest-tag }} | cut -d. -f3) + 1 )) + echo "::set-output name=new-version::$latest.$minor.0" + + - name: 更新版本号并推送更改 + env: + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} run: | - echo "清除Docker缓存..." - docker builder prune -a --filter "dangling=true" + echo ${{ steps.version.outputs.new-version }} > VERSION + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + echo $GIT_TOKEN | git credential approve + git add VERSION + git commit -m "chore: bump version to ${{ steps.version.outputs.new-version }}" + git push + git push origin --tags - name: 构建并推送Docker镜像 uses: docker/build-push-action@v2 with: context: . push: true - tags: wu529778790/wallpaper.shenzjd.com:latest + tags: wu529778790/wallpaper.shenzjd.com:${{ steps.version.outputs.new-version }} diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..afaf360 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +1.0.0 \ No newline at end of file