-
Notifications
You must be signed in to change notification settings - Fork 4
139 lines (130 loc) · 4.42 KB
/
go.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
135
136
137
138
139
name: Go
permissions:
contents: write
on:
push:
tags:
- '*'
branches: [ master,main ]
pull_request:
branches: [ master,main ]
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: latest
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go from go.mod
uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Clean test cache
run: go clean -testcache
- name: Build
run: go build -v ./...
- name: Tests
run: go test -v ./... -race
build-darwin-artifacts:
if: startsWith(github.ref, 'refs/tags/v')
needs: [ golangci,test ]
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: -f release/.goreleaser-darwin.yml release --clean --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Upload
uses: actions/upload-artifact@v3
with:
name: bin-darwin
path: dist/${{ github.event.repository.name }}_*.tar.gz
release-linux:
if: startsWith(github.ref, 'refs/tags/v')
needs: [ build-darwin-artifacts ]
runs-on: ubuntu-latest
steps:
- name: Setup Dockerhub repo based on var
if: vars.DOCKERHUB_REPO != null
run: |
echo "DOCKERHUB_REPO=${{vars.DOCKERHUB_REPO}}" >> $GITHUB_ENV
- name: Default Dockerhub repo to on project name
if: vars.DOCKERHUB_REPO == null
run: |
echo "DOCKERHUB_REPO=$(basename ${GITHUB_REPOSITORY})" >> $GITHUB_ENV
- name: Setup Dockerhub owner based on var
if: vars.DOCKERHUB_OWNER != null
run: |
echo "DOCKERHUB_OWNER=${{vars.DOCKERHUB_OWNER}}" >> $GITHUB_ENV
- name: Default Dockerhub owner to dockerhub username
if: vars.DOCKERHUB_OWNER == null
run: |
echo "DOCKERHUB_OWNER=${{secrets.DOCKERHUB_USERNAME}}" >> $GITHUB_ENV
- uses: actions/checkout@v3
with:
fetch-depth: 0
- run: git fetch --force --tags
- uses: actions/setup-go@v4
with:
go-version-file: go.mod
- name: Make directory for darwin bin
run: |
mkdir -p ./release/artifacts/darwin
- name: Download Darwin binaries
uses: actions/download-artifact@v3
with:
name: bin-darwin
path: ./release/artifacts/darwin
# Uncomment if you need CGO_ENABLED=1
# - name: Install cross-compiler for linux/arm64
# run: sudo apt-get -y install gcc-aarch64-linux-gnu
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Prepare README for dockerhub
run: |
envsubst < ./release/README.DOCKER.md > ./release/artifacts/README.DOCKER.md
- name: Go Release
uses: goreleaser/goreleaser-action@v4
with:
distribution: goreleaser
version: latest
args: -f release/.goreleaser-linux.yml release --clean --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKERHUB_USERNAME: ${{ env.DOCKERHUB_OWNER }}
DOCKERHUB_REPONAME: ${{ env.DOCKERHUB_REPO }}
SOURCE_URL: ${{ github.event.repository.url }}
- name: Docker Hub Description
uses: peter-evans/dockerhub-description@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
short-description: ${{ github.event.repository.description }}
repository: ${{ env.DOCKERHUB_OWNER }}/${{ env.DOCKERHUB_REPO }}
readme-filepath: ./release/artifacts/README.DOCKER.md