From 7cf1c7ddf2b56ff8b5333d5cb09f151e995c65cc Mon Sep 17 00:00:00 2001 From: hi2hi Date: Thu, 5 Dec 2024 09:28:56 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E6=B3=A8=E9=87=8A=E6=8E=89=20Docke?= =?UTF-8?q?r=20=E6=9E=84=E5=BB=BA=E5=92=8C=E5=8F=91=E5=B8=83=E5=B7=A5?= =?UTF-8?q?=E4=BD=9C=E6=B5=81=E4=B8=AD=E7=9A=84=20push=20=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=EF=BC=8C=E6=94=B9=E4=B8=BA=E6=89=8B=E5=8A=A8=E8=A7=A6?= =?UTF-8?q?=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/docker-build.yml | 20 +++++++++++++------- .github/workflows/release.yml | 28 +++++++++++++++++++--------- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml index 496650f..cc844a9 100644 --- a/.github/workflows/docker-build.yml +++ b/.github/workflows/docker-build.yml @@ -1,10 +1,11 @@ name: Build and Push Docker Image on: - push: - branches: - - main # 监听 main 分支的 push 操作 - workflow_dispatch: # 手动触发 + workflow_dispatch: + inputs: + version: + description: 'Version to use for the Docker image' + required: false jobs: build: @@ -22,9 +23,14 @@ jobs: - name: Install dependencies run: npm install - - name: Get version from package.json - id: get_version - run: echo "VERSION=$(node -p 'require("./package.json").version')" >> $GITHUB_ENV + - name: Determine version + id: determine_version + run: | + if [ -z "${{ github.event.inputs.version }}" ]; then + echo "VERSION=$(node -p 'require("./package.json").version')" >> $GITHUB_ENV + else + echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV + fi - name: Print version run: echo "Version is $VERSION" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index af9ce57..122f13d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,10 +1,11 @@ name: Build and Release on: - push: - branches: - - main # 监听 main 分支的 push 操作 - workflow_dispatch: # 手动触发支持 + workflow_dispatch: + inputs: + version: + description: 'Version to release' + required: false jobs: build-and-release: @@ -29,20 +30,29 @@ jobs: id: get_version run: echo "::set-output name=version::$(node -p "require('./package.json').version")" + - name: Determine version + id: determine_version + run: | + if [ "${{ github.event.inputs.version }}" ]; then + echo "::set-output name=version::${{ github.event.inputs.version }}" + else + echo "::set-output name=version::${{ steps.get_version.outputs.version }}" + fi + - name: Create Release id: create_release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: - tag_name: v${{ steps.get_version.outputs.version }} - release_name: Release v${{ steps.get_version.outputs.version }} + tag_name: v${{ steps.determine_version.outputs.version }} + release_name: Release v${{ steps.determine_version.outputs.version }} draft: false prerelease: false - name: Package build output run: | - zip -r build-v${{ steps.get_version.outputs.version }}.zip dist + zip -r build-v${{ steps.determine_version.outputs.version }}.zip dist - name: Upload Release Asset uses: actions/upload-release-asset@v1 @@ -50,6 +60,6 @@ jobs: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create_release.outputs.upload_url }} - asset_path: ./build-v${{ steps.get_version.outputs.version }}.zip - asset_name: build-v${{ steps.get_version.outputs.version }}.zip + asset_path: ./build-v${{ steps.determine_version.outputs.version }}.zip + asset_name: build-v${{ steps.determine_version.outputs.version }}.zip asset_content_type: application/zip