-
Notifications
You must be signed in to change notification settings - Fork 13
102 lines (97 loc) · 3.42 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
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches:
- main
release:
types: [published]
pull_request:
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Remove all permissions by default
permissions: {}
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build-and-test:
runs-on: ubuntu-20.04
name: Build and Test
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/setup-go@41dfa10bad2bb2ae585af6ee5bb4d7d973ad74ed
with:
go-version: '^1.22.4' # The Go version to download (if necessary) and use.
- name: Install Build Dependencies
run: make get-build-deps
- name: Download required modules
run: make download
- name: Vet
run: make vet
- name: Lint
run: make lint
- name: Test
run: make test
- name: Cover
run: make cover
- name: Race Test
run: make race-test
- name: Build
run: |
set -ex
for dist in amd64 arm64; do
target=out/gonit-linux-$dist
rm -rf "$target"
make build/$dist TOOL_PATH="$target"
file $target
tar -C "$(dirname "$target")" -czf "$target.tar.gz" "$(basename "$target")"
done
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882
with:
name: built-binaries
path: |
out/*.tar.gz
release:
needs: [ 'build-and-test' ]
if: startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
- uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16
with:
path: ./artifacts
- name: Set tag name
id: vars
run: echo ::set-output name=tag::${GITHUB_REF#refs/*/}
- name: Release
run: |
set -e
create_digest_file() {
local digest_file=${1:?You must provide the digest file path}
shift
for file in "$@"; do
(
cd "$(dirname "$file")"
sha256sum "$(basename "$file")"
) >> "$digest_file"
done
}
assets=( ./artifacts/built-binaries/*.gz )
tag_name="${{ steps.vars.outputs.tag }}"
checksums_file="${tag_name}_checksums.txt"
create_digest_file "$checksums_file" "${assets[@]}"
assets+=( "$checksums_file" )
if gh release view "$tag_name" >/dev/null 2>/dev/null; then
echo "Release $tag_name already exists. Updating"
gh release upload "$tag_name" "${assets[@]}"
else
echo "Creating new release $tag_name"
# Format checksums for the release text
printf '```\n%s\n```' "$(<"$checksums_file")" > release.txt
gh release create -t "$tag_name" "$tag_name" -F release.txt "${assets[@]}"
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}