Skip to content

Commit

Permalink
CI for Testing and Publishing Exporter CLI / Image (#9)
Browse files Browse the repository at this point in the history
* CI for Testing and Publishing Exporter CLI / Image

* fixing workflow

* testing cli via docker run
  • Loading branch information
onelapahead authored Jan 19, 2021
1 parent c9d6674 commit 3104c92
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 3 deletions.
100 changes: 100 additions & 0 deletions .github/workflows/exporter-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
name: "Ethminer Metrics Exporter"
on:
pull_request:
branches:
- '**'
paths:
- 'ethminer-exporter/*'
- 'ethminer-exporter/**/*'
- .github/workflows/exporter-build.yml
push:
branches:
- main
paths:
- 'ethminer-exporter/*'
- 'ethminer-exporter/**/*'
- .github/workflows/exporter-build.yml
jobs:
ci:
runs-on: ubuntu-18.04
name: CI
steps:
- name: git checkout
uses: actions/checkout@v2

- name: extract versions
id: versions
run: |
version=$(cat VERSION)
echo "::set-output name=git-tag::ethminer-exporter-v${version}"
echo "::set-output name=version::v${version}"
echo "::set-output name=dirty-version::v${version}-$(git rev-parse --short HEAD)"
working-directory: ethminer-exporter

- name: docker login
uses: azure/docker-login@v1
with:
login-server: ghcr.io
username: hfuss
password: ${{ secrets.PACKAGES_TOKEN }}

- name: test
run: |
make test
fmt=$(go fmt ./.../ | wc -l)
[[ "$fmt" -eq "0" ]]
working-directory: ethminer-exporter

- name: build
run: |
docker build . -f build/Dockerfile -t ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.dirty-version }}
docker run -i ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.dirty-version }} client --help
docker push ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.dirty-version }}
working-directory: ethminer-exporter

- name: enforce new version
run: |
git ls-remote --exit-code origin --tags '${{ steps.versions.outputs.git-tag }}' && found=true
if [[ "${found}" == "true" ]]; then
echo "${{ steps.versions.outputs.git-tag }} tag already exists, please update the version and changelog"
exit 1
fi
- name: enforce changelog
if: ${{ github.event_name == 'pull_request' }}
uses: dangoslen/changelog-enforcer@v2
with:
changeLogPath: 'ethminer-exporter/CHANGELOG.md'
skipLabels: 'Skip-Changelog'
expectedLatestVersion: ${{ steps.versions.outputs.version }}

- name: extract changelog
id: changelog
uses: mindsers/changelog-reader-action@v2
with:
validation_depth: 10
version: ${{ steps.versions.outputs.version }}
path: ethminer-exporter/CHANGELOG.md

- name: tag images
run: |
docker tag ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.dirty-version }} ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.version }}
docker tag ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.dirty-version }} ghcr.io/hfuss/ethminer-exporter:latest
- name: promote images
if: ${{ github.event_name == 'push' }}
run: |
docker push ghcr.io/hfuss/ethminer-exporter:${{ steps.versions.outputs.version }}
docker push ghcr.io/hfuss/ethminer-exporter:latest
- name: git release
uses: actions/create-release@v1
if: ${{ github.event_name == 'push' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{ steps.versions.outputs.git-tag }}
release_name: Ethminer Metrics Exporter ${{ steps.versions.outputs.version }} Release
body: ${{ steps.changelog.outputs.changes }}
draft: false
prerelease: false
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@

# Dependency directories (remove the comment below to include it)
# vendor/

**/build/_output/
28 changes: 28 additions & 0 deletions ethminer-exporter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# CHANGELOG

Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)

## Unreleased
### Added
- ...

### Changed
- ...

### Removed
- ...

### Dependencies
- ...

## [v0.1.0]
### Changed
- `ApiClient` for interacting with the Ethminer JSON RPC 2.0 API
- `MockServer` for mocking the Ethminer JSON RPC 2.0 API
- CLI utility for testing client and mock API server

### Dependencies
- All dependencies are vendored
- Retry library `github.com/avast/retry-go@v3.0.0`
- CLI library and generator `github.com/spf13/cobra@v1.1.1`
- JSON RPC 2.0 client and server library `github.com/sourcegraph/jsonrpc2@v0.0.0`
21 changes: 21 additions & 0 deletions ethminer-exporter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
.PHONY: build docker-build test clean all fmt

all: build docker-build

fmt:
go fmt ./.../

test:
go test -cover -count=1 -v ./.../

build/_output/bin/ethxporter:
mkdir -p build/_output/bin/
go build -a -tags netgo -mod=vendor -o build/_output/bin/ethxporter main.go

build: build/_output/bin/ethxporter

docker-build:
docker build . -f build/Dockerfile -t ethxporter

clean:
rm -r build/_output/bin/ethxporter
5 changes: 3 additions & 2 deletions ethminer-exporter/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ package cmd

import (
"fmt"
"github.com/spf13/cobra"
"os"

"github.com/spf13/cobra"

homedir "github.com/mitchellh/go-homedir"
"github.com/spf13/viper"
)
Expand All @@ -28,7 +29,7 @@ var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "ethminer-exporter",
Use: "ethxporter",
Short: "A brief description of your application",
Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:
Expand Down
Binary file removed ethminer-exporter/ethxporter
Binary file not shown.
2 changes: 1 addition & 1 deletion miner/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Changed
- Enabling API server

### Dependecies
### Dependencies
- Bump `https://github.com/ethereum-mining/ethminer` to `v0.19.0`

## [v0.1.0]
Expand Down

0 comments on commit 3104c92

Please sign in to comment.