diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 7fbe843..a628a39 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -6,40 +6,63 @@ permissions: pull-requests: read jobs: lint: - name: pull-kapacity-golangci-lint + name: Run linting runs-on: ubuntu-latest steps: + - name: Checkout code + uses: actions/checkout@v3 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v39 + with: + files_yaml: | + go: + - '**/*.go' - name: Set up Go + if: steps.changed-files.outputs.go_any_changed == 'true' uses: actions/setup-go@v4 with: go-version: "1.19" cache: false - - name: Checkout code - uses: actions/checkout@v3 - name: Run golangci-lint + if: steps.changed-files.outputs.go_any_changed == 'true' uses: golangci/golangci-lint-action@v3 with: version: latest only-new-issues: true # TODO(zqzten): add verify job test: - name: pull-kapacity-unit-test + name: Run unit tests needs: lint runs-on: ubuntu-latest steps: - - name: Set up Go - uses: actions/setup-go@v4 - with: - go-version: "1.19" - name: Checkout code uses: actions/checkout@v3 with: fetch-depth: 0 + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v39 + with: + files_yaml: | + go: + - '**/*.go' + - go.mod + - go.sum + - Makefile - name: Git config + if: steps.changed-files.outputs.go_any_modified == 'true' run: | git config user.name "github-actions[bot]" git config user.email "41898282+github-actions[bot]@users.noreply.github.com" - name: Rebase code + if: steps.changed-files.outputs.go_any_modified == 'true' run: git rebase origin/main + - name: Set up Go + if: steps.changed-files.outputs.go_any_modified == 'true' + uses: actions/setup-go@v4 + with: + go-version: "1.19" - name: Run unit tests + if: steps.changed-files.outputs.go_any_modified == 'true' run: make unit-test diff --git a/.github/workflows/release-algorithm.yaml b/.github/workflows/release-algorithm.yaml new file mode 100644 index 0000000..72be209 --- /dev/null +++ b/.github/workflows/release-algorithm.yaml @@ -0,0 +1,37 @@ +name: Release +on: + push: + tags: + - 'algorithm-v*' +permissions: + contents: read + packages: write +jobs: + build-and-push-image: + name: Build and push image + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Get tag + run: echo "tag=$(git describe --tags --match 'algorithm-v*' | sed -e 's/^algorithm-//')" >> $GITHUB_ENV + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push image + uses: docker/build-push-action@v4 + with: + context: ./algorithm + file: ./algorithm/horizontal-predictive.Dockerfile + platforms: linux/amd64 + push: true + tags: ghcr.io/${{ github.repository_owner }}/kapacity-algorithm-horizontal-predictive:${{ env.tag }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 75d0101..81f5a70 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -7,8 +7,8 @@ permissions: contents: read packages: write jobs: - image: - name: build-and-push-kapacity-manager-image + build-and-push-image: + name: Build and push image runs-on: ubuntu-latest steps: - name: Checkout code @@ -16,7 +16,7 @@ jobs: with: fetch-depth: 0 - name: Get tag - run: echo "tag=$(git describe --tags)" >> $GITHUB_ENV + run: echo "tag=$(git describe --tags --match 'v*')" >> $GITHUB_ENV - name: Set up QEMU uses: docker/setup-qemu-action@v2 - name: Set up Docker Buildx