diff --git a/.github/workflows/build-docker-artifact.yml b/.github/workflows/build-docker-artifact.yml index 57c57c11b..c45b642c0 100644 --- a/.github/workflows/build-docker-artifact.yml +++ b/.github/workflows/build-docker-artifact.yml @@ -1,11 +1,14 @@ name: Build Docker Image Artifact on: + push: + branches: + - master workflow_dispatch: inputs: tag: description: '镜像标签版本' - required: true + required: false default: 'latest' jobs: @@ -40,17 +43,26 @@ jobs: go mod tidy CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags '-s -w' -o next-terminal ../main.go + - name: Get version + id: version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "VERSION=${{ inputs.tag }}" >> $GITHUB_OUTPUT + else + echo "VERSION=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_OUTPUT + fi + - name: Create package run: | mkdir -p next-terminal cp server/next-terminal next-terminal/ cp config.yml.example next-terminal/config.yml cp LICENSE next-terminal/ - tar zcvf next-terminal-${{ inputs.tag }}-linux-amd64.tar.gz next-terminal/ + tar zcvf next-terminal-${{ steps.version.outputs.VERSION }}-linux-amd64.tar.gz next-terminal/ - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: next-terminal-${{ inputs.tag }}-linux-amd64 - path: next-terminal-${{ inputs.tag }}-linux-amd64.tar.gz + name: next-terminal-${{ steps.version.outputs.VERSION }}-linux-amd64 + path: next-terminal-${{ steps.version.outputs.VERSION }}-linux-amd64.tar.gz retention-days: 7 diff --git a/.github/workflows/build-docker-image.yml b/.github/workflows/build-docker-image.yml index db9554f2f..5e591304e 100644 --- a/.github/workflows/build-docker-image.yml +++ b/.github/workflows/build-docker-image.yml @@ -1,11 +1,14 @@ name: Build Docker Image on: + push: + branches: + - master workflow_dispatch: inputs: tag: description: '镜像标签版本' - required: true + required: false default: 'latest' jobs: @@ -29,17 +32,26 @@ jobs: yarn build cp -r build ../server/resource/ + - name: Get version + id: version + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "VERSION=${{ inputs.tag }}" >> $GITHUB_OUTPUT + else + echo "VERSION=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_OUTPUT + fi + - name: Build Docker image run: | - docker build -t next-terminal:${{ inputs.tag }} . + docker build -t next-terminal:${{ steps.version.outputs.VERSION }} . - name: Save Docker image run: | - docker save next-terminal:${{ inputs.tag }} | gzip > next-terminal-${{ inputs.tag }}.tar.gz + docker save next-terminal:${{ steps.version.outputs.VERSION }} | gzip > next-terminal-${{ steps.version.outputs.VERSION }}.tar.gz - name: Upload artifact uses: actions/upload-artifact@v4 with: - name: next-terminal-docker-${{ inputs.tag }} - path: next-terminal-${{ inputs.tag }}.tar.gz + name: next-terminal-docker-${{ steps.version.outputs.VERSION }} + path: next-terminal-${{ steps.version.outputs.VERSION }}.tar.gz retention-days: 7