Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatic Github release to termcols #6

Merged
merged 7 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@ jobs:
build:
strategy:
matrix:
go-version: [ '1.19', '1.21' ]
os: [ ubuntu-latest, macos-latest ]
go: [ '1.21' ]
os: [ windows-latest, ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
name: ${{ matrix.go }}/${{ matrix.os }}

steps:
- name: Set up Go
uses: actions/setup-go@v2
uses: actions/setup-go@v4
with:
go-version: ${{ matrix.go-version }}
go-version: ${{ matrix.go }}

- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Install dependencies
run: |
Expand All @@ -32,10 +35,15 @@ jobs:
run: make build

- name: Test
run: go test -v -coverprofile coverage.txt -covermode atomic ./...
run: go test -v -coverprofile='coverage.txt' -covermode='atomic' ./...

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true

release-check:
uses: ./.github/workflows/release.yaml
with:
args: --snapshot
43 changes: 43 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: release

on:
push:
tags:
- '*'
workflow_call:
inputs:
args:
description: 'Extra arguments to pass to goreleaser'
default: ''
required: false
type: string

jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'

- name: Login to Github container registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Release
uses: goreleaser/goreleaser-action@v3
with:
distribution: goreleaser
version: latest
args: release ${{ inputs.args }} --clean
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73 changes: 73 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
before:
hooks:
- go mod tidy
- go fmt ./...
- go test ./...

builds:
- id: tcols
main: ./cmd/tcols
binary: tcols
env:
- CGO_ENABLED=0
flags:
- -trimpath
ldflags:
- -X main.version={{ .Version }} -X main.commit={{ .Commit }} -X main.date={{ .CommitDate }}
mod_timestamp: '{{ .CommitTimestamp }}'
targets:
- linux_amd64
- linux_arm64
- linux_arm
- linux_riscv64
- windows_amd64
- windows_arm64
- windows_arm
- darwin_amd64
- darwin_arm64

universal_binaries:
- id: tcols
replace: true
name_template: tcols

archives:
- id: tcols
format: tar.gz
builds:
- tcols
files:
- none*
name_template: "{{ .Binary }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"

dockers:
- id: tools
goos: linux
goarch: amd64
ids:
- tcols
image_templates:
- "ghcr.io/mdm-code/tcols:latest"
- "ghcr.io/mdm-code/tcols:{{ .Tag }}"
- "ghcr.io/mdm-code/tcols:v{{ .Major }}"
skip_push: false

checksum:
name_template: 'sha256sums.txt'

snapshot:
name_template: "{{ incpatch .Version }}-next"

release:
github:
owner: mdm-code
name: tcols
draft: true
prerelease: auto
mode: replace

changelog:
use: github-native

announce:
skip: true
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM scratch
ENV PATH "$PATH:/bin"
COPY tcols /bin/tcols
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 Michał Adamczyk
Copyright (c) 2024 Michał Adamczyk

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
43 changes: 18 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
GO=go
GOFLAGS=-race
DEV_BIN=bin
COV_PROFILE=cp.out
GOFLAGS=
COV_PROFILE=coverage.txt

export CGO_ENABLED = 1
export CGO_ENABLED=0

.DEFAULT_GOAL := build

.PHONY: fmt vet lint test install build cover clean

fmt:
$(GO) fmt ./...
.PHONY: fmt
@$(GO) fmt ./...

vet: fmt
$(GO) vet ./...
.PHONY: vet
@$(GO) vet ./...

lint: vet
golint -set_exit_status=1 ./...
.PHONY: lint
@golint -set_exit_status=1 ./...

test: lint
$(GO) clean -testcache
$(GO) test ./... -v
.PHONY: test
@$(GO) clean -testcache
@$(GO) test ./... -v

install: test
$(GO) install ./...
.PHONY: install
@$(GO) install ./...

build: test
$(GO) build $(GOFLAGS) github.com/mdm-code/termcols/...
.PHONY: build
@$(GO) build $(GOFLAGS) github.com/mdm-code/termcols/...

cover:
$(GO) test -coverprofile=$(COV_PROFILE) -covermode=atomic ./...
$(GO) tool cover -html=$(COV_PROFILE)
.PHONY: cover
@$(GO) test -coverprofile=$(COV_PROFILE) -covermode=atomic ./...
@$(GO) tool cover -html=$(COV_PROFILE)

clean:
$(GO) clean github.com/mdm-code/termcols/...
$(GO) mod tidy
$(GO) clean -testcache
rm -f $(COV_PROFILE)
.PHONY: clean
@$(GO) clean github.com/mdm-code/termcols/...
@$(GO) mod tidy
@$(GO) clean -testcache
@rm -f $(COV_PROFILE)
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,13 @@ Type `tcols -h` to get a list of styles and colors to (1) see what is implemente
and (2) what is supported by your terminal.


Alternatively, `tcols` can be run from inside of the Docker container:

```sh
docker run -i ghcr.io/mdm-code/tcols:latest tcols -s 'redfg bluebg' < <(echo -n 'Hello, world!')
```


## Development

Consult [Makefile](Makefile) to see how to format, examine code with `go vet`,
Expand All @@ -125,7 +132,7 @@ This will give you ns/op value for the setup it's been benchmarked on.

## License

Copyright (c) 2022 Michał Adamczyk.
Copyright (c) 2024 Michał Adamczyk.

This project is licensed under the [MIT license](https://opensource.org/licenses/MIT).
See [LICENSE](LICENSE) for more details.
Loading