Skip to content

Commit

Permalink
CI/CD Improvements (#45)
Browse files Browse the repository at this point in the history
* Updated Makefile & added .github/workflows

Added ci target to Makefile

Added .github/workflows/release.yml .github/workflows/unit-tests.yml
	Added ci steps to release a binary

* Updated .github/workflows

Added checkout code steps before running the tests

* Updated ci/cd

.circleci/config.yml:
	Removed circleci as ci executor

.github/workflows/release.yml:
	Improved automatic release

Makefile:
	Improved GOOS and GOARCH handling

* Updated .github/workflows/release.yml

Changed draft: true to draft: false

* Updated README.md

Changed status badges to match github-actions
  • Loading branch information
leonsteinhaeuser authored Mar 25, 2021
1 parent dc37ace commit 2c1b10c
Show file tree
Hide file tree
Showing 5 changed files with 223 additions and 56 deletions.
55 changes: 0 additions & 55 deletions .circleci/config.yml

This file was deleted.

178 changes: 178 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
name: release

on:
push:
branches:
- "production"

jobs:
unit-tests:
name: unit-tests
runs-on: ubuntu-latest
steps:
- name: run go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16

- name: Checkout code
uses: actions/checkout@v2

- name: execute unit tests
shell: bash
run: make test

- name: Notify slack channel about a failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.K8S_DEPLOYMENT_SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: k8s-deployment
SLACK_USERNAME: fylr-bot
SLACK_ICON: https://avatars.githubusercontent.com/u/1220228?s=200&v=4
SLACK_COLOR: "#ff0000"
SLACK_MESSAGE: Unit tests failed
SLACK_TITLE: Unit tests failed
SLACK_FOOTER: ""

release:
runs-on: ubuntu-latest
needs:
- unit-tests
outputs:
asset_upload_url: ${{ steps.set_url.outputs.asset_upload_url }}
version: ${{ steps.bump_version.outputs.tag_version }}
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: init bump
id: tag_version
uses: mathieudutour/github-tag-action@v5.3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
release_branches: releases

- name: bump version
id: bump_version
shell: bash
run: echo "::set-output name=tag_version::$(echo ${{ steps.tag_version.outputs.new_tag }})"

- name: create release
uses: actions/create-release@v1
id: create_release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ steps.bump_version.outputs.tag_version }}
release_name: ${{ steps.bump_version.outputs.tag_version }}
body_path: RELEASES.md
draft: false
prerelease: false

- name: set url
id: set_url
run: echo "::set-output name=asset_upload_url::${{ steps.create_release.outputs.upload_url }}"

- name: Notify slack channel about a failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.K8S_DEPLOYMENT_SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: k8s-deployment
SLACK_USERNAME: fylr-bot
SLACK_MSG_AUTHOR: fylr-bot
SLACK_ICON: https://avatars.githubusercontent.com/u/1220228?s=200&v=4
SLACK_COLOR: "#ff0000"
SLACK_MESSAGE: Automated release failed with unknown reason. Please take care of it.
SLACK_TITLE: Release ${{ needs.release.outputs.tag_version }} failed
SLACK_FOOTER: "Repository: https://github.com/$GITHUB_REPOSITORY"

upload-asset:
runs-on: ubuntu-latest
needs:
- release
strategy:
matrix:
include:
- goos: darwin
goarch: amd64
- goos: darwin
goarch: arm64

- goos: linux
goarch: 386
- goos: linux
goarch: amd64
- goos: linux
goarch: arm
- goos: linux
goarch: arm64
- goos: linux
goarch: mips
- goos: linux
goarch: mips64

- goos: windows
goarch: 386
- goos: windows
goarch: amd64
- goos: windows
goarch: arm
steps:
- name: run go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16

- name: Checkout code
uses: actions/checkout@v2

- name: build binary
shell: bash
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: make ci

- name: upload asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.release.outputs.asset_upload_url }}
asset_path: bin/apitest_${{ matrix.goos }}_${{ matrix.goarch }}
asset_name: apitest_${{ matrix.goos }}_${{ matrix.goarch }}
asset_content_type: application/octet-stream

notify-slack:
runs-on: ubuntu-latest
needs:
- release
- upload-asset
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: set body message
id: body_message
run: echo "::set-output name=slack_body_message::$(cat RELEASES.md)"

- name: set title
id: title_message
run: echo "::set-output name=slack_title_message::Released a new version ${{ needs.release.outputs.version }}"

- name: Notify slack channel about the release
if: ${{ success() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.K8S_DEPLOYMENT_SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: k8s-deployment
SLACK_USERNAME: fylr-bot
SLACK_MSG_AUTHOR: fylr-bot
SLACK_ICON: https://avatars.githubusercontent.com/u/1220228?s=200&v=4
SLACK_COLOR: "#00ff00"
SLACK_MESSAGE: ${{ steps.body_message.outputs.slack_body_message }}
SLACK_TITLE: ${{ steps.title_message.outputs.slack_title_message }}
SLACK_FOOTER: ""
37 changes: 37 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: unit-tests

on:
push:
branches:
- "**"
- "!production"

jobs:
unit-tests:
name: unit-tests
runs-on: ubuntu-latest
steps:
- name: run go 1.16
uses: actions/setup-go@v1
with:
go-version: 1.16

- name: Checkout code
uses: actions/checkout@v2

- name: execute unit tests
shell: bash
run: make test

- name: Notify slack channel about a failure
if: ${{ failure() }}
uses: rtCamp/action-slack-notify@v2
env:
SLACK_WEBHOOK: ${{ secrets.K8S_DEPLOYMENT_SLACK_WEBHOOK_URL }}
SLACK_CHANNEL: k8s-deployment
SLACK_USERNAME: fylr-bot
SLACK_ICON: https://avatars.githubusercontent.com/u/1220228?s=200&v=4
SLACK_COLOR: "#ff0000"
SLACK_MESSAGE: Unit tests failed
SLACK_TITLE: Unit tests failed
SLACK_FOOTER: ""
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
GOOS ?= linux
GOARCH ?= amd64

all: test build

deps:
Expand Down Expand Up @@ -27,6 +30,9 @@ gox: deps
clean:
rm -rfv ./apitest ./bin/* ./testcoverage.out

ci: deps
go build -o bin/apitest_$(GOOS)_$(GOARCH) *.go

build: deps
go build

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# apitest

[![CircleCI](https://circleci.com/gh/programmfabrik/apitest.svg?style=svg)](https://circleci.com/gh/programmfabrik/apitest)
[![release](https://github.com/programmfabrik/apitest/actions/workflows/release.yml/badge.svg?branch=production)](https://github.com/programmfabrik/apitest/actions/workflows/release.yml)
[![unit-tests](https://github.com/programmfabrik/apitest/actions/workflows/unit-tests.yml/badge.svg)](https://github.com/programmfabrik/apitest/actions/workflows/unit-tests.yml)
[![Twitter](https://img.shields.io/twitter/follow/programmfabrik.svg?label=Follow&style=social)](https://twitter.com/programmfabrik)
[![GoReportCard](https://goreportcard.com/badge/github.com/programmfabrik/apitest)](https://goreportcard.com/report/github.com/programmfabrik/apitest)

Expand Down

0 comments on commit 2c1b10c

Please sign in to comment.