Skip to content

Commit

Permalink
feat: add semantic release (#12)
Browse files Browse the repository at this point in the history
* fix: build and linting

Signed-off-by: Manuel Vogel <[email protected]>

* feat: add semantic release

Signed-off-by: Manuel Vogel <[email protected]>

* chore: remove deprecated tools

Signed-off-by: Manuel Vogel <[email protected]>

* feat: add renovate

Signed-off-by: Manuel Vogel <[email protected]>

* fix: back from main to tmp master

Signed-off-by: Manuel Vogel <[email protected]>

* fix: run test and lint on PR

Signed-off-by: Manuel Vogel <[email protected]>

* fix(ci): use also GH token for semantic release

Signed-off-by: Manuel Vogel <[email protected]>

---------

Signed-off-by: Manuel Vogel <[email protected]>
  • Loading branch information
mavogel authored Oct 14, 2024
1 parent 8b09f88 commit fa91354
Show file tree
Hide file tree
Showing 14 changed files with 194 additions and 182 deletions.
40 changes: 0 additions & 40 deletions .chglog/CHANGELOG.tpl.md

This file was deleted.

33 changes: 0 additions & 33 deletions .chglog/config.yml

This file was deleted.

6 changes: 6 additions & 0 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": [
"config:recommended"
]
}
20 changes: 10 additions & 10 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ on:
push:
branches:
- master
paths-ignore:
- 'README.md'

permissions:
contents: read

jobs:
golangci:
lint:
name: lint
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
fetch-depth: 0
go-version: '1.21.x'
cache: false
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.40.0
uses: golangci/golangci-lint-action@v6
26 changes: 0 additions & 26 deletions .github/workflows/release.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .github/workflows/semantic-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: semantic-lint

on:
pull_request_target:
types:
- opened
- edited
- synchronize

permissions:
contents: read
pull-requests: read

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
37 changes: 37 additions & 0 deletions .github/workflows/semantic.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: semantic
on:
push:
branches:
- master
- next

permissions:
contents: read # for checkout

jobs:
release:
name: release
runs-on: ubuntu-latest
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: setup node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
- name: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
npx \
-p @semantic-release/commit-analyzer \
-p @semantic-release/release-notes-generator \
-p @semantic-release/github \
semantic-release --debug
27 changes: 16 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ on:
- 'README.md'
jobs:
unit:
runs-on: ubuntu-20.04
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: 1.16
go-version: 1.21.x
- name: Run tests
run: make test
- name: Convert coverage
uses: jandelgado/[email protected]
- name: Upload coverage
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
path-to-lcov: coverage.lcov
#- name: Upload coverage reports to Codecov
# uses: codecov/codecov-action@v4
# env:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
#- name: Upload coverage reports to Codeclimate
# if: github.event_name != 'pull_request'
# uses: paambaati/[email protected]
# env:
# CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }}
# with:
# prefix: "github.com/mavogel/go-ssh-forward"
# coverageLocations: coverage.txt:gocov
78 changes: 70 additions & 8 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,73 @@
run:
tests: false
linters-settings:
dupl:
threshold: 100
funlen:
lines: 100
statements: 50
goconst:
min-len: 2
min-occurrences: 3
gocritic:
enabled-tags:
- diagnostic
- experimental
- opinionated
- performance
- style
disabled-checks:
- dupImport # https://github.com/go-critic/go-critic/issues/845
- ifElseChain
- octalLiteral
- whyNoLint
gocyclo:
min-complexity: 15
golint:
min-confidence: 0
lll:
line-length: 140
maligned:
suggest-new: true
misspell:
locale: US

linters:
enable-all: true
disable:
# please, do not use `enable-all`: it's deprecated and will be removed soon.
# inverted configuration with `enable-all` and `disable` is not scalable during updates of golangci-lint
disable-all: true
enable:
- bodyclose
- dogsled
- errcheck
- funlen
- goconst
- gocritic
- gocyclo
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- ineffassign
- lll
- exhaustivestruct
- interfacer
- maligned
- scopelint
- misspell
- nakedret
- nilnil
- noctx
- nolintlint
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- whitespace

issues:
exclude-rules:
- path: _test\.go
linters:
- funlen

run:
timeout: 2m
16 changes: 16 additions & 0 deletions .releaserc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- - "@semantic-release/github"
- successComment: |
:tada: This ${issue.pull_request ? 'pull request is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:
The release is available on [GitHub release](https://github.com/mavogel/go-ssh-forward/releases/tag/${nextRelease.gitTag}) :rocket:
branches:
- name: +([0-9])?(.{+([0-9]),x}).x
- name: master
- name: next
prerelease: true
- name: pre/rc
prerelease: '${name.replace(/^pre\\//g, "")}'
39 changes: 3 additions & 36 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ GOOS ?= $(shell $(GO) env GOOS)
GOARCH ?= $(shell $(GO) env GOARCH)
GOHOST ?= GOOS=$(GOOS) GOARCH=$(GOARCH) $(GO)

# Tool versions
GOLANGCI_VERSION = 1.39.0
GITCHGLOG_VERSION = 0.14.2

.PHONY: all
all: help

Expand All @@ -20,41 +16,12 @@ all: help
.PHONY: test
test: ## Run tests
@ $(MAKE) --no-print-directory log-$@
$(GOHOST) test -race -covermode atomic -coverprofile coverage.out -v ./...

bin/golangci-lint: bin/golangci-lint-${GOLANGCI_VERSION}
@ln -sf golangci-lint-${GOLANGCI_VERSION} bin/golangci-lint
bin/golangci-lint-${GOLANGCI_VERSION}:
@mkdir -p bin
curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | BINARY=golangci-lint bash -s -- v${GOLANGCI_VERSION}
@mv bin/golangci-lint $@
$(GOHOST) test -timeout 60s -race -covermode atomic -coverprofile coverage.txt -v ./...

.PHONY: lint
lint: bin/golangci-lint ## Run linters
@ $(MAKE) --no-print-directory log-$@
bin/golangci-lint run

###########
##@ Release

bin/git-chglog: bin/git-chglog-${GITCHGLOG_VERSION}
@ln -sf git-chglog-${GITCHGLOG_VERSION} bin/git-chglog
bin/git-chglog-${GITCHGLOG_VERSION}:
@mkdir -p bin
curl -L https://github.com/git-chglog/git-chglog/releases/download/v${GITCHGLOG_VERSION}/git-chglog_${GITCHGLOG_VERSION}_${OS}_amd64.tar.gz | tar -zOxf - git-chglog > ./bin/git-chglog-${GITCHGLOG_VERSION} && chmod +x ./bin/git-chglog-${GITCHGLOG_VERSION}

.PHONY: changelog
changelog: bin/git-chglog ## Generate changelog
@ $(MAKE) --no-print-directory log-$@
bin/git-chglog --next-tag $(VERSION) -o CHANGELOG.md

.PHONY: release
release: changelog ## Release a new tag
lint: ## Run linters
@ $(MAKE) --no-print-directory log-$@
git add CHANGELOG.md
git commit -m "chore: update changelog for $(VERSION)"
git tag $(VERSION)
git push origin master $(VERSION)
golangci-lint run

########
##@ Help
Expand Down
Loading

0 comments on commit fa91354

Please sign in to comment.