Skip to content

Commit a284a4c

Browse files
authored
Prepare for v1 release (#14)
* Update README.md and CHANGELOG.md to point to v1 * Rename $COVERAGE_REPORT_TRIM to $TRIM_PACKAGE * Rename "-root-pkg" flag to "-root" * Fail "Download go-coverage-report" job on non-zero status codes * Move downloading of binary into its own script * Use v0.4.0 version in GitHub CI workflow until v1.0.0 is actually released * Move Go code into "cmd" directory * Tell goreleaser where to find the main package * Support install go-coverage-report from local and remote source * Some more tweaking of input and variable naming
1 parent a29f921 commit a284a4c

File tree

18 files changed

+164
-80
lines changed

18 files changed

+164
-80
lines changed

.github/outputs/go-coverage-report

1.71 MB
Binary file not shown.

.github/workflows/ci.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ on:
77
branches:
88
- 'main'
99

10+
env:
11+
GO_VERSION: "^1.22"
12+
1013
jobs:
1114
unit_tests:
1215
name: "Unit tests"
@@ -18,7 +21,7 @@ jobs:
1821
- name: Setup Go
1922
uses: actions/setup-go@v5
2023
with:
21-
go-version: ^1.22
24+
go-version: ${{ env.GO_VERSION }}
2225

2326
- name: Restore Go modules cache
2427
uses: actions/cache@v4
@@ -52,12 +55,16 @@ jobs:
5255
# Grant permission to add comments to the PR.
5356
pull-requests: write
5457
steps:
55-
# Normally,users of the action don't have to check out the source code.
58+
# Normally,users of the action don't have to check out the source code or setup Go.
5659
# We need this here however because we are using a local action.yml.
5760
- name: Checkout repository
5861
uses: actions/checkout@v4
62+
- name: Setup Go
63+
uses: actions/setup-go@v5
64+
with:
65+
go-version: ${{ env.GO_VERSION }}
5966

6067
- uses: ./
6168
with:
62-
coverage-artifact-name: "code-coverage"
63-
coverage-file-name: "coverage.txt"
69+
version: local
70+
trim: "github.com/fgrosse/go-coverage-report/"

.goreleaser.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ builds:
1111
- linux
1212
- windows
1313
- darwin
14+
main: ./cmd/go-coverage-report
1415

1516
archives:
1617
- format: tar.gz

CHANGELOG.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
> [!NOTE]
8-
> We are currently working towards **v1.0.0**
9-
107
## [Unreleased]
118
_Nothing yet_
129

13-
## [v0.4.0] - 2024-03-16
14-
- Skip coverage report if no file changed (fgrosse/go-coverage-report#11)
15-
- _… changes before we started the CHANGELOG.md …_
10+
## [v1.0.0] - 2024-03-18
11+
- Initial release
1612

17-
[Unreleased]: https://github.com/fgrosse/go-coverage-report/compare/v0.4.0...HEAD
18-
[v0.4.0]: https://github.com/fgrosse/go-coverage-report/compare/v0.3.0...v0.4.0
19-
[v0.3.0]: https://github.com/fgrosse/go-coverage-report/compare/v0.2.0...v0.3.0
20-
[v0.2.0]: https://github.com/fgrosse/go-coverage-report/compare/v0.1.0...v0.2.0
21-
[v0.1.0]: https://github.com/fgrosse/go-coverage-report/releases/tag/v1.0.0
13+
[Unreleased]: https://github.com/fgrosse/go-coverage-report/compare/v1.0.0...HEAD
14+
[v1.0.0]: https://github.com/fgrosse/go-coverage-report/releases/tag/v1.0.0

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
runs-on: ubuntu-latest
9898
needs: unit_tests # Depends on the artifact uploaded by the "unit_tests" job
9999
steps:
100-
- uses: fgrosse/go-coverage-report@v0.4.0 # Consider using a Git revision for maximum security
100+
- uses: fgrosse/go-coverage-report@v1.0.0 # Consider using a Git revision for maximum security
101101
with:
102102
coverage-artifact-name: "code-coverage" # can be omitted if you used this default value
103103
coverage-file-name: "coverage.txt" # can be omitted if you used this default value
@@ -112,10 +112,10 @@ inputs:
112112
version:
113113
description: 'The exact version of the go-coverage-report tool to use.'
114114
required: true
115-
default: "v0.4.0"
115+
default: "v1.0.0"
116116

117117
sha256sum:
118-
description: 'Expected SHA256 checksum of the tarball when downloading the go-coverage-report binary.'
118+
description: 'Optional SHA256 checksum of the tarball when downloading the go-coverage-report binary.'
119119
required: false
120120

121121
coverage-artifact-name:
@@ -128,7 +128,7 @@ inputs:
128128
required: true
129129
default: "coverage.txt"
130130

131-
repo-import-path:
131+
root-package:
132132
description: |
133133
The Go import path of the tested repository to add as a prefix to all paths of the
134134
changed files. This is useful to map the changed files (e.g., ["foo/my_file.go"]

action.yml

Lines changed: 10 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ branding:
77

88
inputs:
99
version:
10-
description: 'The exact version of the go-coverage-report tool to use.'
10+
description: 'The exact version tag of the go-coverage-report tool to use.'
1111
required: true
12-
default: "v0.4.0"
12+
default: "v1.0.0"
1313

1414
sha256sum:
15-
description: 'Expected SHA256 checksum of the tarball when downloading the go-coverage-report binary.'
15+
description: 'Optional SHA256 checksum of the tarball when downloading the go-coverage-report binary.'
1616
required: false
1717

1818
coverage-artifact-name:
@@ -25,7 +25,7 @@ inputs:
2525
required: true
2626
default: "coverage.txt"
2727

28-
repo-import-path:
28+
root-package:
2929
description: |
3030
The Go import path of the tested repository to add as a prefix to all paths of the
3131
changed files. This is useful to map the changed files (e.g., ["foo/my_file.go"]
@@ -46,45 +46,10 @@ runs:
4646
- name: Download go-coverage-report
4747
shell: bash
4848
id: download
49+
run: $GITHUB_ACTION_PATH/scripts/download-cli-tool.sh "${{ inputs.version }}" "${{ inputs.sha256sum }}"
4950
env:
50-
VERSION: ${{ inputs.version }}
51-
SHA256SUM: ${{ inputs.sha256sum }}
52-
run: |
53-
if [ ${{ runner.arch }} = "ARM64" ]; then
54-
ARCH="arm64"
55-
elif [ ${{ runner.arch }} = "ARM" ]; then
56-
ARCH="arm"
57-
elif [ ${{ runner.arch }} = "X86" ]; then
58-
ARCH="386"
59-
elif [ ${{ runner.arch }} = "X64" ]; then
60-
ARCH="amd64"
61-
else
62-
ARCH="amd64"
63-
fi
64-
65-
mkdir -p .github/outputs
66-
67-
RUNNER_OS=$(echo '${{ runner.os }}' | tr '[:upper:]' '[:lower:]')
68-
FILENAME="go-coverage-report-${VERSION}-${RUNNER_OS}-${ARCH}.tar.gz"
69-
URL="https://github.com/fgrosse/go-coverage-report/releases/download/${VERSION}/${FILENAME}"
70-
echo "Downloading \"$FILENAME\" from \"$URL\""
71-
curl --fail --location "$URL" --output .github/outputs/$FILENAME
72-
73-
if ! [[ "$SHA256SUM" ]] ; then
74-
URL="https://github.com/fgrosse/go-coverage-report/releases/download/${VERSION}/checksums.txt"
75-
cd .github/outputs
76-
echo "Downloading checksums from \"$URL\""
77-
curl -fsSL "$URL" | sha256sum --check --ignore-missing
78-
cd -
79-
else
80-
echo "Expected sha256: $SHA256SUM"
81-
echo "Actual sha256: $(sha256sum .github/outputs/go-coverage-report.tar.gz)"
82-
echo "$SHA256SUM .github/outputs/$FILENAME" | sha256sum -c
83-
fi
84-
85-
tar -xzf .github/outputs/$FILENAME -C .github/outputs/ go-coverage-report
86-
rm .github/outputs/$FILENAME
87-
sudo mv .github/outputs/go-coverage-report /usr/bin
51+
RUNNER_OS: ${{ runner.os }}
52+
RUNNER_ARCH: ${{ runner.arch }}
8853

8954
- name: Determine changed files
9055
id: changed-files
@@ -100,7 +65,7 @@ runs:
10065
10166
- name: Code coverage report
10267
shell: bash
103-
run: $GITHUB_ACTION_PATH/github-action.sh ${{ github.repository }} ${{ github.event.pull_request.number }} ${{ github.run_id }}
68+
run: $GITHUB_ACTION_PATH/scripts/github-action.sh "${{ github.repository }}" "${{ github.event.pull_request.number }}" "${{ github.run_id }}"
10469
env:
10570
GH_REPO: ${{ github.repository }}
10671
GH_TOKEN: ${{ github.token }}
@@ -109,5 +74,5 @@ runs:
10974
CHANGED_FILES_PATH: .github/outputs/all_changed_files.json
11075
COVERAGE_ARTIFACT_NAME: ${{ inputs.coverage-artifact-name }}
11176
COVERAGE_FILE_NAME: ${{ inputs.coverage-file-name }}
112-
REPOSITORY_IMPORT_PATH: ${{ inputs.repo-import-path }}
113-
COVERAGE_REPORT_TRIM: ${{ inputs.trim }}
77+
ROOT_PACKAGE: ${{ inputs.root-package }}
78+
TRIM_PACKAGE: ${{ inputs.trim }}
File renamed without changes.

coverage.go renamed to cmd/go-coverage-report/coverage.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// Package coverage contains code to parse and format code coverage profiles.
21
package main
32

43
import (
File renamed without changes.

main.go renamed to cmd/go-coverage-report/main.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Parse the OLD_COVERAGE_FILE and NEW_COVERAGE_FILE and compare the coverage of th
1616
files listed in CHANGED_FILES_FILE. The result is printed to stdout as a simple
1717
Markdown table with emojis indicating the coverage change per package.
1818
19-
You can use the -root-pkg flag to add a prefix to all paths in the list of changed
19+
You can use the -root flag to add a prefix to all paths in the list of changed
2020
files. This is useful to map the changed files (e.g., ["foo/my_file.go"] to their
2121
coverage profile which uses the full package name to identify the files
2222
(e.g., "github.com/fgrosse/example/foo/my_file.go"). Note that currently,
@@ -31,9 +31,9 @@ OPTIONS:
3131
`, filepath.Base(os.Args[0])))
3232

3333
type options struct {
34-
rootPkg string
35-
trim string
36-
format string
34+
root string
35+
trim string
36+
format string
3737
}
3838

3939
func main() {
@@ -44,7 +44,7 @@ func main() {
4444
flag.PrintDefaults()
4545
}
4646

47-
flag.String("root-pkg", "", "The import path of the tested repository to add as prefix to all paths of the changed files")
47+
flag.String("root", "", "The import path of the tested repository to add as prefix to all paths of the changed files")
4848
flag.String("trim", "", "trim a prefix in the \"Impacted Packages\" column of the markdown report")
4949
flag.String("format", "markdown", "output format (currently only 'markdown' is supported)")
5050

@@ -67,9 +67,9 @@ func programArgs() (oldCov, newCov, changedFile string, opts options) {
6767
}
6868

6969
opts = options{
70-
rootPkg: flag.Lookup("root-pkg").Value.String(),
71-
trim: flag.Lookup("trim").Value.String(),
72-
format: flag.Lookup("format").Value.String(),
70+
root: flag.Lookup("root").Value.String(),
71+
trim: flag.Lookup("trim").Value.String(),
72+
format: flag.Lookup("format").Value.String(),
7373
}
7474

7575
return args[0], args[1], args[2], opts
@@ -86,7 +86,7 @@ func run(oldCovPath, newCovPath, changedFilesPath string, opts options) error {
8686
return fmt.Errorf("failed to parse new coverage: %w", err)
8787
}
8888

89-
changedFiles, err := ParseChangedFiles(changedFilesPath, opts.rootPkg)
89+
changedFiles, err := ParseChangedFiles(changedFilesPath, opts.root)
9090
if err != nil {
9191
return fmt.Errorf("failed to load changed files: %w", err)
9292
}

0 commit comments

Comments
 (0)