Преглед изворни кода

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

Speed up Github actions
tags/v2.2.0^2^2
Sergei Arkhipov пре 1 месец
родитељ
комит
a051518def
No account linked to committer's email address
3 измењених фајлова са 46 додато и 19 уклоњено
  1. 33
    11
      .github/workflows/ci.yaml
  2. 2
    2
      .mise.toml
  3. 11
    6
      Dockerfile

+ 33
- 11
.github/workflows/ci.yaml Прегледај датотеку

48
       - uses: jdx/mise-action@v3
48
       - uses: jdx/mise-action@v3
49
         name: Install mise
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
       - name: Run tests
61
       - name: Run tests
52
         run: mise tasks run covtest
62
         run: mise tasks run covtest
53
 
63
 
69
       - uses: jdx/mise-action@v3
79
       - uses: jdx/mise-action@v3
70
         name: Install mise
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
       - name: Run fuzzing
92
       - name: Run fuzzing
73
         run: mise tasks run 'test:fuzz:*'
93
         run: mise tasks run 'test:fuzz:*'
74
 
94
 
86
       - uses: jdx/mise-action@v3
106
       - uses: jdx/mise-action@v3
87
         name: Install mise
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
       - name: Run linter
119
       - name: Run linter
90
         run: mise tasks run lint
120
         run: mise tasks run lint
91
 
121
 
123
       - name: Setup BuildX
153
       - name: Setup BuildX
124
         uses: docker/setup-buildx-action@v3
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
       - name: Login to DockerHub
156
       - name: Login to DockerHub
135
         if: github.event_name != 'pull_request'
157
         if: github.event_name != 'pull_request'
136
         uses: docker/login-action@v3
158
         uses: docker/login-action@v3
147
           password: ${{ secrets.GITHUB_TOKEN }}
169
           password: ${{ secrets.GITHUB_TOKEN }}
148
 
170
 
149
       - name: Build and push
171
       - name: Build and push
150
-        uses: docker/build-push-action@v2
172
+        uses: docker/build-push-action@v6
151
         with:
173
         with:
152
           pull: true
174
           pull: true
153
           context: .
175
           context: .
155
           push: ${{ github.event_name != 'pull_request' }}
177
           push: ${{ github.event_name != 'pull_request' }}
156
           tags: ${{ steps.meta.outputs.tags }}
178
           tags: ${{ steps.meta.outputs.tags }}
157
           labels: ${{ steps.meta.outputs.labels }}
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 Прегледај датотеку

33
 
33
 
34
 [tasks.test]
34
 [tasks.test]
35
 description = "Run tests"
35
 description = "Run tests"
36
-run = "go test -v ./..."
36
+run = "go test -v -race ./..."
37
 
37
 
38
 [tasks.covtest]
38
 [tasks.covtest]
39
 description = "Run tests with code coverage"
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
 [tasks.test-all]
42
 [tasks.test-all]
43
 description = "Run all tests"
43
 description = "Run all tests"

+ 11
- 6
Dockerfile Прегледај датотеку

5
 
5
 
6
 ENV CGO_ENABLED=0
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
 COPY . /app
20
 COPY . /app
15
-WORKDIR /app
16
 
21
 
17
 RUN set -x \
22
 RUN set -x \
18
   && version="$(git describe --exact-match HEAD 2>/dev/null || git describe --tags --always)" \
23
   && version="$(git describe --exact-match HEAD 2>/dev/null || git describe --tags --always)" \

Loading…
Откажи
Сачувај