-
Notifications
You must be signed in to change notification settings - Fork 2
83 lines (81 loc) · 2.99 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: Main
on: [push, pull_request]
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: 1.20.x
cache: true
- name: Run golangci-lint
# run: |
# curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.30.0
# $(go env GOPATH)/bin/golangci-lint run --timeout=5m -c .golangci.yml
uses: golangci/golangci-lint-action@v3
### golangci-lint will take much time if loading multiple linters in .golangci.yml
with:
version: latest
args: --timeout 5m --verbose
skip-cache: false
skip-pkg-cache: false
skip-build-cache: false
only-new-issues: true
test:
# matrix strategy from: https://github.com/mvdan/github-actions-golang/blob/master/.github/workflows/test.yml
strategy:
matrix:
go-version: [1.20.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Install Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
cache: true
- name: Run go test
env:
WEB3_URI: ${{ secrets.WEB3_URI }}
run: go test -timeout=10m -race ./...
docker-release:
runs-on: ubuntu-latest
needs: [test, lint]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/stage' || startsWith(github.ref, 'refs/heads/release')
steps:
- name: Check out the repo
uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Get short commit sha and branch name
id: vars
run: |
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
echo "branch_name=$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-' )" >> $GITHUB_OUTPUT
- name: Push to Docker Hub and ghcr.io
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile
platforms: linux/amd64
push: true
tags: |
vocdoni/${{ github.event.repository.name }}:latest, vocdoni/${{ github.event.repository.name }}:${{ steps.vars.outputs.branch_name }},
ghcr.io/vocdoni/${{ github.event.repository.name }}:latest, ghcr.io/vocdoni/${{ github.event.repository.name }}:${{ steps.vars.outputs.branch_name }}
cache-from: type=gha
cache-to: type=gha,mode=max