Files
Yun Pan da3b7b6c03 ci(lifecycle): keep lint incremental on push (#7130)
* ci: keep lifecycle lint incremental on push

* ci(lifecycle): document incremental lint base
2026-07-28 14:36:56 +08:00

120 lines
3.6 KiB
YAML
Executable File

name: CI
env:
GO_VERSION: "1.25"
on:
workflow_call:
workflow_dispatch:
inputs:
push_mage:
description: "Push images"
required: false
type: boolean
push:
branches: ["main"]
paths-ignore:
- "docs/**"
- "**/*.md"
- "**/*.yaml"
- "CHANGELOG/**"
- "controllers/**"
- "service/**"
- "webhooks/**"
- "frontend/**"
pull_request:
branches: ["*"]
paths-ignore:
- "docs/**"
- "CHANGELOG/**"
- "**/*.md"
- "**/*.yaml"
- "CHANGELOG/**"
- "controllers/**"
- "service/**"
- "webhooks/**"
- "frontend/**"
# Avoid using ${{ github.workflow }} - when called via workflow_call, it inherits the caller's name causing conflicts
concurrency:
group: ci-${{ github.head_ref || github.run_id }}
cancel-in-progress: true
jobs:
resolve-modules:
runs-on: ubuntu-24.04
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
has_modules: ${{ steps.set-matrix.outputs.has_modules }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve Modules
id: set-matrix
run: |
# Use a diff base when available so lifecycle pushes stay incremental.
BASE_REF=""
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
BASE_REF="${{ github.event.pull_request.base.sha }}"
HEAD_REF="${{ github.sha }}"
elif [[ "${{ github.event_name }}" == "push" && "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]]; then
BASE_REF="${{ github.event.before }}"
HEAD_REF="${{ github.sha }}"
else
HEAD_REF="${{ github.sha }}"
fi
if [[ -n "${BASE_REF}" ]]; then
bash ./scripts/resolve-modules.sh ./lifecycle --changed "${BASE_REF}" "${HEAD_REF}"
else
bash ./scripts/resolve-modules.sh ./lifecycle
fi
golangci-lint:
if: ${{ needs.resolve-modules.outputs.has_modules == 'true' }}
needs: [resolve-modules]
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.resolve-modules.outputs.matrix) }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Golang with cache
uses: magnetikonline/action-golang-cache@v5
with:
go-version: ${{ env.GO_VERSION }}
- name: Install Dependencies
run: sudo apt update && sudo apt install -y libgpgme-dev libbtrfs-dev libdevmapper-dev
- name: Resolve Linter Args
id: lint-args
run: |
args="--color=always --config=${{ github.workspace }}/.golangci.yml"
# Match module resolution so historical lifecycle lint debt does not fail unrelated pushes.
new_from_rev=""
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
new_from_rev="${{ github.event.pull_request.base.sha }}"
elif [[ "${{ github.event_name }}" == "push" && "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]]; then
new_from_rev="${{ github.event.before }}"
fi
if [[ -n "${new_from_rev}" ]]; then
args="${args} --new-from-rev=${new_from_rev}"
fi
echo "args=${args}" >> "$GITHUB_OUTPUT"
- name: Run Linter
uses: golangci/golangci-lint-action@v8
with:
version: v2.12.2
working-directory: ${{ matrix.workdir }}
# args between =, not space
args: ${{ steps.lint-args.outputs.args }}