Skip to content

Commit

Permalink
Adding some CI. (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
gemyago authored Sep 29, 2024
1 parent 3a0402c commit e5496b5
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 20 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/push-test-artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Push Test Artifacts

on:
pull_request:
# to test this flow: add labeled or synchronize for testing and comment job condition
types: [closed]

# Target branch for the PR
branches:
- "main"

jobs:
push-test-artifacts:
if: github.event.pull_request.merged == true
name: Publish Test Artifacts
runs-on: ubuntu-latest
permissions:
contents: 'write'
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Get Test Artifacts
run: |
gh run download --dir .cover/ -n test-artifacts-pr-${{ github.event.pull_request.node_id }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- run: make push-test-artifacts
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
41 changes: 41 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Tests

on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- 'main'

jobs:
run-tests:
name: Run
runs-on: ubuntu-24.04
steps:
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version-file: 'go.mod'
cache-dependency-path: 'go.sum'

- id: golangci-version
name: Get golangci version
run: echo "value=$(cat .golangci-version)" >> $GITHUB_OUTPUT

- name: lint
uses: golangci/golangci-lint-action@v6
with:
version: '${{ steps.golangci-version.outputs.value }}'

- run: make test

- name: Store Test Artifacts
uses: actions/upload-artifact@v4
with:
name: test-artifacts-pr-${{ github.event.pull_request.node_id }}
path: |
.cover/coverage.svg
.cover/coverage.html
retention-days: 10
overwrite: true
45 changes: 44 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,47 @@ test: $(go-test-coverage) $(cover_profile)

.PHONY: docker-images
docker-images:
make -C docker clean-images .local-client-image .local-server-image
make -C docker clean-images .local-client-image .local-server-image

$(cover_dir)/coverage.%.blob-sha:
@gh api \
--method GET \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/gemyago/word-of-wisdom-go/contents/coverage/golang-coverage.$*?ref=test-artifacts \
| jq -jr '.sha' > $@

$(cover_dir)/coverage.%.gh-cli-body.json: $(cover_dir)/coverage.% $(cover_dir)/coverage.%.blob-sha
@echo "{" > $@
@echo "\"branch\": \"test-artifacts\"," >> $@
@printf "\"sha\": \"">> $@
@cat $(cover_dir)/coverage.$*.blob-sha >> $@
@printf "\",\n">> $@
@echo "\"message\": \"Updating golang coverage.$*\",">> $@
@printf "\"content\": \"">> $@
@base64 -i $< | tr -d '\n' >> $@
@printf "\"\n}">> $@


# Orphan branch will need to be created prior to running this
# git checkout --orphan test-artifacts
# git rm -rf .
# rm -f .gitignore
# echo '# Test Artifacts' > README.md
# git add README.md
# git commit -m 'init'
# git push origin test-artifacts
.PHONY: push-test-artifacts
push-test-artifacts: $(cover_dir)/coverage.svg.gh-cli-body.json $(cover_dir)/coverage.html.gh-cli-body.json
@gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/gemyago/word-of-wisdom-go/contents/coverage/golang-coverage.svg \
--input $(cover_dir)/coverage.svg.gh-cli-body.json
@gh api \
--method PUT \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
/repos/gemyago/word-of-wisdom-go/contents/coverage/golang-coverage.html \
--input $(cover_dir)/coverage.html.gh-cli-body.json
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# word-of-wisdom-go

[![Test](https://github.com/gemyago/word-of-wisdom-go/actions/workflows/run-tests.yml/badge.svg)](https://github.com/gemyago/word-of-wisdom-go/actions/workflows/run-tests.yml)
[![Coverage](https://raw.githubusercontent.com/gemyago/word-of-wisdom-go/test-artifacts/coverage/golang-coverage.svg)](https://htmlpreview.github.io/?https://raw.githubusercontent.com/gemyago/word-of-wisdom-go/test-artifacts/coverage/golang-coverage.html)

## Running Locally Via Docker

It is assumed that GNU make and docker are available
Expand Down Expand Up @@ -56,7 +59,7 @@ Nice to have, but out of scope:
- Monitoring mechanism to see if we are under attack (e.g DDOS started)
- CI/CD, Deployment pipeline e.t.c

### High level design of the system is outlined below
### High level conceptual design of the system is outlined below
<img src="./doc/wow-high-level.svg">

Each time the client will be requesting a next WoW, the server may generate the challenge, send it back to the client. Once the response is received - the server will verify the challenge and in case of success - return a valid WoW.
Expand Down
14 changes: 1 addition & 13 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,13 +1 @@
# This file is provided by @freshcutgg/ci-terraform-flow. Please avoid updating it manually.
# Please follow steps below in order to install most recent version:
# * npm i --save-dev @freshcutgg/ci-terraform-flow@latest
# * npm exec update-ci-templates

.buildx-builder
.local-registry
.local-image*
.build-image*
.deployed-image*
.cloud-run-exports-image*
tmp/
.npmrc
.local-*
5 changes: 0 additions & 5 deletions docker/docker-entrypoint.sh

This file was deleted.

0 comments on commit e5496b5

Please sign in to comment.