Przeglądaj źródła

Merge pull request #356 from 9seconds/gh-cache

Speed up Github actions
tags/v2.2.0^2^2
Sergei Arkhipov 1 miesiąc temu
rodzic
commit
a051518def
No account linked to committer's email address
3 zmienionych plików z 46 dodań i 19 usunięć
  1. 33
    11
      .github/workflows/ci.yaml
  2. 2
    2
      .mise.toml
  3. 11
    6
      Dockerfile

+ 33
- 11
.github/workflows/ci.yaml Wyświetl plik

@@ -48,6 +48,16 @@ jobs:
48 48
       - uses: jdx/mise-action@v3
49 49
         name: Install mise
50 50
 
51
+      - name: Cache Go modules and build
52
+        uses: actions/cache@v5
53
+        with:
54
+          path: |
55
+            ~/go/pkg/mod
56
+            ~/.cache/go-build
57
+          key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
58
+          restore-keys: |
59
+            ${{ runner.os }}-go-
60
+
51 61
       - name: Run tests
52 62
         run: mise tasks run covtest
53 63
 
@@ -69,6 +79,16 @@ jobs:
69 79
       - uses: jdx/mise-action@v3
70 80
         name: Install mise
71 81
 
82
+      - name: Cache Go modules and build
83
+        uses: actions/cache@v5
84
+        with:
85
+          path: |
86
+            ~/go/pkg/mod
87
+            ~/.cache/go-build
88
+          key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
89
+          restore-keys: |
90
+            ${{ runner.os }}-go-
91
+
72 92
       - name: Run fuzzing
73 93
         run: mise tasks run 'test:fuzz:*'
74 94
 
@@ -86,6 +106,16 @@ jobs:
86 106
       - uses: jdx/mise-action@v3
87 107
         name: Install mise
88 108
 
109
+      - name: Cache Go modules and build
110
+        uses: actions/cache@v5
111
+        with:
112
+          path: |
113
+            ~/go/pkg/mod
114
+            ~/.cache/go-build
115
+          key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }}
116
+          restore-keys: |
117
+            ${{ runner.os }}-go-
118
+
89 119
       - name: Run linter
90 120
         run: mise tasks run lint
91 121
 
@@ -123,14 +153,6 @@ jobs:
123 153
       - name: Setup BuildX
124 154
         uses: docker/setup-buildx-action@v3
125 155
 
126
-      - name: Setup cache
127
-        uses: actions/cache@v5
128
-        with:
129
-          path: /tmp/buildx-cache
130
-          key: ${{ runner.os }}-buildx-${{ github.sha }}
131
-          restore-keys: |
132
-            ${{ runner.os }}-buildx-
133
-
134 156
       - name: Login to DockerHub
135 157
         if: github.event_name != 'pull_request'
136 158
         uses: docker/login-action@v3
@@ -147,7 +169,7 @@ jobs:
147 169
           password: ${{ secrets.GITHUB_TOKEN }}
148 170
 
149 171
       - name: Build and push
150
-        uses: docker/build-push-action@v2
172
+        uses: docker/build-push-action@v6
151 173
         with:
152 174
           pull: true
153 175
           context: .
@@ -155,5 +177,5 @@ jobs:
155 177
           push: ${{ github.event_name != 'pull_request' }}
156 178
           tags: ${{ steps.meta.outputs.tags }}
157 179
           labels: ${{ steps.meta.outputs.labels }}
158
-          cache-from: type=local,src=/tmp/buildx-cache
159
-          cache-to: type=local,dest=/tmp/buildx-cache
180
+          cache-from: type=gha
181
+          cache-to: type=gha,mode=max

+ 2
- 2
.mise.toml Wyświetl plik

@@ -33,11 +33,11 @@ run = "govulncheck ./..."
33 33
 
34 34
 [tasks.test]
35 35
 description = "Run tests"
36
-run = "go test -v ./..."
36
+run = "go test -v -race ./..."
37 37
 
38 38
 [tasks.covtest]
39 39
 description = "Run tests with code coverage"
40
-run = "go test -coverprofile=coverage.txt -covermode=atomic -parallel 2 -race -v ./..."
40
+run = "go test -coverprofile=coverage.txt -covermode=atomic -count=2 -race -v ./..."
41 41
 
42 42
 [tasks.test-all]
43 43
 description = "Run all tests"

+ 11
- 6
Dockerfile Wyświetl plik

@@ -5,14 +5,19 @@ FROM golang:1.26-alpine AS build
5 5
 
6 6
 ENV CGO_ENABLED=0
7 7
 
8
-RUN set -x \
9
-  && apk --no-cache --update add \
10
-    bash \
11
-    ca-certificates \
12
-    git
8
+RUN --mount=type=cache,target=/var/cache/apk \
9
+    set -x \
10
+    && apk --update add \
11
+      bash \
12
+      ca-certificates \
13
+      git
14
+
15
+COPY go.mod go.sum /app/
16
+WORKDIR /app
17
+
18
+RUN go mod download
13 19
 
14 20
 COPY . /app
15
-WORKDIR /app
16 21
 
17 22
 RUN set -x \
18 23
   && version="$(git describe --exact-match HEAD 2>/dev/null || git describe --tags --always)" \

Ładowanie…
Anuluj
Zapisz