Skip to content

Commit

Permalink
Add release workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
web-flow committed Sep 19, 2020
1 parent 843ce59 commit 10e8098
Show file tree
Hide file tree
Showing 4 changed files with 284 additions and 34 deletions.
34 changes: 0 additions & 34 deletions .github/workflows/go.yml

This file was deleted.

95 changes: 95 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
name: Release

on:
push:
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
setup:
name: Initial build env
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15

build:
name: Checkout, build, archive, upload
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: List checked-out code
run: ls -al

- name: Build fat binary
run: make all-arch

- name: Archive binary
run: make releases

- name: Upload archived binary
uses: actions/upload-artifact@v2
with:
name: ipfs-pinner
path: build/package/ipfs-pinner*

checksum:
name: Get archived packages checksum
runs-on: ubuntu-latest
needs: build
outputs:
digest: ${{ steps.digest.outputs.result }}
steps:
- name: Download math result from build job
uses: actions/download-artifact@v2
with:
name: ipfs-pinner
path: bin

- name: Create all binary digest
id: digest
run: |
digest=$(find bin/ipfs-pinner* -type f -exec sha256sum {} +)
digest="${digest//$'%'/%25}"
digest="${digest//$'\n'/%0A}"
digest="${digest//$'bin\/'}"
echo "::set-output name=result::$digest"
release:
name: Create and upload release
runs-on: ubuntu-latest
needs: [build, checksum]
steps:
- name: Download math result from build and checksum jobs
uses: actions/download-artifact@v2
with:
name: ipfs-pinner
path: ipfs-pinner # Put files to ipfs-pinner directory

- name: Create Release
uses: actions/create-release@v1
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: |
**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: ipfs-pinner/
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
52 changes: 52 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Test

on:
push:
branches: [ master ]
paths:
- "**/*.go"
- "go.mod"
- "go.sum"
pull_request:
branches: [ master ]
types: [ opened, synchronize, reopened ]
paths:
- "**/*.go"
- "go.mod"
- "go.sum"

jobs:
test:
name: Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
steps:
- name: Set up Go 1.x
uses: actions/setup-go@v2
with:
go-version: ^1.15

- name: Set up IPFS
uses: ibnesayeed/setup-ipfs@master
id: ipfs
with:
run_daemon: true

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Cache go module
uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: ${{ runner.os }}-go-

- name: Test
run: go test -v ./...
137 changes: 137 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
export GO111MODULE = on
export GOPROXY = https://proxy.golang.org

NAME = ipfs-pinner
BINDIR ?= ./bin
PACKDIR ?= ./build/package
GOBUILD := CGO_ENABLED=0 go build --ldflags="-s -w" -v
GOFILES := $(wildcard ./cmd/ipfs-pinner/*.go)
VERSION := $(shell git describe --tags `git rev-list --tags --max-count=1`)
VERSION := $(VERSION:v%=%)
PROJECT := github.com/wabarc/ipfs-pinner
PACKAGES := $(shell go list ./...)

PLATFORM_LIST = \
darwin-amd64 \
linux-386 \
linux-amd64 \
linux-armv5 \
linux-armv6 \
linux-armv7 \
linux-armv8 \
linux-mips-softfloat \
linux-mips-hardfloat \
linux-mipsle-softfloat \
linux-mipsle-hardfloat \
linux-mips64 \
linux-mips64le \
linux-ppc64 \
linux-ppc64le \
linux-s390x \
freebsd-386 \
freebsd-amd64 \
openbsd-386 \
openbsd-amd64

WINDOWS_ARCH_LIST = \
windows-386 \
windows-amd64

.PHONY: all
all: linux-amd64 darwin-amd64 windows-amd64

darwin-386:
GOARCH=386 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

darwin-amd64:
GOARCH=amd64 GOOS=darwin $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-386:
GOARCH=386 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-amd64:
GOARCH=amd64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-armv5:
GOARCH=arm GOOS=linux GOARM=5 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-armv6:
GOARCH=arm GOOS=linux GOARM=6 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-armv7:
GOARCH=arm GOOS=linux GOARM=7 $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-armv8:
GOARCH=arm64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-mips-softfloat:
GOARCH=mips GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-mips-hardfloat:
GOARCH=mips GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-mipsle-softfloat:
GOARCH=mipsle GOMIPS=softfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-mipsle-hardfloat:
GOARCH=mipsle GOMIPS=hardfloat GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-mips64:
GOARCH=mips64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-mips64le:
GOARCH=mips64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-ppc64:
GOARCH=ppc64 GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-ppc64le:
GOARCH=ppc64le GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

linux-s390x:
GOARCH=s390x GOOS=linux $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

freebsd-386:
GOARCH=386 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

freebsd-amd64:
GOARCH=amd64 GOOS=freebsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

openbsd-386:
GOARCH=386 GOOS=openbsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

openbsd-amd64:
GOARCH=amd64 GOOS=openbsd $(GOBUILD) -o $(BINDIR)/$(NAME)-$@ $(GOFILES)

windows-386:
GOARCH=386 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe $(GOFILES)

windows-amd64:
GOARCH=amd64 GOOS=windows $(GOBUILD) -o $(BINDIR)/$(NAME)-$@.exe $(GOFILES)

fmt:
@echo "-> Running go fmt"
@go fmt $(PACKAGES)

tar_releases := $(addsuffix .gz, $(PLATFORM_LIST))
zip_releases := $(addsuffix .zip, $(WINDOWS_ARCH_LIST))

$(tar_releases): %.gz : %
@mkdir -p $(PACKDIR)
chmod +x $(BINDIR)/$(NAME)-$(basename $@)
tar -czf $(PACKDIR)/$(NAME)-$(basename $@)-$(VERSION).tar.gz --transform "s,$(BINDIR)/,bin/," $(BINDIR)/$(NAME)-$(basename $@)

$(zip_releases): %.zip : %
@mkdir -p $(PACKDIR)
zip -m -j $(PACKDIR)/$(NAME)-$(basename $@)-$(VERSION).zip $(BINDIR)/$(NAME)-$(basename $@).exe

all-arch: $(PLATFORM_LIST) $(WINDOWS_ARCH_LIST)

releases: $(tar_releases) $(zip_releases)

clean:
rm -f $(BINDIR)/*
rm -f $(PACKDIR)/*

tag:
git tag v$(VERSION)

0 comments on commit 10e8098

Please sign in to comment.