-
Notifications
You must be signed in to change notification settings - Fork 17
134 lines (129 loc) · 5.25 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
---
name: Main
on: [push, pull_request]
jobs:
go-tests:
runs-on: self-hosted
container:
image: golang:1.18.6
options: --user 1000
if: github.repository == 'vocdoni/vocdoni-node'
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: gofmt
# Run gofmt first, as it's quick and issues are common.
run: diff -u <(echo -n) <(gofmt -s -d $(git ls-files '*.go'))
- name: go test
run: |
# check that log lines contains no invalid chars (evidence of format mismatch)
export LOG_PANIC_ON_INVALIDCHARS=true
# we run vet in another step
go test -vet=off -timeout=1m -coverprofile=covprofile ./...
# -race can easily make the crypto stuff 10x slower
go test -vet=off -timeout=15m -race ./...
- name: go vet
run: go vet ./...
- name: Download staticcheck
run: |
curl -L https://github.com/dominikh/go-tools/releases/download/2022.1.2/staticcheck_linux_amd64.tar.gz | tar -xzf -
- name: staticcheck
run: |
./staticcheck/staticcheck ./... 2> staticcheck/stderr
- name: check staticcheck stderr
run: |
if cat staticcheck/stderr | grep "matched no packages" ; then
echo "staticcheck step did nothing, due to https://github.com/vocdoni/vocdoni-node/issues/444"
echo "Please re-run job."
# seize the opportunity to fix the underlying problem: a permissions error in ~/.cache
epoch=$(date +%s)
# if any file is reported by find, grep returns true and the mv is done
if [ -d ~/.cache ] && find ~/.cache -not -user `id --user` -print0 | grep -qz . ; then
echo "~/.cache had broken permissions, moving it away... (cache will be rebuilt with usage)"
mv -v ~/.cache ~/.cache-broken-by-root-$epoch
fi
exit 2
fi
- name: Go build for Mac
run: |
# Some of our devs are on Mac. Ensure it builds.
# It's surprisingly hard with some deps like bazil.org/fuse.
GOOS=darwin go build ./...
compose-test:
runs-on: self-hosted
if: github.repository == 'vocdoni/vocdoni-node'
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Run compose script
run: |
export COMPOSE_DOCKER_CLI_BUILD=1 DOCKER_BUILDKIT=1
export DOCKER_CLI_EXPERIMENTAL=enabled
export COMPOSE_PROJECT_NAME=${RANDOM}${RANDOM}_testsuite
export TESTSUITE_BUILD_TAG=${CI_COMMIT_SHA::10}
export COMPOSE_HOST_PATH=${PWD}/dockerfiles/testsuite
export COMPOSE_DVOTE_PORT_MAPPING="9090" # Will use a random available port mapping
export LOG_PANIC_ON_INVALIDCHARS=true
cd dockerfiles/testsuite
docker-compose build
./start_test.sh
docker-release:
runs-on: self-hosted
needs: [go-tests, compose-test]
if: github.ref == 'refs/heads/master' || github.ref == 'refs/heads/stage' || startsWith(github.ref, 'refs/heads/release') || github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/ethless'
steps:
- name: Check out the repo
uses: actions/checkout@v3
- uses: docker/setup-buildx-action@v1
# - name: Set up QEMU
# id: qemu
# uses: docker/setup-qemu-action@v1
# with:
# image: tonistiigi/binfmt:latest
# platforms: all
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Login to GitHub Packages Docker Registry
uses: docker/login-action@v1
with:
registry: docker.pkg.github.com
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Get short branch name
id: var
shell: bash
# Grab the short branch name, convert slashes to dashes
run: |
echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/} | tr '/' '-' )"
- name: Push to Docker Hub, Packages and ghcr.io
uses: docker/build-push-action@v2
with:
context: .
# platforms: linux/amd64,linux/arm64
push: true
tags: |
vocdoni/go-dvote:latest, vocdoni/go-dvote:${{ steps.var.outputs.branch }},
ghcr.io/vocdoni/go-dvote:latest,ghcr.io/vocdoni/go-dvote:${{ steps.var.outputs.branch }}
- name: Push to Docker Hub, Packages and ghcr.io (race enabled)
uses: docker/build-push-action@v2
if: github.ref == 'refs/heads/dev' || github.ref == 'refs/heads/master'
with:
context: .
push: true
build-args: |
BUILDARGS=-race
tags: |
vocdoni/go-dvote:latest-race, vocdoni/go-dvote:${{ steps.var.outputs.branch }}-race,
ghcr.io/vocdoni/go-dvote:latest-race,ghcr.io/vocdoni/go-dvote:${{ steps.var.outputs.branch }}-race