diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 201cd50..0000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,55 +0,0 @@ -version: 2 -jobs: - test: - docker: - - image: circleci/golang:1.16 - working_directory: ~/apitest - steps: - - checkout - - run: make test - crosscompile: - docker: - - image: circleci/golang:1.16 - working_directory: ~/apitest_cross - steps: - - checkout - - run: go get -u github.com/mitchellh/gox - - run: GOOS=windows go get -u github.com/spf13/cobra - - run: make gox - - run: cd bin/ && git tag -l 'v*' | tail -1 > version - - persist_to_workspace: - root: ~/apitest_cross - paths: - - bin/ - publish-github-release: - docker: - - image: cibuilds/github:0.10 - working_directory: ~/apitest_cross - steps: - - attach_workspace: - at: ~/apitest_cross - - run: - name: "Publish Release on GitHub" - command: | - VERSION=$(less ~/apitest_cross/bin/version) && rm ~/apitest_cross/bin/version && - ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} --replace ${VERSION} ~/apitest_cross/bin/ -workflows: - version: 2 - test: - jobs: - - test: - filters: - branches: - ignore: master - crossbuild-and-deploy: - jobs: - - test: - filters: - branches: - only: master - - crosscompile: - requires: - - test - - publish-github-release: - requires: - - crosscompile \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..561dece --- /dev/null +++ b/.github/workflows/release.yml @@ -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: "" \ No newline at end of file diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml new file mode 100644 index 0000000..4ca4582 --- /dev/null +++ b/.github/workflows/unit-tests.yml @@ -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: "" \ No newline at end of file diff --git a/Makefile b/Makefile index 057fcf4..fe207a3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +GOOS ?= linux +GOARCH ?= amd64 + all: test build deps: @@ -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 diff --git a/README.md b/README.md index c9fbaaa..66cd022 100644 --- a/README.md +++ b/README.md @@ -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)