From d9812162d1680b6a2916849804b8914a90ea3559 Mon Sep 17 00:00:00 2001 From: Evgeny Snitko Date: Tue, 26 Aug 2025 23:20:13 +0400 Subject: [PATCH 1/2] split ci --- .github/workflows/{build.yml => publish.yml} | 75 ++++++++------------ .github/workflows/test.yml | 28 ++++++++ 2 files changed, 56 insertions(+), 47 deletions(-) rename .github/workflows/{build.yml => publish.yml} (52%) create mode 100644 .github/workflows/test.yml diff --git a/.github/workflows/build.yml b/.github/workflows/publish.yml similarity index 52% rename from .github/workflows/build.yml rename to .github/workflows/publish.yml index d4f68a4..823f09a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/publish.yml @@ -1,4 +1,4 @@ -name: Build +name: Publish on: pull_request: @@ -8,68 +8,49 @@ on: workflow_dispatch: inputs: tag_name: - description: 'Tag name' - required: true - -concurrency: - group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} - cancel-in-progress: true + description: 'Tag name' + default: '' + required: false jobs: - tests: - runs-on: cattery-gce - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Start MongoDB - uses: supercharge/mongodb-github-action@1.12.0 - with: - mongodb-replica-set: rs0 - mongodb-port: 27017 - - - name: run tests - run: go test -C src ./... - build: - needs: [tests] permissions: contents: write runs-on: cattery-gce + if: github.event.inputs.tag_name != '' env: VERSION: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name || github.sha }} steps: - - name: Checkout code - uses: actions/checkout@v4 + - name: Checkout code + uses: actions/checkout@v4 - - name: Set up Go - uses: actions/setup-go@v5 - with: - go-version: '1.24' + - name: Set up Go + uses: actions/setup-go@v5 + with: + go-version: '1.24' - - name: Install dependencies - run: go mod download -C src + - name: Install dependencies + run: go mod download -C src - - name: Build - run: go build -C src -o ../bin/cattery_linux_x86_${{ env.VERSION }} -ldflags="-X cattery/cmd.Version=${{ env.VERSION }}" + - name: Build + run: go build -C src -o ../bin/cattery_linux_x86_${{ env.VERSION }} -ldflags="-X cattery/cmd.Version=${{ env.VERSION }}" - - run: ls -la bin/ + - run: ls -la bin/ - - name: create-release - if: github.event_name == 'workflow_dispatch' - uses: softprops/action-gh-release@v2 - with: - tag_name: ${{ github.event.inputs.tag_name }} - name: v${{ github.event.inputs.tag_name }} - draft: true - token: ${{ github.token }} - target_commitish: ${{ github.sha }} - files: | - bin/cattery* + - name: create-release + if: github.event_name == 'workflow_dispatch' + uses: softprops/action-gh-release@v2 + with: + tag_name: ${{ github.event.inputs.tag_name }} + name: v${{ github.event.inputs.tag_name }} + draft: true + token: ${{ github.token }} + target_commitish: ${{ github.sha }} + files: | + bin/cattery* docker-build: - needs: [tests] if: github.event_name == 'workflow_dispatch' || contains(github.event.pull_request.labels.*.name, 'image-push') runs-on: cattery-gce environment: ${{ github.event_name == 'workflow_dispatch' && 'main' || null }} @@ -95,4 +76,4 @@ jobs: ${{ env.REGISTRY_PATH }}:latest push: true build-args: | - CATTERY_VERSION=${{ env.VERSION }} + CATTERY_VERSION=${{ env.VERSION }} \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..9079115 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,28 @@ +name: Test + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review, labeled] + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true + +jobs: + + tests: + runs-on: cattery-gce + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Start MongoDB + uses: supercharge/mongodb-github-action@1.12.0 + with: + mongodb-replica-set: rs0 + mongodb-port: 27017 + + - name: run tests + run: go test -C src ./... From b6f94a0e656a313846baaef48c4488e336285b7d Mon Sep 17 00:00:00 2001 From: Evgeny Snitko Date: Wed, 27 Aug 2025 18:47:42 +0400 Subject: [PATCH 2/2] release condition --- .github/workflows/publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 823f09a..abd9634 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -14,7 +14,7 @@ on: jobs: - build: + release: permissions: contents: write runs-on: cattery-gce @@ -39,7 +39,7 @@ jobs: - run: ls -la bin/ - name: create-release - if: github.event_name == 'workflow_dispatch' + if: github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name != '' uses: softprops/action-gh-release@v2 with: tag_name: ${{ github.event.inputs.tag_name }}