Skip to content

Commit 66c6a43

Browse files
committed
Add GitHub Actions workflow for release automation and update go-coverage-report version handling
1 parent 457275a commit 66c6a43

File tree

5 files changed

+195
-23
lines changed

5 files changed

+195
-23
lines changed

.github/workflows/release.yml

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
# run only against tags
6+
tags:
7+
- "*"
8+
9+
permissions:
10+
contents: write
11+
id-token: write
12+
attestations: write
13+
14+
jobs:
15+
release:
16+
runs-on: ubuntu-latest
17+
name: Release
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
21+
with:
22+
fetch-depth: 0
23+
- name: Set up Go
24+
uses: actions/setup-go@f111f3307d8850f501ac008e886eec1fd1932a34 # v5.3.0
25+
with:
26+
go-version: stable
27+
# More assembly might be required: Docker logins, GPG, etc.
28+
# It all depends on your needs.
29+
- name: Run GoReleaser
30+
uses: goreleaser/goreleaser-action@90a3faa9d0182683851fbfa97ca1a2cb983bfca3 # v6.2.1
31+
with:
32+
# either 'goreleaser' (default) or 'goreleaser-pro'
33+
distribution: goreleaser
34+
# 'latest', 'nightly', or a semver
35+
version: "~> v2"
36+
args: release --clean
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
39+

.goreleaser.yaml

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
1-
version: 1
1+
version: 2
22

33
before:
44
hooks:
5-
- go mod tidy
5+
- go mod tidy
66

77
builds:
8-
- env:
9-
- CGO_ENABLED=0
10-
goos:
11-
- linux
12-
- windows
13-
- darwin
14-
main: ./cmd/go-coverage-report
8+
- env:
9+
- CGO_ENABLED=0
10+
goos:
11+
- linux
12+
- windows
13+
- darwin
14+
main: ./cmd/go-coverage-report
1515

1616
archives:
17-
- format: tar.gz
18-
name_template: '{{ .ProjectName }}-v{{ .Version }}-{{ title .Os | tolower }}-{{- .Arch }}'
19-
format_overrides:
20-
- goos: windows
21-
format: zip
17+
- format: tar.gz
18+
name_template: '{{ .ProjectName }}-v{{ .Version }}-{{ title .Os | tolower }}-{{- .Arch }}'
19+
format_overrides:
20+
- goos: windows
21+
format: zip
2222

2323
checksum:
2424
name_template: 'checksums.txt'
@@ -27,5 +27,5 @@ changelog:
2727
sort: asc
2828
filters:
2929
exclude:
30-
- "^docs:"
31-
- "^test:"
30+
- "^docs:"
31+
- "^test:"

action.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ inputs:
99
version:
1010
description: 'The exact version tag of the go-coverage-report tool to use.'
1111
required: true
12-
default: "main"
12+
default: "v3"
1313

1414
sha256sum:
1515
description: 'Optional SHA256 checksum of the tarball when downloading the go-coverage-report binary.'
@@ -65,13 +65,12 @@ runs:
6565

6666
steps:
6767
- name: Download go-coverage-report
68-
uses: actions/setup-go@v5
69-
with:
70-
go-version: '1.24'
71-
- name: Install report tool
7268
shell: bash
73-
run: |
74-
go clean -modcache && go install github.com/teamniteo/go-coverage-report/cmd/go-coverage-report@latest
69+
id: download
70+
run: $GITHUB_ACTION_PATH/scripts/cli-tool.sh "${{ inputs.version }}" "${{ inputs.sha256sum }}"
71+
env:
72+
RUNNER_OS: ${{ runner.os }}
73+
RUNNER_ARCH: ${{ runner.arch }}
7574
- name: Determine changed files
7675
id: changed-files
7776
uses: tj-actions/changed-files@aa08304bd477b800d468db44fe10f6c61f7f7b11 # v42.1.0

scripts/cli-tool.sh

+134
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
type curl >/dev/null 2>&1 || {
6+
echo >&2 'ERROR: Script requires "curl"'
7+
exit 1
8+
}
9+
type sha256sum >/dev/null 2>&1 || {
10+
echo >&2 'ERROR: Script requires "sha256sum"'
11+
exit 1
12+
}
13+
type tar >/dev/null 2>&1 || {
14+
echo >&2 'ERROR: Script requires "tar"'
15+
exit 1
16+
}
17+
18+
USAGE="$0: Download the go-coverage-report binary from GitHub.
19+
20+
This script is meant to be used as part of a GitHub action and makes use of Workflow commands as
21+
described in https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions
22+
23+
Usage:
24+
$0 version [sha256sum]
25+
26+
Example:
27+
$0 Linux X64
28+
29+
You can use the following environment variables to configure the script:
30+
- RUNNER_OS: The operating system of the runner (default: Linux)
31+
- RUNNER_ARCH: The architecture of the runner (default: X64)
32+
- DRY_RUN: Do not actually move the binary to /usr/bin (default: false)
33+
"
34+
35+
if [[ $# == 0 ]]; then
36+
echo -e "Error: script requires at least one argument\n"
37+
echo "$USAGE"
38+
exit 1
39+
fi
40+
41+
VERSION=$1
42+
RUNNER_OS=${RUNNER_OS:-Linux}
43+
RUNNER_ARCH=${RUNNER_ARCH:-X64}
44+
45+
if [[ -z ${VERSION+x} ]]; then
46+
echo "Missing version argument"
47+
exit 1
48+
fi
49+
50+
if [[ $# == 2 ]]; then
51+
SHA256SUM=$2
52+
fi
53+
54+
sudo_or_dry_run="sudo"
55+
if [[ "$DRY_RUN" == "true" ]]; then
56+
sudo_or_dry_run='echo [DRY-RUN]: sudo'
57+
fi
58+
59+
start_group() {
60+
echo "::group::$*"
61+
{
62+
set -x
63+
return
64+
} 2>/dev/null
65+
}
66+
67+
end_group() {
68+
{
69+
set +x
70+
return
71+
} 2>/dev/null
72+
echo "::endgroup::"
73+
}
74+
75+
if [[ $VERSION == "local" ]]; then
76+
start_group "Installing go-coverage-report from local source"
77+
go install -v ./cmd/go-coverage-report
78+
end_group
79+
exit 0
80+
fi
81+
82+
if [[ ${#VERSION} == 40 ]]; then
83+
start_group "Installing go-coverage-report from remote source"
84+
go install -v "github.com/teamniteo/go-coverage-report@$VERSION"
85+
end_group
86+
exit 0
87+
fi
88+
89+
start_group "Determining runner architecture"
90+
if [ "$RUNNER_ARCH" = "ARM64" ]; then
91+
ARCH="arm64"
92+
elif [ "$RUNNER_ARCH" = "ARM" ]; then
93+
ARCH="arm"
94+
elif [ "$RUNNER_ARCH" = "X86" ]; then
95+
ARCH="386"
96+
elif [ "$RUNNER_ARCH" = "X64" ]; then
97+
ARCH="amd64"
98+
else
99+
ARCH="amd64"
100+
fi
101+
end_group
102+
103+
start_group "Downloading tar archive from GitHub"
104+
mkdir -p .github/outputs
105+
OS=$(echo "$RUNNER_OS" | tr '[:upper:]' '[:lower:]')
106+
FILENAME="go-coverage-report-${VERSION}-${OS}-${ARCH}.tar.gz"
107+
URL="https://github.com/teamniteo/go-coverage-report/releases/download/${VERSION}/${FILENAME}"
108+
curl --fail --location "$URL" --output ".github/outputs/$FILENAME"
109+
end_group
110+
111+
if ! [[ "$SHA256SUM" ]]; then
112+
start_group "Checking checksum using checksums.txt file from GitHub release"
113+
URL="https://github.com/teamniteo/go-coverage-report/releases/download/${VERSION}/checksums.txt"
114+
cd .github/outputs
115+
curl -fsSL "$URL" | sha256sum --check --ignore-missing
116+
cd -
117+
end_group
118+
else
119+
start_group "Checking checksum using provided SHA256 hash"
120+
echo "Actual sha256:"
121+
sha256sum ".github/outputs/$FILENAME"
122+
echo "Checking checksum"
123+
echo "$SHA256SUM .github/outputs/$FILENAME" | sha256sum -c
124+
end_group
125+
fi
126+
127+
start_group "Decompressing tar archive"
128+
tar -xzf ".github/outputs/$FILENAME" -C .github/outputs/ go-coverage-report
129+
rm ".github/outputs/$FILENAME"
130+
end_group
131+
132+
start_group "Move binary to /usr/bin"
133+
$sudo_or_dry_run mv .github/outputs/go-coverage-report /usr/bin
134+
end_group

scripts/github-action.sh

100644100755
File mode changed.

0 commit comments

Comments
 (0)