Skip to content

Commit

Permalink
fix tests after main branch rename; drop common make
Browse files Browse the repository at this point in the history
some tests were failing after renaming master branch to main. fixed.

makefile: drop common-make includes; simplify make tasks

gha: bump GHA actions versions and configure dependabot to automate
updates
  • Loading branch information
joemiller committed Nov 20, 2024
1 parent a1fcd0a commit 4f00265
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 355 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ updates:
directory: /
schedule:
interval: daily

- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
52 changes: 21 additions & 31 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,62 +1,52 @@
name: CI

on:
push:
branches:
- 'main'
- main
pull_request:
types:
- opened
- reopened
- synchronize

jobs:
test:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up Go
uses: actions/setup-go@v2
uses: actions/checkout@v4

- name: Restore Go Modules Cache
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Run golangci-lint
uses: golangci/golangci-lint-action@v6

- name: Environment Config
run: |
echo "$HOME/go/bin" >> $GITHUB_PATH
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Download Dependencies
run: |
go mod download
- name: Set up Go
uses: actions/setup-go@v5

- name: Git Config for Unit Tests
run: |
git config --global user.email ci
git config --global user.name ci
git config --global init.defaultBranch main
- name: Run Unit Tests
run: |
make test-gha
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Run Linter
uses: golangci/golangci-lint-action@v2
make test
goreleaser-check:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Check goreleaser's Configuration
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v6
with:
version: latest
args: check
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ dist/
Attic
.vscode/
/.idea/
cover.out
25 changes: 17 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
APP := autotag

include scripts/make/common.mk
include scripts/make/common-go.mk
.PHONY: lint build test cov run

build::
CGO_ENABLED=0 go build -o $(APP)/$(APP) $(APP)/*.go
default: build

snapshot:
@goreleaser --rm-dist --snapshot --debug
build:
CGO_ENABLED=0 go build -trimpath -v -o $(APP)/$(APP) $(APP)/*.go

lint:
golangci-lint run -v ./...

test:
go test -cover -coverprofile=cover.out -v ./...

.PHONY:: test-gha
test-gha:: test-go ## for running unit tests on GitHub Actions
cov:
@echo "--- Coverage:"
go tool cover -html=cover.out
go tool cover -func cover.out

snapshot:
@goreleaser --rm-dist --snapshot --debug
11 changes: 5 additions & 6 deletions autotag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ type testRepoSetup struct {
// testing the autotag package.
// You must call cleanupTestRepo(t, r.repo) to remove the temporary directory after running tests.
func newTestRepo(t *testing.T, setup testRepoSetup) GitRepo {
t.Helper()

tr := createTestRepo(t, setup.branch)

repo, err := git.Open(tr)
checkFatal(t, err)

branch := setup.branch
if branch == "" {
branch = "master"
branch = "main"
}

tag := setup.initialTag
Expand Down Expand Up @@ -99,7 +101,6 @@ func newTestRepo(t *testing.T, setup testRepoSetup) GitRepo {
Scheme: setup.scheme,
Prefix: !setup.disablePrefix,
})

if err != nil {
t.Fatal("Error creating repo: ", err)
}
Expand Down Expand Up @@ -179,7 +180,7 @@ func TestValidateConfig(t *testing.T) {
}

func TestNewRepo(t *testing.T) {
var newRepoTests = []struct {
newRepoTests := []struct {
createBranch string
requestBranch string
expectBranch string
Expand All @@ -203,7 +204,6 @@ func TestNewRepo(t *testing.T) {
Branch: tt.requestBranch,
RepoPath: repo.Path(),
})

if err != nil {
t.Fatal("Error creating repo: ", err)
}
Expand Down Expand Up @@ -243,7 +243,7 @@ func TestNewRepoMainAndMaster(t *testing.T) {
makeTag(repo, "v0.2.1")

// check results
var newRepoTests = []struct {
newRepoTests := []struct {
requestBranch string
expectBranch string
}{
Expand All @@ -257,7 +257,6 @@ func TestNewRepoMainAndMaster(t *testing.T) {
Branch: tt.requestBranch,
RepoPath: repo.Path(),
})

if err != nil {
t.Fatal("Error creating repo: ", err)
}
Expand Down
24 changes: 0 additions & 24 deletions scripts/install-libgit2.sh

This file was deleted.

166 changes: 0 additions & 166 deletions scripts/make/common-go.mk

This file was deleted.

12 changes: 0 additions & 12 deletions scripts/make/common.mk

This file was deleted.

Loading

0 comments on commit 4f00265

Please sign in to comment.