Skip to content

Commit

Permalink
ci: add linter, update pr template, variety of cleanups (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
smsunarto authored Mar 17, 2024
1 parent f7430a0 commit 9ae350c
Show file tree
Hide file tree
Showing 43 changed files with 1,151 additions and 615 deletions.
56 changes: 35 additions & 21 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
Closes: #XXX
Closes: WORLD-XXX

## What is the purpose of the change

> Add a description of the overall background and high-level changes that this PR introduces
**_Example (remove this)_**
<!---
Add a prefix to indicate what kind of release this pull request corresponds to:
feat, fix, docs, style, refactor, perf, test, build, ci, chore, revert
--->

- _The metadata is stored in the blob store on job creation time as a persistent artifact_
- _Deployments RPC transmits only the blob storage reference_
- _Daemons retrieve the RPC data from the blob cache_
## Overview

> Description of the overall background and high-level changes that this PR introduces
<!---
Example: This pull request improves documentation of area A by adding ...
--->

## Brief Changelog

<!---
Example:
- The metadata is stored in the blob store on job creation time as a persistent artifact
- Deployments RPC transmits only the blob storage reference
- Daemons retrieve the RPC data from the blob cache
--->

## Testing and Verifying

> Please pick one of the following options
This change is a trivial rework/code cleanup without any test coverage.

**(or)**

This change is already covered by existing tests, such as _(please describe tests)_.

**(or)**

This change added tests and can be verified as follows:

<!---
Pick one of the following options:
- This change is a trivial rework/code cleanup without any test coverage.
- This change is already covered by existing tests, such as <describe test>.
- This change added tests and can be verified as follows:
- Added unit test that validates ...
- Added integration tests for end-to-end deployment with ...
- Extended integration test for ...
- Manually verified the change by ...
--->
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ on:
type: boolean

jobs:
go-build:
name: Run Go Build
build-go:
name: Go
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -51,7 +51,7 @@ jobs:
env GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -ldflags "-X main.AppVersion=$bin_version -X main.SentryDsn=$sentry_dsn -X main.PosthogApiKey=$posthog_api_key" -o $output_name ./cmd/world
echo "output_name=$output_name" >> $GITHUB_OUTPUT
- name: Compress Build Binary
- name: Compress build binary
uses: a7ul/[email protected]
id: compress
with:
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/lint-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Lint

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

permissions:
contents: read

jobs:
lint-go:
name: Go
runs-on: namespace-profile-linux-4vcpu-8gb-cached
env:
GO_VERSION: 1.22.1
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
## skip cache, use Namespace volume cache
cache: false
- name: Setup Namespace cache
uses: namespacelabs/nscloud-cache-action@v1
with:
cache: go
path: |
/home/runner/go/pkg
/home/runner/.cache/go-build
/home/runner/.cache/golangci-lint
- name: Find go path
id: go-dir
run: echo "path=$(go list -f '{{.Dir}}/...' -m | xargs)" >> $GITHUB_OUTPUT
## Equivalent to 'make lint' arguments
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.56.2
args: --timeout=10m --concurrency 8 -v ${{ steps.go-dir.outputs.path }}
## skip cache, use Namespace volume cache
skip-cache: true
17 changes: 17 additions & 0 deletions .github/workflows/lint-pr-title.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Lint

on:
pull_request:
types: [opened, synchronize, edited, reopened]

jobs:
linr-pr-title:
name: PR Title
permissions:
pull-requests: read # for amannn/action-semantic-pull-request to analyze PRs
statuses: write # for amannn/action-semantic-pull-request to mark status of analyzed PR
runs-on: ubuntu-latest
steps:
- uses: amannn/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ jobs:
secrets: inherit

release:
name: Release world-cli binary
name: Release World CLI binary
runs-on: ubuntu-latest
needs: [go-test, go-build]
strategy:
matrix:
go-version: [1.21.x]
steps:
- name: Download world-cli build binary
- name: Download World CLI build binary
uses: actions/download-artifact@v3
- name: Display downloaded files
run: |
ls -R
- name: Publish world-cli binary to corresponding Github Release
- name: Publish World CLI binary to corresponding Github Release
uses: skx/github-action-publish-binaries@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
63 changes: 25 additions & 38 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,45 @@ name: Test

on:
pull_request:
types: [opened, synchronize, edited, reopened]
push:
branches:
- main
workflow_call:

env:
GO_VERSION: 1.21.0

jobs:
go-test:
name: Run Go Test
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [1.21.x]
test-unit-coverage:
name: Unit & Coverage
runs-on: namespace-profile-linux-4vcpu-8gb-cached
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Set up Docker Build
uses: docker/setup-buildx-action@v2
- name: Install Go
uses: actions/setup-go@v4
uses: actions/checkout@v4
# Setup Docker build to use Namespace workspace builder
- name: Configure Namespace powered Buildx
uses: namespacelabs/nscloud-setup-buildx-action@v0
- name: Setup Golang
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
cache-dependency-path: "go.sum"
go-version: ${{ env.GO_VERSION }}
## skip cache, use Namespace volume cache
cache: false
- name: Init Dummy Git config for testing
run: |
git config --global user.email "[email protected]"
git config --global user.name "github-action"
- name: Test
shell: 'script -q -e -c "bash {0}"'
run: |
go test ./... -coverprofile=coverage.out -covermode=count -v
- name: Upload coverage results to Github artifact
uses: actions/upload-artifact@v3
with:
name: coverage
path: ./coverage.out

upload-codecov:
name: Upload coverage output to Codecov.io
runs-on: ubuntu-latest
needs: go-test
if: github.ref == 'refs/heads/main' || github.event_name == 'pull_request'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download coverage output file
uses: actions/download-artifact@v3
- name: Setup Namespace cache
uses: namespacelabs/nscloud-cache-action@v1
with:
name: coverage
- name: Upload coverage output to Codecov
uses: codecov/codecov-action@v3
cache: go
- name: Run unit tests with coverage
shell: 'script -q -e -c "bash {0}"'
run: make test-coverage
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
fail_ci_if_error: true
directory: "./"
directory: "./"
Loading

0 comments on commit 9ae350c

Please sign in to comment.