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..abd9634 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] + release: 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' && github.event.inputs.tag_name != '' + 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 ./...