Skip to content

Commit 267f47d

Browse files
committed
Add GitHub Actions workflow for building and releasing
1 parent ceb6106 commit 267f47d

28 files changed

+523
-177
lines changed

.github/workflows/README.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# CI/CD Workflows
2+
3+
This directory contains GitHub Actions workflows for continuous integration and deployment.
4+
5+
## Workflows
6+
7+
### CI (`ci.yml`)
8+
Runs on every push and pull request to master/main branch.
9+
10+
**Jobs:**
11+
- **Lint**: Code formatting, imports, and linting checks
12+
- **Test**: Unit tests across multiple Go versions and OS platforms
13+
- **Security**: Security scanning with gosec and govulncheck
14+
- **Build**: Multi-platform builds (Linux, macOS, Windows)
15+
- **Integration**: Integration test suite
16+
- **Dependency Review**: Security review of dependencies (PRs only)
17+
18+
### Release (`release.yml`)
19+
Runs when a version tag is pushed (e.g., `v1.0.0`).
20+
21+
**Features:**
22+
- Automated packaging with `package.sh`
23+
- GitHub release creation
24+
- Binary artifact uploads
25+
26+
## Local Development
27+
28+
### Prerequisites
29+
```bash
30+
# Install golangci-lint
31+
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
32+
33+
# Install goimports
34+
go install golang.org/x/tools/cmd/goimports@latest
35+
```
36+
37+
### Commands
38+
```bash
39+
# Run all checks locally
40+
make lint
41+
42+
# Format code
43+
make fmt
44+
45+
# Run tests
46+
make test
47+
48+
# Build
49+
make build
50+
```
51+
52+
## Configuration
53+
54+
### golangci-lint (`.golangci.yml`)
55+
Comprehensive linting configuration with:
56+
- Code quality checks
57+
- Security scanning
58+
- Performance analysis
59+
- Style enforcement
60+
61+
### Dependabot (`.github/dependabot.yml`)
62+
Automated dependency updates:
63+
- Go modules: Weekly updates
64+
- GitHub Actions: Weekly updates
65+
- Automatic PR creation with reviews
66+
67+
## Best Practices
68+
69+
1. **Always run `make lint` before committing**
70+
2. **Ensure tests pass locally before pushing**
71+
3. **Use conventional commit messages**
72+
4. **Review Dependabot PRs promptly**
73+
5. **Tag releases with semantic versioning (v1.0.0)**

.github/workflows/ci.yml

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
lint:
11+
name: Lint and Format Check
12+
runs-on: ubuntu-latest
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v4
19+
with:
20+
go-version: '1.25'
21+
22+
- name: Install golangci-lint
23+
uses: golangci/golangci-lint-action@v8
24+
with:
25+
version: v2.4.0
26+
args: --timeout=10m
27+
skip-cache: true
28+
29+
- name: Install goimports
30+
run: go install golang.org/x/tools/cmd/goimports@latest
31+
32+
- name: Check formatting
33+
run: |
34+
if [ "$(gofmt -l . | wc -l)" -gt 0 ]; then
35+
echo "Code is not formatted. Please run 'make fmt' and commit changes."
36+
gofmt -l .
37+
exit 1
38+
fi
39+
40+
- name: Check imports
41+
run: |
42+
if [ "$(goimports -l . | wc -l)" -gt 0 ]; then
43+
echo "Imports are not properly formatted. Please run 'make fmt' and commit changes."
44+
goimports -l .
45+
exit 1
46+
fi
47+
48+
test:
49+
name: Test
50+
runs-on: ubuntu-latest
51+
strategy:
52+
matrix:
53+
go-version: [ '1.25' ]
54+
os: [ ubuntu-latest, macos-latest, windows-latest ]
55+
steps:
56+
- name: Checkout code
57+
uses: actions/checkout@v4
58+
59+
- name: Set up Go ${{ matrix.go-version }}
60+
uses: actions/setup-go@v4
61+
with:
62+
go-version: ${{ matrix.go-version }}
63+
64+
- name: Install dependencies
65+
run: go mod download
66+
67+
- name: Verify dependencies
68+
run: go mod verify
69+
70+
- name: Run tests
71+
run: go test -v -race -coverprofile=coverage.out -covermode=atomic ./...
72+
73+
- name: Upload coverage to Codecov
74+
uses: codecov/codecov-action@v4
75+
with:
76+
file: ./coverage.out
77+
flags: unittests
78+
name: codecov-umbrella
79+
fail_ci_if_error: false
80+
81+
security:
82+
name: Security Scan
83+
runs-on: ubuntu-latest
84+
needs: [lint, test]
85+
steps:
86+
- uses: actions/checkout@v4
87+
88+
- name: Set up Go
89+
uses: actions/setup-go@v4
90+
with:
91+
go-version: '1.25'
92+
93+
- name: Install GoSec
94+
run: |
95+
go install github.com/securego/gosec/v2/cmd/gosec@latest
96+
97+
- name: Run GoSec
98+
run: |
99+
gosec -fmt sarif -out results.sarif ./...
100+
101+
- name: Upload GoSec SARIF
102+
uses: github/codeql-action/upload-sarif@v3
103+
if: always()
104+
with:
105+
sarif_file: results.sarif
106+
107+
- name: Run govulncheck
108+
run: |
109+
go install golang.org/x/vuln/cmd/govulncheck@latest
110+
govulncheck ./...
111+
112+
build:
113+
name: Build
114+
runs-on: ubuntu-latest
115+
needs: [lint, test]
116+
strategy:
117+
matrix:
118+
goos: [linux, darwin, windows]
119+
goarch: [amd64, arm64]
120+
exclude:
121+
- goos: windows
122+
goarch: arm64
123+
steps:
124+
- name: Checkout code
125+
uses: actions/checkout@v4
126+
127+
- name: Set up Go
128+
uses: actions/setup-go@v4
129+
with:
130+
go-version: '1.25'
131+
132+
- name: Build for ${{ matrix.goos }}/${{ matrix.goarch }}
133+
env:
134+
GOOS: ${{ matrix.goos }}
135+
GOARCH: ${{ matrix.goarch }}
136+
run: |
137+
go build -v -ldflags="-s -w -X main.Version=$(cat VERSION)" -o "ssh-aliases-${{ matrix.goos }}-${{ matrix.goarch }}"
138+
139+
- name: Upload build artifacts
140+
uses: actions/upload-artifact@v4
141+
with:
142+
name: ssh-aliases-${{ matrix.goos }}-${{ matrix.goarch }}
143+
path: ssh-aliases-${{ matrix.goos }}-${{ matrix.goarch }}
144+
145+
dependency-review:
146+
name: Dependency Review
147+
runs-on: ubuntu-latest
148+
if: github.event_name == 'pull_request'
149+
steps:
150+
- name: Checkout code
151+
uses: actions/checkout@v4
152+
153+
- name: Dependency Review
154+
uses: actions/dependency-review-action@v4
155+
with:
156+
fail-on-severity: moderate

.github/workflows/release.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
jobs:
9+
release:
10+
name: Package and Release
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up Go
17+
uses: actions/setup-go@v4
18+
with:
19+
go-version: '1.25'
20+
21+
- name: Install dependencies
22+
run: go mod download
23+
24+
- name: Run package.sh
25+
run: |
26+
chmod +x ./package.sh
27+
./package.sh ${{ github.ref_name }}
28+
29+
- name: Create GitHub Release
30+
uses: softprops/action-gh-release@v1
31+
with:
32+
files: dist/*
33+
draft: false
34+
prerelease: false
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.golangci.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
version: '2'
2+
3+
run:
4+
timeout: 10m
5+
go: "1.25"
6+
7+
linters:
8+
enable:
9+
- govet
10+
- errcheck
11+
- staticcheck
12+
- ineffassign
13+
- unused
14+
- misspell
15+
- dupl
16+
- gocritic
17+
- revive
18+
- unconvert
19+
- goconst
20+
- prealloc
21+
- nakedret
22+
- noctx
23+
- paralleltest
24+
- tagliatelle
25+
- tparallel
26+
- wastedassign

.travis.yml

Lines changed: 0 additions & 16 deletions
This file was deleted.

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
APP_NAME := ssh-aliases
22
APP_VERSION := $(shell cat VERSION)
33

4-
PACKAGES := $(shell go list ./... | grep -v /vendor/)
4+
PACKAGES := $(shell go list ./...)
55
BUILD_FOLDER := target
66
DIST_FOLDER := dist
77

8-
GIT_DESC := $(shell git describe)
8+
GIT_DESC := $(shell git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
99
GIT_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
1010

11-
SRC := $(shell find . -type f -name '*.go' -not -path "./vendor/*")
11+
SRC := $(shell find . -type f -name '*.go')
1212

1313
.PHONY: all version fmt clean test build release lint lint-deps
1414

15-
ifneq "$(APP_VERSION)" "$(GIT_DESC)"
15+
# Only use git describe if VERSION file doesn't exist or is empty
16+
ifneq "$(APP_VERSION)" ""
17+
# VERSION file exists and has content, use it
18+
else
1619
APP_VERSION := $(GIT_DESC)-$(GIT_BRANCH)
1720
endif
1821

@@ -36,12 +39,10 @@ build:
3639
release: clean lint build
3740
@bash ./package.sh $(APP_VERSION)
3841

39-
fmt: lint-deps
42+
fmt:
4043
@goimports -w $(SRC)
4144
@gofmt -l -s -w $(SRC)
4245

43-
lint: lint-deps
46+
lint:
4447
@golangci-lint run
4548

46-
lint-deps:
47-
@which golangci-lint > /dev/null || go get -u github.com/golangci/golangci-lint/cmd/golangci-lint

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# ssh-aliases
2-
[![Build Status](https://travis-ci.org/dankraw/ssh-aliases.svg?branch=master)](https://travis-ci.org/dankraw/ssh-aliases)
32
[![Go Report Card](https://goreportcard.com/badge/github.com/dankraw/ssh-aliases)](https://goreportcard.com/report/github.com/dankraw/ssh-aliases)
43

54
`ssh-aliases` is a command line tool that brings ease to living with `~/.ssh/config`.

command/cli.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Package command provides CLI command implementations for ssh-aliases
12
package command
23

34
import (
@@ -65,7 +66,7 @@ func configureCLI(version string, writer io.Writer) (*cli.App, error) {
6566
Destination: &hostsFile,
6667
},
6768
},
68-
Action: func(ctx *cli.Context) error {
69+
Action: func(_ *cli.Context) error {
6970
hosts, err := readHostsFile(hostsFile)
7071
if err != nil {
7172
return cli.NewExitError(err.Error(), 1)
@@ -103,7 +104,7 @@ func configureCLI(version string, writer io.Writer) (*cli.App, error) {
103104
Destination: &hostsFile,
104105
},
105106
},
106-
Action: func(ctx *cli.Context) error {
107+
Action: func(_ *cli.Context) error {
107108
var err error
108109
hosts, err := readHostsFile(hostsFile)
109110
if err != nil {

0 commit comments

Comments
 (0)