Skip to content

Commit

Permalink
Refactor package
Browse files Browse the repository at this point in the history
- Upgrade to Go 1.16
- Build binary for Apple Silicon
- Change package path from `github.com/wabarc/archive.is/pkg` to `github.com/wabarc/archive.is`
- Minor improvements
- Do not redirect for wayback
- Add playback func to search archived URLs
- Add more tests
  • Loading branch information
web-flow committed Apr 17, 2021
1 parent 3c4eba7 commit 1b8c3a6
Show file tree
Hide file tree
Showing 16 changed files with 498 additions and 363 deletions.
23 changes: 10 additions & 13 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ jobs:
arch: ppc64
- os: linux
arch: ppc64le
- os: darwin
arch: arm64
exclude:
- os: darwin
arch: 386
Expand All @@ -68,7 +70,7 @@ jobs:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15
go-version: ^1.16

- name: Build fat binary
id: builder
Expand Down Expand Up @@ -128,24 +130,19 @@ jobs:
path: archive-is # Put files to archive.is directory

- name: Create Release
uses: actions/create-release@v1
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
body: |
See [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/CHANGELOG.md).
**Digests in this release:**
```
${{ needs.checksum.outputs.digest }}
```
draft: false
prerelease: true

- name: Upload release assets
uses: fnkr/github-action-ghr@v1
if: startsWith(github.ref, 'refs/tags/')
env:
GHR_PATH: archive-is/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
draft: true
files: |
archive-is/*
12 changes: 4 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ export GOPROXY = https://proxy.golang.org
NAME = archive.is
BINDIR ?= ./build/binary
PACKDIR ?= ./build/package
LDFLAGS := $(shell echo "-X 'archive.is/version.Version=`git describe --tags --abbrev=0`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X 'archive.is/version.Commit=`git rev-parse --short HEAD`'")
LDFLAGS := $(shell echo "${LDFLAGS} -X 'archive.is/version.BuildDate=`date +%FT%T%z`'")
LDFLAGS := $(shell echo "-X 'github.com/wabarc/archive.is.Version=`git describe --tags --abbrev=0`'")
GOBUILD ?= CGO_ENABLED=0 go build -trimpath --ldflags "-s -w ${LDFLAGS} -buildid=" -v
VERSION ?= $(shell git describe --tags `git rev-list --tags --max-count=1` | sed -e 's/v//g')
GOFILES ?= $(wildcard ./cmd/archive.is/*.go)
Expand All @@ -15,6 +13,7 @@ PACKAGES ?= $(shell go list ./...)

PLATFORM_LIST = \
darwin-amd64 \
darwin-arm64 \
linux-386 \
linux-amd64 \
linux-armv5 \
Expand Down Expand Up @@ -42,6 +41,7 @@ WINDOWS_ARCH_LIST = \
.PHONY: \
darwin-386 \
darwin-amd64 \
darwin-arm64 \
linux-386 \
linux-amd64 \
linux-armv5 \
Expand All @@ -68,11 +68,7 @@ WINDOWS_ARCH_LIST = \
releases \
clean \
test \
fmt \
rpm \
debian \
debian-packages \
docker-image
fmt

darwin-386:
GOARCH=386 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)
Expand Down
54 changes: 54 additions & 0 deletions cmd/archive.is/is.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package main

import (
"flag"
"fmt"
"os"

"github.com/wabarc/archive.is"
)

func main() {
var (
playback bool
version bool
)

const playbackHelp = "Search archived URL"
const versionHelp = "Show version"

flag.BoolVar(&playback, "playback", false, playbackHelp)
flag.BoolVar(&playback, "p", false, playbackHelp)
flag.BoolVar(&version, "version", false, versionHelp)
flag.BoolVar(&version, "v", false, versionHelp)
flag.Parse()

if version {
fmt.Println(is.Version)
os.Exit(0)
}

args := flag.Args()
if len(args) < 1 {
flag.Usage()
e := os.Args[0]
fmt.Printf(" %s url [url]\n\n", e)
fmt.Printf("example:\n %s https://example.com https://example.org\n\n", e)
os.Exit(1)
}

wbrc := &is.Archiver{}

if playback {
collects, _ := wbrc.Playback(args)
for orig, dest := range collects {
fmt.Println(orig, "=>", dest)
}
os.Exit(0)
}

saved, _ := wbrc.Wayback(args)
for orig, dest := range saved {
fmt.Println(orig, "=>", dest)
}
}
28 changes: 0 additions & 28 deletions cmd/is.go

This file was deleted.

File renamed without changes.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ require (
github.com/cretz/bine v0.1.0
github.com/stretchr/testify v1.7.0 // indirect
github.com/wabarc/helper v0.0.0-20210127120855-10af37cc2616
github.com/wabarc/logger v0.0.0-20210417045349-d0d82e8e99ee
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5Cc
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/wabarc/helper v0.0.0-20210127120855-10af37cc2616 h1:wZ5HtpmZAVUq0Im5Sm92ycJrTeLJk5lB/Kvh55Rd+Ps=
github.com/wabarc/helper v0.0.0-20210127120855-10af37cc2616/go.mod h1:N9P4r7Rn46p4nkWtXV6ztN3p5ACVnp++bgfwjTqSxQ8=
github.com/wabarc/logger v0.0.0-20210417045349-d0d82e8e99ee h1:MMIp++7eem2CI1jIYDoPByMwXeZAjsFo2ciBNtvhB80=
github.com/wabarc/logger v0.0.0-20210417045349-d0d82e8e99ee/go.mod h1:4uYr9fnQaQoDk1ttTzLnSB3lZm3i/vrJwN8EZIB2YuI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down
Loading

0 comments on commit 1b8c3a6

Please sign in to comment.