Skip to content

Commit

Permalink
ci: update release workflow
Browse files Browse the repository at this point in the history
test: Improve codecov
  • Loading branch information
Nicconike committed Jul 16, 2024
1 parent 9488092 commit a33cd70
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
15 changes: 12 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
permissions:
contents: write
packages: write
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- name: GitHub App Token
uses: actions/create-github-app-token@v1
Expand All @@ -37,21 +40,23 @@ jobs:

- name: Semantic Release
uses: go-semantic-release/action@v1
id: semantic
with:
github-token: ${{ steps.app-token.outputs.token }}
changelog-file: CHANGELOG.md
update-file: go.mod
changelog-generator-opt: "emojis=true"

- name: Update pkg.go.dev # https://pkg.go.dev/github.com/Nicconike/goautomate
- name: Update pkg.go.dev
if: steps.semantic.outputs.new_release_published == 'true'
run: |
VERSION=$(git describe --tags --abbrev=0)
go list -m github.com/Nicconike/goautomate@$VERSION
go list -m github.com/Nicconike/goautomate@${{ steps.semantic.outputs.new_release_version }}
goreleaser:
name: GoReleaser
needs: semantic-release
runs-on: ubuntu-latest
if: needs.semantic-release.outputs.new_release_published == 'true'
permissions:
contents: write
packages: write
Expand All @@ -69,6 +74,9 @@ jobs:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Fetch latest tags
run: git fetch --force --tags

- name: Set up Go
uses: actions/setup-go@v5
with:
Expand All @@ -82,3 +90,4 @@ jobs:
args: release --clean
env:
GITHUB_TOKEN: ${{ steps.app-token.outputs.token }}
GORELEASER_CURRENT_TAG: ${{ needs.semantic-release.outputs.new_release_version }}
19 changes: 18 additions & 1 deletion tests/unit/checksum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func TestGetOfficialChecksum(t *testing.T) {
want: "",
wantErr: "failed to fetch Go releases: HTTP status 500",
},
{
name: "HTTP GET request failure",
serverFunc: func(w http.ResponseWriter, r *http.Request) {
panic("forced connection error")
},
filename: "go1.22.5.linux-amd64.tar.gz",
want: "",
wantErr: "failed to fetch Go releases",
},
{
name: "Read body error",
serverFunc: func(w http.ResponseWriter, r *http.Request) {
Expand All @@ -128,7 +137,15 @@ func TestGetOfficialChecksum(t *testing.T) {

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(tt.serverFunc))
var server *httptest.Server
server = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
defer func() {
if r := recover(); r != nil {
server.CloseClientConnections()
}
}()
tt.serverFunc(w, r)
}))
defer server.Close()

originalURL := pkg.URL
Expand Down

0 comments on commit a33cd70

Please sign in to comment.