Skip to content

Commit

Permalink
Add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ww24 committed Jan 26, 2020
1 parent 848ebff commit ea3858a
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 0 deletions.
65 changes: 65 additions & 0 deletions .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test for PR

on: pull_request

env:
IMAGE_NAME: worker
IMAGE_TAG: latest

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with:
go-version: "1.13"
- name: setup env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
shell: bash
- name: Install go tools
run: cat tools.go | grep _ | awk -F '"' '{print $2}' | xargs -tI {} go install {}
- name: go generate
run: go generate ./...
- name: Check uncommitted changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "uncommitted changes"
git status
exit 1
fi
- name: go lint
run: go list ./... | xargs golint -set_exit_status
- run: go vet ./...
- run: go test -v -race ./...

docker:
name: Build docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Shellcheck
env:
SHELLCHECK_OPTS: -e SC2187
run: find . -name "*.sh" | xargs shellcheck
- name: Lint
run: |
docker run -v $(pwd):/working --rm hadolint/hadolint \
hadolint /working/Dockerfile \
--ignore DL3018
- name: Build docker image
run: docker build -t "docker.pkg.github.com/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${IMAGE_TAG}" .
- name: Install trivy
run: |
sudo apt-get install --no-install-recommends apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install --no-install-recommends trivy
- name: Vulnerability Scan
run: |
trivy -q --severity HIGH,CRITICAL --exit-code 1 \
"docker.pkg.github.com/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${IMAGE_TAG}"
73 changes: 73 additions & 0 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Test on master

on:
push:
branches:
- master

env:
IMAGE_NAME: worker
IMAGE_TAG: latest

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with:
go-version: "1.13"
- name: setup env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
shell: bash
- name: Install go tools
run: cat tools.go | grep _ | awk -F '"' '{print $2}' | xargs -tI {} go install {}
- name: go generate
run: go generate ./...
- name: Check uncommitted changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "uncommitted changes"
git status
exit 1
fi
- name: go lint
run: go list ./... | xargs golint -set_exit_status
- run: go vet ./...
- run: go test -v -race ./...

docker:
needs: test
name: Build and push docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Shellcheck
env:
SHELLCHECK_OPTS: -e SC2187
run: find . -name "*.sh" | xargs shellcheck
- name: Lint
run: |
docker run -v $(pwd):/working --rm hadolint/hadolint \
hadolint /working/Dockerfile \
--ignore DL3018
- name: Build docker image
run: docker build -t "docker.pkg.github.com/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${IMAGE_TAG}" .
- name: Install trivy
run: |
sudo apt-get install --no-install-recommends apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install --no-install-recommends trivy
- name: Vulnerability Scan
run: |
trivy -q --severity HIGH,CRITICAL --exit-code 1 \
"docker.pkg.github.com/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${IMAGE_TAG}"
- name: Push docker image
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u owner --password-stdin docker.pkg.github.com
docker push "docker.pkg.github.com/${GITHUB_REPOSITORY}/worker:${IMAGE_TAG}"
79 changes: 79 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Release

on:
push:
tags:
- v[0-9]+.[0-9]+.[0-9]+

env:
IMAGE_NAME: worker

jobs:
test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-go@v1
with:
go-version: "1.13"
- name: setup env
run: |
echo "::set-env name=GOPATH::$(go env GOPATH)"
echo "::add-path::$(go env GOPATH)/bin"
shell: bash
- name: Install go tools
run: cat tools.go | grep _ | awk -F '"' '{print $2}' | xargs -tI {} go install {}
- name: go generate
run: go generate ./...
- name: Check uncommitted changes
run: |
if [ -n "$(git status --porcelain)" ]; then
echo "uncommitted changes"
git status
exit 1
fi
- name: go lint
run: go list ./... | xargs golint -set_exit_status
- run: go vet ./...
- run: go test -v -race ./...

docker:
needs: test
name: Build and push docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set image tag
run: |
tag=$(echo "${GITHUB_REF}" | sed "s/^refs\/tags\/v//")
if [ -z "$tag" ]; then
exit 1
fi
echo "::set-env name=IMAGE_TAG::$tag"
- name: Shellcheck
env:
SHELLCHECK_OPTS: -e SC2187
run: find . -name "*.sh" | xargs shellcheck
- name: Lint
run: |
docker run -v $(pwd):/working --rm hadolint/hadolint \
hadolint /working/Dockerfile \
--ignore DL3018
- name: Build docker image
run: docker build -t "docker.pkg.github.com/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${IMAGE_TAG}" .
- name: Install trivy
run: |
sudo apt-get install --no-install-recommends apt-transport-https gnupg lsb-release
wget -qO - https://aquasecurity.github.io/trivy-repo/deb/public.key | sudo apt-key add -
echo deb https://aquasecurity.github.io/trivy-repo/deb $(lsb_release -sc) main | sudo tee -a /etc/apt/sources.list.d/trivy.list
sudo apt-get update
sudo apt-get install --no-install-recommends trivy
- name: Vulnerability Scan
run: |
trivy -q --severity HIGH,CRITICAL --exit-code 1 \
"docker.pkg.github.com/${GITHUB_REPOSITORY}/${IMAGE_NAME}:${IMAGE_TAG}"
- name: Push docker image
run: |
echo "${{ secrets.GITHUB_TOKEN }}" | docker login -u owner --password-stdin docker.pkg.github.com
docker push "docker.pkg.github.com/${GITHUB_REPOSITORY}/worker:${IMAGE_TAG}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.*
!.github
!.gitignore
!.dockerignore

Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
calendar-worker
===

![](https://github.com/ww24/calendar-worker/workflows/Test%20on%20master/badge.svg)

Calendar Worker is Google Calendar event handler and actions.

## Features
Expand Down Expand Up @@ -29,6 +31,7 @@ Calendar Worker is Google Calendar event handler and actions.
## Usage

### For the docker-compose

- Run `docker-compose up`

### For the docker
Expand Down
1 change: 1 addition & 0 deletions tools.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
package calendar

import (
_ "golang.org/x/lint/golint"
_ "golang.org/x/tools/cmd/stringer"
)

0 comments on commit ea3858a

Please sign in to comment.