Skip to content

Commit

Permalink
Merge pull request #25 from mdp/mdp/v3.1.0
Browse files Browse the repository at this point in the history
Goreleaser and build actions
  • Loading branch information
mdp authored May 26, 2023
2 parents b74f0e0 + c760e5e commit d63a5d8
Show file tree
Hide file tree
Showing 14 changed files with 228 additions and 90 deletions.
25 changes: 25 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/go:0-1-bullseye",
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Use 'postCreateCommand' to run commands after the container is created.
"postCreateCommand": "go install github.com/goreleaser/goreleaser@latest"

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
21 changes: 21 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Build

on: [push]

jobs:
build:

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

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

- name: Build
run: go build -v ./...

- name: Test
run: go test -v ./...
49 changes: 49 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: qrterminal release

on:
push:
tags:
- "*"

permissions:
contents: write
packages: write

jobs:
Build:
runs-on: ubuntu-20.04
env:
DOCKER_BUILDKIT: 1
steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: "^1.20.4"
- name: Source checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Fetch all tags
run: git fetch --force --tags
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver: docker
install: true
- name: GitHub Container Registry Login
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- uses: goreleaser/goreleaser-action@v3
name: Publish qrterminal
with:
distribution: goreleaser
version: latest
args: release --timeout 50m
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GORELEASER_TOKEN_TAP: ${{ secrets.GORELEASER_TOKEN_TAP }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist/
18 changes: 0 additions & 18 deletions .goreleaser

This file was deleted.

106 changes: 106 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
release:
github:
owner: mdp
name: qrterminal
draft: false
# If set to auto, will mark the release as not ready for production
# in case there is an indicator for this in the tag e.g. v1.0.0-rc1
# If set to true, will mark the release as not ready for production.
# Default is false.
prerelease: auto

builds:
-
main: ./cmd/qrterminal/main.go
binary: qrterminal
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of uname.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip
files:
- LICENSE
- README.md
- CHANGELOG.md
rlcp: true
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

brews:
-
name: qrterminal
tap:
owner: mdp
name: homebrew-tap
token: "{{ .Env.GORELEASER_TOKEN_TAP }}"
commit_author:
name: mdp
email: [email protected]
homepage: https://github.com/mdp/qrterminal
description: 'Create and display QR codes on the command line'

dockers:
- image_templates:
- ghcr.io/mdp/qrterminal:{{ .Tag }}-amd64
goarch: amd64
use: buildx
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/amd64"
- image_templates:
- ghcr.io/mdp/qrterminal:{{ .Tag }}-arm64
goarch: arm64
use: buildx
dockerfile: Dockerfile
build_flag_templates:
- "--platform=linux/arm64"

docker_manifests:
- id: qrterminal-latest
name_template: ghcr.io/mdp/qrterminal:latest
image_templates:
- ghcr.io/mdp/qrterminal:{{ .Tag }}-amd64
- ghcr.io/mdp/qrterminal:{{ .Tag }}-arm64
skip_push: auto
- id: qrterminal-Tag
name_template: ghcr.io/mdp/qrterminal:{{ .Tag }}
image_templates:
- ghcr.io/mdp/qrterminal:{{ .Tag }}-amd64
- ghcr.io/mdp/qrterminal:{{ .Tag }}-arm64

# The lines beneath this are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
57 changes: 0 additions & 57 deletions .goreleaser.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 3.1.0

- Add the ability to accept input string from stdin
- Integrate github actions for build and release

## 3.0.0

Adjust go.mod to include required version string
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# QRCode Terminal

[![Build Status](https://api.travis-ci.org/mdp/qrterminal.svg)](https://travis-ci.org/mdp/qrterminal)
[![Build Status](https://github.com/mdp/qrterminal/actions/workflows/build.yml/badge.svg)](https://github.com/mdp/qrterminal/actions/workflows/build.yml)

A golang library for generating QR codes in the terminal.

Expand Down Expand Up @@ -92,7 +92,7 @@ Print out a basic QR code in your terminal:
Using 'medium' error correction:
`qrterminal https://github.com/mdp/qrterminal -l M`

Or just use Docker: `docker run --rm mpercival/qrterminal:latest 'https://github.com/mdp/qrterminal'`
Or just use Docker: `docker run --rm ghcr.io/mdp/qrterminal:latest 'https://github.com/mdp/qrterminal'`

### Contributors/Credits:

Expand Down
18 changes: 12 additions & 6 deletions cmd/qrterminal/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"flag"
"fmt"
"io"
"os"
"runtime"
"strings"
Expand Down Expand Up @@ -36,12 +37,16 @@ func main() {

flag.Parse()
level := getLevel(levelFlag)
content := strings.Join(flag.Args(), " ")

if len(flag.Args()) < 1 {
fmt.Fprintf(os.Stderr, "usage of %s: \"[arguments]\"\n", os.Args[0])
fmt.Println("Options:")
flag.PrintDefaults()
os.Exit(1)
if len(content) < 1 {
// Get input from stdin until EOF
stdin, err := io.ReadAll(os.Stdin)

if err != nil {
panic(err)
}
content = string(stdin)
} else if level < 0 {
fmt.Fprintf(os.Stderr, "Invalid error correction level: %s\n", levelFlag)
fmt.Fprintf(os.Stderr, "Valid options are [L, M, H]\n")
Expand Down Expand Up @@ -69,5 +74,6 @@ func main() {
cfg.WhiteChar = qrterminal.WHITE
}

qrterminal.GenerateWithConfig(strings.Join(flag.Args(), "\n"), cfg)
fmt.Fprint(os.Stdout, "\n")
qrterminal.GenerateWithConfig(content, cfg)
}
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
module github.com/mdp/qrterminal/v3

go 1.20

require (
github.com/mattn/go-colorable v0.1.2
github.com/mdp/qrterminal v1.0.1
rsc.io/qr v0.2.0
)

require (
github.com/mattn/go-isatty v0.0.8 // indirect
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect
)
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mdp/qrterminal v1.0.1 h1:07+fzVDlPuBlXS8tB0ktTAyf+Lp1j2+2zK3fBOL5b7c=
github.com/mdp/qrterminal v1.0.1/go.mod h1:Z33WhxQe9B6CdW37HaVqcRKzP+kByF3q/qLxOGe12xQ=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
rsc.io/qr v0.2.0 h1:6vBLea5/NRMVTz8V66gipeLycZMl/+UlFmk8DvqQ6WY=
Expand Down
Binary file added oryxBuildBinary
Binary file not shown.

0 comments on commit d63a5d8

Please sign in to comment.