Explorar el Código

Merge pull request #175 from 9seconds/ci

Integrate with Github actions
undefined
Sergey Arkhipov hace 5 años
padre
commit
ce7769472d
No account linked to committer's email address
Se han modificado 4 ficheros con 142 adiciones y 32 borrados
  1. 131
    0
      .github/workflows/ci.yaml
  2. 0
    21
      .travis.yml
  3. 5
    7
      Dockerfile
  4. 6
    4
      Makefile

+ 131
- 0
.github/workflows/ci.yaml Ver fichero

@@ -0,0 +1,131 @@
1
+---
2
+
3
+name: CI
4
+
5
+on:
6
+  push:
7
+    tags:
8
+      - v*
9
+    branches:
10
+      - master
11
+  release:
12
+    types:
13
+      - published
14
+      - released
15
+  pull_request:
16
+    types:
17
+      - opened
18
+      - edited
19
+      - reopened
20
+      - synchronize
21
+      - ready_for_review
22
+
23
+jobs:
24
+  test:
25
+    name: Test
26
+    runs-on: ubuntu-latest
27
+    timeout-minutes: 5
28
+    strategy:
29
+      matrix:
30
+        go_version:
31
+          - ~1.14
32
+          - ~1.15
33
+          - ^1.16
34
+    steps:
35
+      - name: Checkout
36
+        uses: actions/checkout@v2
37
+        with:
38
+          submodules: recursive
39
+
40
+      - name: Setup Go
41
+        uses: actions/setup-go@v2
42
+        with:
43
+          go-version: ${{ matrix.go_version }}
44
+
45
+      - name: Cache dependencies
46
+        uses: actions/cache@v2
47
+        with:
48
+          path: ~/go/pkg/mod
49
+          key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
50
+          restore-keys: ${{ runner.os }}-go-
51
+
52
+      - name: Run tests
53
+        run: go test -coverprofile=./coverage.txt -covermode=atomic -v ./...
54
+
55
+      - name: Collect coverage
56
+        uses: codecov/codecov-action@v1
57
+        with:
58
+          file: ./coverage.txt
59
+
60
+  lint:
61
+    name: Lint
62
+    runs-on: ubuntu-latest
63
+    timeout-minutes: 5
64
+    steps:
65
+      - name: Checkout
66
+        uses: actions/checkout@v2
67
+        with:
68
+          submodules: recursive
69
+
70
+      - name: Run linter
71
+        uses: golangci/golangci-lint-action@v2
72
+        with:
73
+          version: v1.37.1
74
+
75
+  docker:
76
+    name: Docker
77
+    runs-on: ubuntu-latest
78
+    timeout-minutes: 15
79
+    steps:
80
+      - name: Checkout
81
+        uses: actions/checkout@v2
82
+        with:
83
+          submodules: recursive
84
+
85
+      - name: Get Docker meta
86
+        id: docker_meta
87
+        uses: crazy-max/ghaction-docker-meta@v1
88
+        with:
89
+          images: nineseconds/mtg,ghcr.io/9seconds/mtg
90
+          tag-semver: "{{version}},{{major}},{{major}}.{{minor}}"
91
+
92
+      - name: Setup QEMU
93
+        uses: docker/setup-qemu-action@v1
94
+
95
+      - name: Setup BuildX
96
+        uses: docker/setup-buildx-action@v1
97
+
98
+      - name: Setup cache
99
+        uses: actions/cache@v2
100
+        with:
101
+          path: /tmp/buildx-cache
102
+          key: ${{ runner.os }}-buildx-${{ github.sha }}
103
+          restore-keys: |
104
+            ${{ runner.os }}-buildx-
105
+
106
+      - name: Login to DockerHub
107
+        if: github.event_name != 'pull_request'
108
+        uses: docker/login-action@v1
109
+        with:
110
+          username: ${{ secrets.DOCKERHUB_USERNAME }}
111
+          password: ${{ secrets.DOCKERHUB_PASSWORD }}
112
+
113
+      - name: Login to GHCR.io
114
+        if: github.event_name != 'pull_request'
115
+        uses: docker/login-action@v1
116
+        with:
117
+          registry: ghcr.io
118
+          username: ${{ github.repository_owner }}
119
+          password: ${{ secrets.GH_PAT }}
120
+
121
+      - name: Build and push
122
+        uses: docker/build-push-action@v2
123
+        with:
124
+          pull: true
125
+          context: .
126
+          platforms: linux/amd64,linux/arm64,linux/386
127
+          push: ${{ github.event_name != 'pull_request' }}
128
+          tags: ${{ steps.docker_meta.outputs.tags }}
129
+          labels: ${{ steps.docker_meta.outputs.labels }}
130
+          cache-from: type=local,src=/tmp/buildx-cache
131
+          cache-to: type=local,dest=/tmp/buildx-cache

+ 0
- 21
.travis.yml Ver fichero

@@ -1,21 +0,0 @@
1
----
2
-
3
-language: go
4
-sudo: false
5
-dist: trusty
6
-
7
-go:
8
-  - 1.15.x
9
-  - 1.14.x
10
-  - 1.13.x
11
-  - master
12
-
13
-before_script: make prepare
14
-
15
-script:
16
-  - make all
17
-  - make lint
18
-
19
-matrix:
20
-  allow_failures:
21
-    - go: master

+ 5
- 7
Dockerfile Ver fichero

@@ -9,15 +9,13 @@ RUN set -x \
9 9
     ca-certificates \
10 10
     curl \
11 11
     git \
12
-    make \
13
-    upx
12
+    make
14 13
 
15
-COPY . /go/src/github.com/9seconds/mtg/
16
-WORKDIR /go/src/github.com/9seconds/mtg
14
+COPY . /app
15
+WORKDIR /app
17 16
 
18 17
 RUN set -x \
19
-  && make -j 4 static \
20
-  && upx --ultra-brute -qq ./mtg
18
+  && make -j 4 static
21 19
 
22 20
 
23 21
 ###############################################################################
@@ -31,4 +29,4 @@ ENV MTG_BIND=0.0.0.0:3128 \
31 29
 EXPOSE 3128 3129
32 30
 
33 31
 COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
34
-COPY --from=build /go/src/github.com/9seconds/mtg/mtg /mtg
32
+COPY --from=build /app/mtg /mtg

+ 6
- 4
Makefile Ver fichero

@@ -20,12 +20,13 @@ GOTOOL := env "GOBIN=$(GOBIN)" "PATH=$(ROOT_DIR)/.bin:$(PATH)"
20 20
 all: build
21 21
 
22 22
 .PHONY: build
23
-build: $(APP_NAME)
24
-
25
-$(APP_NAME):
23
+build:
26 24
 	@go build $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"
27 25
 
28
-static-$(APP_NAME):
26
+$(APP_NAME): build
27
+
28
+.PHONY: static
29
+static:
29 30
 	@env CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo $(COMMON_BUILD_FLAGS) -o "$(APP_NAME)"
30 31
 
31 32
 $(APP_NAME)-%: GOOS=$(shell echo -n "$@" | sed 's?$(APP_NAME)-??' | cut -f1 -d-)
@@ -36,6 +37,7 @@ $(APP_NAME)-%: ccbuilds
36 37
 		$(COMMON_BUILD_FLAGS) \
37 38
 		-o "./ccbuilds/$(APP_NAME)-$(GOOS)-$(GOARCH)"
38 39
 
40
+.PHONY: ccbuilds
39 41
 ccbuilds:
40 42
 	@rm -rf ./ccbuilds && mkdir -p ./ccbuilds
41 43
 

Loading…
Cancelar
Guardar