Skip to content

Commit

Permalink
feat(ci): add GH actions release pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
arvdias committed Nov 23, 2020
1 parent f597f3d commit ab7d3cb
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 12 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: Release
on:
release:
types:
# works for building pre-releases
- published
# works for releases and changing from pre-release to release
- released

env:

DOCKER_IMAGE: newrelic/nri-kube-events
RELEASE_VERSION: ${{ github.event.release.tag_name }}
S3_PATH: s3://nr-downloads-main/infrastructure_agent

jobs:
publish:
name: Publish
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Extract version from release tag
run: |
RELEASE_VERSION=$(echo $RELEASE_VERSION | grep -oE '([0-9.]*[0-9])$')
echo "RELEASE_VERSION=$RELEASE_VERSION">> $GITHUB_ENV
- name: Test for prerelase
if: ${{ github.event.release.prerelease }}
run: |
echo "RELEASE_VERSION=$RELEASE_VERSION-pre" >> $GITHUB_ENV
echo "S3_PATH=$S3_PATH/test" >> $GITHUB_ENV
# - name: Login to DockerHub
# uses: docker/login-action@v1
# with:
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push
env:
PRERELEASE: ${{ github.event.release.prerelease }}
DOCKER_IMAGE_NAME: ${{ env.DOCKER_IMAGE }}:${{ env.RELEASE_VERSION }}
run: |
make docker-build
echo "docker push $DOCKER_IMAGE_NAME"
# push 'latest' if NOT pre-release
if [[ -z "$PRERELEASE" || "false" == "$PRERELEASE" ]]; then
docker tag $DOCKER_IMAGE_NAME $DOCKER_IMAGE:latest
echo "docker push $DOCKER_IMAGE:latest"
fi
- uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Upload manifest to S3
run: |
aws s3 cp deploy/nri-kube-events.yaml $S3_PATH/integrations/kubernetes/nri-kube-events-${{ env.RELEASE_VERSION }}.yaml"
aws s3 cp deploy/nri-kube-events.yaml $S3_PATH/integrations/kubernetes/nri-kube-events-latest.yaml"
File renamed without changes.
12 changes: 6 additions & 6 deletions .github/workflows/test.yml → .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name: lint and test code
name: Lint and test code
on:
push:
tags:
- v*
branches:
- master
pull_request:
jobs:
test:
name: test
lint-test:
name: lint and test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install Go
uses: actions/setup-go@v2
with:
go-version: '^1.14.4'
- name: Run unit tests
- name: Lint
run: make
- name: Test
run: make test
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ NATIVEARCH := $(shell go version | awk -F '[ /]' '{print $$5}')
TOOLS_DIR := ./bin/dev-tools
INTEGRATION = nri-kube-events
GOLANGCILINT_VERSION = 1.17.1
IMAGE_NAME = newrelic/nri-kube-events
DOCKER_IMAGE_NAME ?= newrelic/nri-kube-events
BUILD_TARGET ?= bin/$(INTEGRATION)

all: build
Expand Down Expand Up @@ -40,18 +40,18 @@ test:
@go test -race ./...

docker-test:
@docker build . --target base-env -t $(IMAGE_NAME)_test
@docker build . --target base-env -t $(DOCKER_IMAGE_NAME)_test
@echo "=== $(INTEGRATION) === [ docker-test ]: Running unit tests in Docker..."
@docker run -t $(IMAGE_NAME)_test make test
@docker run -t $(DOCKER_IMAGE_NAME)_test make test

docker-lint:
@docker build . --target base-env -t $(IMAGE_NAME)_lint
@docker build . --target base-env -t $(DOCKER_IMAGE_NAME)_lint
@echo "=== $(INTEGRATION) === [ docker-lint ]: Validating source code running golangci-lint in Docker..."
@docker run -t $(IMAGE_NAME)_lint make lint
@docker run -t $(DOCKER_IMAGE_NAME)_lint make lint

docker-build:
@echo "=== $(INTEGRATION) === [ docker-build ]: Building final Docker image..."
@docker build . --target final -t $(IMAGE_NAME)
@docker build . --target final -t $(DOCKER_IMAGE_NAME)

docker-lint/dockerfile:
@echo "=== $(INTEGRATION) === [ docker-lint ]: Linting Docker image..."
Expand Down

0 comments on commit ab7d3cb

Please sign in to comment.