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

Support GA of GitHub Actions #84

Merged
merged 24 commits into from
Feb 18, 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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 0 additions & 14 deletions .github/actions/check/Dockerfile

This file was deleted.

12 changes: 0 additions & 12 deletions .github/actions/integration/Dockerfile

This file was deleted.

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

This file was deleted.

48 changes: 0 additions & 48 deletions .github/main.workflow

This file was deleted.

9 changes: 9 additions & 0 deletions .github/workflows/check/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM golangci/golangci-lint:v1.23.6

RUN apt-get install git

COPY "entrypoint.sh" "/entrypoint.sh"
RUN chmod +x /entrypoint.sh

ENV GOFLAGS -mod=vendor
ENTRYPOINT ["/entrypoint.sh"]
8 changes: 8 additions & 0 deletions .github/workflows/check/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Check
description: Run static analysis and unit tests
branding:
icon: check-circle
color: green
runs:
using: 'docker'
image: 'Dockerfile'
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
set -e
golangci-lint run
go test -cover -short ./...
go test -cover -short ./...
7 changes: 7 additions & 0 deletions .github/workflows/integration/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM golangci/golangci-lint:v1.23.6

COPY "entrypoint.sh" "/entrypoint.sh"
RUN chmod +x /entrypoint.sh

ENV GOFLAGS -mod=vendor
ENTRYPOINT ["/entrypoint.sh"]
8 changes: 8 additions & 0 deletions .github/workflows/integration/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Check
description: Run integration tests
branding:
icon: check-circle
color: green
runs:
using: 'docker'
image: 'Dockerfile'
3 changes: 3 additions & 0 deletions .github/workflows/integration/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
set -e
go test -cover ./pkg/runner
10 changes: 10 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: push
on: push

jobs:
ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/workflows/check
#- uses: ./.github/workflows/integration
21 changes: 21 additions & 0 deletions .github/workflows/tag.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: tag
on:
push:
tags:
- 'v*'

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./.github/workflows/check
- uses: ./.github/workflows/integration
- uses: goreleaser/goreleaser-action@v1
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v1
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
linters-settings:
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
min-complexity: 15
gocritic:
disabled-checks:
- ifElseChain
Expand All @@ -18,4 +18,4 @@ linters:
- nakedret
- prealloc
- scopelint
- gocritic
- gocritic
13 changes: 3 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,14 @@ TAG_VERSION = v$(VERSION)
ACT ?= go run -mod=vendor main.go
export GITHUB_TOKEN = $(shell cat ~/.config/github/token)

default: check

test:
go test -cover -short ./...

check:
$(ACT) -ra check
@golangci-lint run
@go test -cover ./...

build: check
$(eval export SNAPSHOT_VERSION=$(VERSION))
$(ACT) -ra build

release:
$(ACT) -ra local-release

install: build
@cp dist/$(shell go env GOOS)_$(shell go env GOARCH)/act /usr/local/bin/act
@chmod 755 /usr/local/bin/act
Expand All @@ -56,4 +49,4 @@ endif
vendor:
go mod vendor

.PHONY: vendor
.PHONY: vendor
40 changes: 10 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
![](https://github.com/nektos/act/wiki/img/logo-150.png)
# Overview [![Join the chat at https://gitter.im/nektos/act](https://badges.gitter.im/nektos/act.svg)](https://gitter.im/nektos/act?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Go Report Card](https://goreportcard.com/badge/github.com/nektos/act)](https://goreportcard.com/report/github.com/nektos/act)
# Overview [![push](https://github.com/nektos/act/workflows/push/badge.svg?branch=master&event=push)](https://github.com/nektos/act/actions) [![Join the chat at https://gitter.im/nektos/act](https://badges.gitter.im/nektos/act.svg)](https://gitter.im/nektos/act?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Go Report Card](https://goreportcard.com/badge/github.com/nektos/act)](https://goreportcard.com/report/github.com/nektos/act)

> "Think globally, <code>act</code> locally"

__Currently this library only supports the HCL syntax, not the YAML syntax__
> "Think globally, <code>act</code> locally"

Run your [GitHub Actions](https://developer.github.com/actions/) locally! Why would you want to do this? Two reasons:

* **Fast Feedback** - Rather than having to commit/push every time you want test out the changes you are making to your `main.workflow` file (or for any changes to embedded GitHub actions), you can use `act` to run the actions locally. The [environment variables](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables) and [filesystem](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#filesystem) are all configured to match what GitHub provides.
* **Local Task Runner** - I love [make](https://en.wikipedia.org/wiki/Make_(software)). However, I also hate repeating myself. With `act`, you can use the GitHub Actions defined in your `main.workflow` file to replace your `Makefile`!
* **Fast Feedback** - Rather than having to commit/push every time you want test out the changes you are making to your `.github/workflows/` files (or for any changes to embedded GitHub actions), you can use `act` to run the actions locally. The [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) and [filesystem](https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners) are all configured to match what GitHub provides.
* **Local Task Runner** - I love [make](https://en.wikipedia.org/wiki/Make_(software)). However, I also hate repeating myself. With `act`, you can use the GitHub Actions defined in your `.github/workflows/` to replace your `Makefile`!

# How Does It Work?
When you run `act` it reads in your GitHub Actions from `.github/main.workflow` and determines the set of actions that need to be run. It uses the Docker API to either pull or build the necessary images, as defined in your `main.workflow` file and finally determines the execution path based on the dependencies that were defined. Once it has the execution path, it then uses the Docker API to run containers for each action based on the images prepared earlier. The [environment variables](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables) and [filesystem](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#filesystem) are all configured to match what GitHub provides.
When you run `act` it reads in your GitHub Actions from `.github/workflows/` and determines the set of actions that need to be run. It uses the Docker API to either pull or build the necessary images, as defined in your workflow files and finally determines the execution path based on the dependencies that were defined. Once it has the execution path, it then uses the Docker API to run containers for each action based on the images prepared earlier. The [environment variables](https://help.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables) and [filesystem](https://help.github.com/en/actions/reference/virtual-environments-for-github-hosted-runners#filesystems-on-github-hosted-runners) are all configured to match what GitHub provides.

Let's see it in action with a [sample repo](https://github.com/cplee/github-actions-demo)!

Expand Down Expand Up @@ -42,8 +41,8 @@ act
# Run a specific event:
act pull_request

# Run a specific action:
act -a test
# Run a specific job:
act -j test

# Run in dry-run mode:
act -n
Expand All @@ -57,29 +56,10 @@ act -v

# Secrets

To run `act` with secrets, you can enter them interactively or supply them as environment variables.
If you have a secret called `FOO` in your `main.workflow`, `act` will take whatever you have set as `FOO` in the session from which you are running `act`.
If `FOO` is unset, it will ask you interactively.

You can set environment variables for the current session by running `export FOO="zap"`, or globally in your `.profile`.
You can also set environment variables *per directory* using a tool such as [direnv](https://direnv.net/).
**Be careful not to expose secrets**:
You may want to `.gitignore` any files or folders containing secrets, and/or encrypt secrets.

# Skip Actions When Run in `act`

You may sometimes want to skip some actions when you're running a `main.workflow` in act, such as deployment.
You can achieve something similar by using a [filter](https://github.com/actions/bin/tree/master/filter) action, filtering on all [`GITHUB_ACTOR`](https://developer.github.com/actions/creating-github-actions/accessing-the-runtime-environment/#environment-variables)s *except* `nektos/act`, which is the `GITHUB_ACTOR` set by `act`.

```
action "Filter Not Act" {
uses = "actions/bin/filter@3c0b4f0e63ea54ea5df2914b4fabf383368cd0da"
args = "not actor nektos/act"
}
```
To run `act` with secrets, you can enter them interactively or supply them as environment variables. The following options are available for providing secrets:

Just remember that GitHub actions will cancel all upcoming and concurrent actions on a neutral exit code.
To avoid prematurely cancelling actions, place this filter at the latest possible point in the build graph.
* `act -s MY_SECRET=somevalue` - use `somevalue` as the value for `MY_SECRET`.
* `act -s MY_SECRET` - check for an environment variable named `MY_SECRET` and use it if it exists. If environment variable is not defined, prompt the user for a value.

# Support

Expand Down
47 changes: 0 additions & 47 deletions actions/action.go

This file was deleted.

51 changes: 0 additions & 51 deletions actions/api.go

This file was deleted.

Loading