Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Iss 86 #98

Merged
merged 14 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions .github/workflows/check/Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/check/action.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/check/entrypoint.sh

This file was deleted.

7 changes: 0 additions & 7 deletions .github/workflows/integration/Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions .github/workflows/integration/action.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .github/workflows/integration/entrypoint.sh

This file was deleted.

37 changes: 34 additions & 3 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,40 @@ name: push
on: push

jobs:
ci:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/workflows/check
#- uses: ./.github/workflows/integration
- uses: docker://golangci/golangci-lint:v1.23.6
with:
args: golangci-lint run
env:
CGO_ENABLED: 0

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: 1.13
- run: go test -cover ./...
env:
CGO_ENABLED: 0
GOFLAGS: -mod=vendor

release:
if: startsWith(github.ref, 'refs/tags/v')
needs:
- lint
- test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GORELEASER_GITHUB_TOKEN }}
20 changes: 0 additions & 20 deletions .github/workflows/tag.yml

This file was deleted.

39 changes: 15 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
LATEST_VERSION := $(shell git tag -l --sort=creatordate | grep "^v[0-9]*.[0-9]*.[0-9]*$$" | tail -1 | cut -c 2-)
ifeq "$(shell git tag -l v$(LATEST_VERSION) --points-at HEAD)" "v$(LATEST_VERSION)"
### latest tag points to current commit, this is a release build
VERSION ?= $(LATEST_VERSION)
else
### latest tag points to prior commit, this is a snapshot build
MAJOR_VERSION := $(word 1, $(subst ., ,$(LATEST_VERSION)))
MINOR_VERSION := $(word 2, $(subst ., ,$(LATEST_VERSION)))
PATCH_VERSION := $(word 3, $(subst ., ,$(LATEST_VERSION)))
VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION).$(shell echo $$(( $(PATCH_VERSION) + 1)) )-develop
endif
VERSION?=$(shell git describe --tags --dirty | cut -c 2-)
IS_SNAPSHOT = $(if $(findstring -, $(VERSION)),true,false)
TAG_VERSION = v$(VERSION)
MAJOR_VERSION = $(word 1, $(subst ., ,$(VERSION)))
MINOR_VERSION = $(word 2, $(subst ., ,$(VERSION)))
PATCH_VERSION = $(word 3, $(subst ., ,$(word 1,$(subst -, , $(VERSION)))))
NEW_VERSION ?= $(MAJOR_VERSION).$(MINOR_VERSION).$(shell echo $$(( $(PATCH_VERSION) + 1)) )

ACT ?= go run -mod=vendor main.go
ACT ?= go run main.go
export GITHUB_TOKEN = $(shell cat ~/.config/github/token)

check:
@golangci-lint run
@go test -cover ./...
build:
go build -ldflags "-X main.version=$(VERSION)" -o dist/local/act main.go

build: check
$(eval export SNAPSHOT_VERSION=$(VERSION))
$(ACT) -ra build
test:
$(ACT) -P ubuntu-latest=nektos/act-environments-ubuntu:18.04

install: build
@cp dist/$(shell go env GOOS)_$(shell go env GOARCH)/act /usr/local/bin/act
@cp dist/local/act /usr/local/bin/act
@chmod 755 /usr/local/bin/act
@act --version

Expand All @@ -33,7 +24,8 @@ installer:
godownloader -r nektos/act -o install.sh

promote: vendor
@echo "VERSION:$(VERSION) IS_SNAPSHOT:$(IS_SNAPSHOT) LATEST_VERSION:$(LATEST_VERSION)"
@git fetch --tags
@echo "VERSION:$(VERSION) IS_SNAPSHOT:$(IS_SNAPSHOT) NEW_VERSION:$(NEW_VERSION)"
ifeq (false,$(IS_SNAPSHOT))
@echo "Unable to promote a non-snapshot"
@exit 1
Expand All @@ -42,9 +34,8 @@ ifneq ($(shell git status -s),)
@echo "Unable to promote a dirty workspace"
@exit 1
endif
$(eval NEW_VERSION := $(word 1,$(subst -, , $(TAG_VERSION))))
git tag -a -m "releasing $(NEW_VERSION)" $(NEW_VERSION)
git push origin $(NEW_VERSION)
git tag -a -m "releasing v$(NEW_VERSION)" v$(NEW_VERSION)
git push origin v$(NEW_VERSION)

vendor:
go mod vendor
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ GitHub Actions offers managed [virtual environments](https://help.github.com/en/

| GitHub Runner | Docker Image |
| --------------- | ------------ |
| ubuntu-latest | [ubuntu:18.04](https://hub.docker.com/_/ubuntu) |
| ubuntu-18.04 | [ubuntu:18.04](https://hub.docker.com/_/ubuntu) |
| ubuntu-16.04 | [ubuntu:16.04](https://hub.docker.com/_/ubuntu) |
| ubuntu-latest | [node:12.6-buster-slim](https://hub.docker.com/_/buildpack-deps) |
| ubuntu-18.04 | [node:12.6-buster-slim](https://hub.docker.com/_/buildpack-deps) |
| ubuntu-16.04 | [node:12.6-stretch-slim](https://hub.docker.com/_/buildpack-deps) |
| windows-latest | `unsupported` |
| windows-2019 | `unsupported` |
| macos-latest | `unsupported` |
Expand Down
1 change: 1 addition & 0 deletions cmd/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Input struct {
workflowsPath string
eventPath string
reuseContainers bool
bindWorkdir bool
secrets []string
platforms []string
dryrun bool
Expand Down
6 changes: 3 additions & 3 deletions cmd/platforms.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

func (i *Input) newPlatforms() map[string]string {
platforms := map[string]string{
"ubuntu-latest": "ubuntu:18.04",
"ubuntu-18.04": "ubuntu:18.04",
"ubuntu-16.04": "ubuntu:16.04",
"ubuntu-latest": "node:12.6-buster-slim",
"ubuntu-18.04": "node:12.6-buster-slim",
"ubuntu-16.04": "node:12.6-stretch-slim",
"windows-latest": "",
"windows-2019": "",
"macos-latest": "",
Expand Down
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Execute(ctx context.Context, version string) {
rootCmd.Flags().StringArrayVarP(&input.secrets, "secret", "s", []string{}, "secret to make available to actions with optional value (e.g. -s mysecret=foo or -s mysecret)")
rootCmd.Flags().StringArrayVarP(&input.platforms, "platform", "P", []string{}, "custom image to use per platform (e.g. -P ubuntu-18.04=nektos/act-environments-ubuntu:18.04)")
rootCmd.Flags().BoolVarP(&input.reuseContainers, "reuse", "r", false, "reuse action containers to maintain state")
rootCmd.Flags().BoolVarP(&input.bindWorkdir, "bind", "b", false, "bind working directory to container, rather than copy")
rootCmd.Flags().BoolVarP(&input.forcePull, "pull", "p", false, "pull docker image(s) if already present")
rootCmd.Flags().StringVarP(&input.eventPath, "eventpath", "e", "", "path to event JSON file")
rootCmd.PersistentFlags().StringVarP(&input.workflowsPath, "workflows", "W", "./.github/workflows/", "path to workflow files")
Expand Down Expand Up @@ -97,6 +98,7 @@ func newRunCommand(ctx context.Context, input *Input) func(*cobra.Command, []str
ForcePull: input.forcePull,
ReuseContainers: input.reuseContainers,
Workdir: input.Workdir(),
BindWorkdir: input.bindWorkdir,
LogOutput: !input.noOutput,
Secrets: newSecrets(input.secrets),
Platforms: input.newPlatforms(),
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ github.com/docker/distribution v2.7.1+incompatible h1:a5mlkVzth6W5A4fOsS3D2EO5BU
github.com/docker/distribution v2.7.1+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/engine v0.0.0-20181106193140-f5749085e9cb h1:PyjxRdW1mqCmSoxy/6uP01P7CGbsD+woX+oOWbaUPwQ=
github.com/docker/engine v0.0.0-20181106193140-f5749085e9cb/go.mod h1:3CPr2caMgTHxxIAZgEMd3uLYPDlRvPqCpyeRf6ncPcY=
github.com/docker/engine v1.13.1 h1:Cks33UT9YBW5Xyc3MtGDq2IPgqfJtJ+qkFaxc2b0Euc=
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
github.com/docker/go-connections v0.4.0/go.mod h1:Gbd7IOopHjR8Iph03tsViu4nIes5XhDvyHbTtUxmeec=
github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk=
Expand Down
9 changes: 9 additions & 0 deletions pkg/common/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ func NewInfoExecutor(format string, args ...interface{}) Executor {
}
}

// NewDebugExecutor is an executor that logs messages
func NewDebugExecutor(format string, args ...interface{}) Executor {
return func(ctx context.Context) error {
logger := Logger(ctx)
logger.Debugf(format, args...)
return nil
}
}

// NewPipelineExecutor creates a new executor from a series of other executors
func NewPipelineExecutor(executors ...Executor) Executor {
if len(executors) == 0 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func NewGitCloneExecutor(input NewGitCloneExecutorInput) Executor {
Force: true,
})
if err != nil {
logger.Errorf("Unable to checkout %s: %v", refName, err)
logger.Errorf("Unable to checkout %s: %v", *hash, err)
return err
}

Expand Down
7 changes: 5 additions & 2 deletions pkg/common/line_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

// LineHandler is a callback function for handling a line
type LineHandler func(line string)
type LineHandler func(line string) bool

type lineWriter struct {
buffer bytes.Buffer
Expand Down Expand Up @@ -42,6 +42,9 @@ func (lw *lineWriter) Write(p []byte) (n int, err error) {

func (lw *lineWriter) handleLine(line string) {
for _, h := range lw.handlers {
h(line)
ok := h(line)
if !ok {
break
}
}
}
3 changes: 2 additions & 1 deletion pkg/common/line_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (

func TestLineWriter(t *testing.T) {
lines := make([]string, 0)
lineHandler := func(s string) {
lineHandler := func(s string) bool {
lines = append(lines, s)
return true
}

lineWriter := NewLineWriter(lineHandler)
Expand Down
2 changes: 1 addition & 1 deletion pkg/container/docker_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type NewDockerPullExecutorInput struct {
func NewDockerPullExecutor(input NewDockerPullExecutorInput) common.Executor {
return func(ctx context.Context) error {
logger := common.Logger(ctx)
logger.Infof("%sdocker pull %v", logPrefix, input.Image)
logger.Debugf("%sdocker pull %v", logPrefix, input.Image)

if common.Dryrun(ctx) {
return nil
Expand Down
Loading