-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate to GitHub Actions and GHCR (#26)
- Loading branch information
Showing
4 changed files
with
162 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |