Skip to content

Commit

Permalink
Migrate to GitHub Actions and GHCR (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 authored Mar 22, 2021
1 parent e7de9a3 commit 4c57e37
Show file tree
Hide file tree
Showing 4 changed files with 162 additions and 39 deletions.
19 changes: 3 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,7 @@ jobs:
docker:
- image: circleci/golang:1.13.7
steps:
- run: mkdir -p ~/bin
- run: echo 'export PATH="$HOME/bin:$PATH"' >> $BASH_ENV
- run: curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b ~/bin v1.21.0
- run: go get github.com/int128/goxzst
- run: |
curl -fL -o /tmp/ghcp.zip https://github.com/int128/ghcp/releases/download/v1.8.0/ghcp_linux_amd64.zip
unzip /tmp/ghcp.zip -d ~/bin
- checkout
- run: make check
- run: make dist
- run: |
if [ "$CIRCLE_TAG" ]; then
make VERSION="$CIRCLE_TAG" release
fi
- run: echo

workflows:
version: 2
Expand All @@ -26,5 +13,5 @@ workflows:
- build:
context: open-source
filters:
tags:
only: /.*/
branches:
only: /^dummy$/
27 changes: 27 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: docker

on:
push:
branches:
- master
paths:
- .github/workflows/docker.yaml
- '**.go'
- go.*
- Dockerfile
tags:
- v*

jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- run: make docker-build-push
90 changes: 90 additions & 0 deletions .github/workflows/go.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: go

on:
push:
branches:
- master
paths:
- .github/workflows/go.yaml
- '**.go'
- go.*
tags:
- v*
pull_request:
branches:
- master
paths:
- .github/workflows/go.yaml
- '**.go'
- go.*

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: golangci/golangci-lint-action@v2
with:
version: v1.38.0

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: go-${{ runner.os }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-${{ runner.os }}-
- run: go test -v -race -cover -coverprofile=coverage.out ./...
- uses: codecov/codecov-action@v1

release:
strategy:
matrix:
platform:
- os: ubuntu-latest
GOOS: linux
GOARCH: amd64
- os: ubuntu-latest
GOOS: linux
GOARCH: arm64
- os: ubuntu-latest
GOOS: linux
GOARCH: arm
- os: macos-latest
GOOS: darwin
GOARCH: amd64
- os: macos-latest
GOOS: darwin
GOARCH: arm64
- os: windows-latest
GOOS: windows
GOARCH: amd64
runs-on: ${{ matrix.platform.os }}
env:
GOOS: ${{ matrix.platform.GOOS }}
GOARCH: ${{ matrix.platform.GOARCH }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: 1.16
- uses: actions/cache@v2
with:
path: ~/go/pkg/mod
key: go-${{ matrix.platform.GOOS }}-${{ matrix.platform.GOARCH }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
go-${{ matrix.platform.GOOS }}-${{ matrix.platform.GOARCH }}-
- run: make dist
- run: make dist-release
if: startswith(github.ref, 'refs/tags/')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
65 changes: 42 additions & 23 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,53 @@
TARGET := slack-docker
VERSION ?= latest
GITHUB_USERNAME := int128
GITHUB_REPONAME := slack-docker
TARGET_ARCHIVE := $(TARGET)_$(GOOS)_$(GOARCH).zip
TARGET_DIGEST := $(TARGET)_$(GOOS)_$(GOARCH).zip.sha256

# determine the version from ref
ifeq ($(GITHUB_REF), refs/heads/master)
VERSION := latest
else
VERSION ?= $(notdir $(GITHUB_REF))
endif

LDFLAGS := -X main.version=$(VERSION)
OSARCH := linux_arm64 linux_amd64 darwin_amd64 windows_amd64 linux_arm

all: $(TARGET)

$(TARGET):
go build -o $@ -ldflags "$(LDFLAGS)"

.PHONY: check
check:
golangci-lint run
go test -v ./...

.PHONY: dist
dist:
# make the zip files for GitHub Releases
VERSION=$(VERSION) CGO_ENABLED=0 goxzst -d dist -i "LICENSE" -o "$(TARGET)" -t "$(TARGET).rb" -osarch "$(OSARCH)" -- -ldflags "$(LDFLAGS)"
# test the zip file
zipinfo dist/$(TARGET)_linux_amd64.zip

.PHONY: release
release: dist
# publish the binaries
ghcp release -u "$(GITHUB_USERNAME)" -r "$(GITHUB_REPONAME)" -t "$(VERSION)" dist/
# publish the Homebrew formula
ghcp commit -u "$(GITHUB_USERNAME)" -r "homebrew-$(GITHUB_REPONAME)" -b "bump-$(VERSION)" -m "Bump the version to $(VERSION)" -C dist/ $(TARGET).rb
ghcp pull-request -u "$(GITHUB_USERNAME)" -r "homebrew-$(GITHUB_REPONAME)" -b "bump-$(VERSION)" --title "Bump the version to $(VERSION)"
dist: $(TARGET_ARCHIVE) $(TARGET_DIGEST)
$(TARGET_ARCHIVE): $(TARGET)
ifeq ($(GOOS), windows)
powershell Compress-Archive -Path $(TARGET),LICENSE,README.md -DestinationPath $@
else
zip $@ $(TARGET) LICENSE README.md
endif

$(TARGET_DIGEST): $(TARGET_ARCHIVE)
ifeq ($(GOOS), darwin)
shasum -a 256 -b $(TARGET_ARCHIVE) > $@
else
sha256sum -b $(TARGET_ARCHIVE) > $@
endif

.PHONY: dist-release
dist-release: dist
gh release upload $(VERSION) $(TARGET_ARCHIVE) $(TARGET_DIGEST) --clobber

DOCKER_REPOSITORY := ghcr.io/int128/slack-docker

.PHONY: docker-build-push
docker-build-push: Dockerfile
docker buildx build . \
--build-arg=VERSION=$(VERSION) \
--tag=$(DOCKER_REPOSITORY):$(VERSION) \
--cache-from=type=registry,ref=$(DOCKER_REPOSITORY):latest \
--cache-to=type=inline \
--platform=linux/amd64,linux/arm64 \
--push

.PHONY: clean
clean:
-rm $(TARGET)
-rm -r dist/

0 comments on commit 4c57e37

Please sign in to comment.