Skip to content

Commit

Permalink
fix: updated dependencies
Browse files Browse the repository at this point in the history
* test: added test for health check

* test: created db helper function

* docs: fixed license headers

* test: added CI test step

* ci: added setup go-v5

* test: fixed test condition

* fix: updated dependencies

* chore: added test coverage

* ci: updated action versions

* ci: updated badge step

* ci: updated badge action

* ci: more ci testing

* ci: with app

* ci: option 1

* ci: more ci test

* ci: more test

* chore: Updated coverage badge.

* ci: working logic

* ci: ready for merge

---------

Co-authored-by: GitHub Action <[email protected]>
  • Loading branch information
karl-cardenas-coding and actions-user authored Feb 23, 2024
1 parent 4d3aea0 commit 5d35b4b
Show file tree
Hide file tree
Showing 23 changed files with 874 additions and 103 deletions.
15 changes: 15 additions & 0 deletions .copywrite.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
schema_version = 1

project {
copyright_holder = "Spectro Cloud"
license = "MPL-2.0"
copyright_year = 2024

# (OPTIONAL) A list of globs that should not have copyright/license headers.
# Supports doublestar glob patterns for more flexibility in defining which
# files or folders should be ignored
header_ignore = [
# "vendors/**",
# "**autogen**",
]
}
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup Nodejs
uses: actions/setup-node@v3
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
steps:
- id: checkout
name: Checkout Repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Retrieve Credentials
id: import-secrets
Expand Down
129 changes: 94 additions & 35 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Pull Request

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

env:
DB_VERSION: 1.0.0
Expand All @@ -21,58 +21,117 @@ jobs:
shell: bash
if: ${{ !github.event.pull_request.draft }}
steps:
# If the condition above is not met, aka, the PR is not in draft status, then this step is skipped.
# Because this step is part of the critical path, omission of this step will result in remaining CI steps not gettinge executed.
# As of 8/8/2022 there is now way to enforce this beahvior in GitHub Actions CI.
# If the condition above is not met, aka, the PR is not in draft status, then this step is skipped.
# Because this step is part of the critical path, omission of this step will result in remaining CI steps not gettinge executed.
# As of 8/8/2022 there is now way to enforce this beahvior in GitHub Actions CI.
- run: exit 0

Docker:
needs: [run-ci]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-go@v3.1.0
with:
go-version: '1.20'
check-latest: true
- uses: actions/setup-go@v5
with:
go-version: "1.21"
check-latest: true

- name: Build
run: |
docker system prune -a -f
docker build --no-cache -t api-server:test .
- name: Build
run: |
docker system prune -a -f
docker build --no-cache -t api-server:test .
Linting:
needs: [run-ci]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v4

- uses: actions/setup-go@v3.1.0
with:
go-version: '1.20'
check-latest: true
- uses: actions/setup-go@v5
with:
go-version: "1.21"
check-latest: true

- name: Lint Internal Package
uses: golangci/[email protected]
with:
args: --verbose --timeout 5m
- name: Lint Internal Package
uses: golangci/[email protected]
with:
args: --verbose --timeout 5m

API-Test:
Tests:
runs-on: ubuntu-latest
needs: [run-ci]
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Retrieve Credentials
id: import-secrets
uses: hashicorp/vault-action@v2
with:
url: https://vault.prism.spectrocloud.com
method: approle
roleId: ${{ secrets.VAULT_ROLE_ID }}
secretId: ${{ secrets.VAULT_SECRET_ID }}
secrets: /providers/github/organizations/spectrocloud/token?org_name=spectrocloud token | VAULT_GITHUB_TOKEN

- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}
fetch-depth: 0
token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }}

- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Dependencies
run: make tests

- name: Go Coverage Badge
uses: tj-actions/coverage-badge-go@v2
with:
filename: coverage.out

- name: Verify Changed files
uses: tj-actions/verify-changed-files@v18
id: verify-changed-files
with:
files: README.md

- name: Setup Nodejs
uses: actions/setup-node@v3
with:
node-version: 18
- name: Commit changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add README.md
git commit -m "chore: Updated coverage badge."
- name: Push changes
if: steps.verify-changed-files.outputs.files_changed == 'true'
uses: ad-m/github-push-action@master
with:
github_token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }}
branch: ${{ github.GITHUB_REF }} # This also worked with GITHUB_BASE_REF
repository: ${{ github.repository }}
force_with_lease: true

API-Test:
runs-on: ubuntu-latest
needs: [run-ci]
steps:
- name: Checkout
uses: actions/checkout@v4

- name: API Test
run: |
make ci-tests
- uses: actions/setup-go@v5
with:
go-version: "1.21"
check-latest: true

- name: API Test
run: |
make ci-tests
3 changes: 2 additions & 1 deletion .releaserc.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Copyright (c) HashiCorp, Inc.
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: MPL-2.0

branches: [main]
repositoryUrl: https://github.com/spectrocloud/hello-universe-api
Expand Down
5 changes: 3 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) HashiCorp, Inc.
# Copyright (c) Spectro Cloud
# SPDX-License-Identifier: MPL-2.0

FROM golang:1.20.2-alpine3.17 as builder
FROM golang:1.21.7-alpine3.19 as builder
WORKDIR /go/src/app
COPY . .
RUN go build -o /go/bin/app && \
Expand Down
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ docker-pull-db:
docker-run-db:
docker run --detach -p 5432:5432 --rm --name api-db ghcr.io/spectrocloud/hello-universe-db:$(VERSION)


stop-db:
docker stop api-db
docker rm api-db

ci-tests: build docker-pull-db docker-run-db
sleep 3
./hello-universe-api 2>&1 &
Expand All @@ -26,6 +31,17 @@ start-server: build docker-pull-db docker-run-db
./hello-universe-api


tests: docker-run-db
sleep 3
go test ./... -covermode=count -coverprofile=coverage.out
go tool cover -func=coverage.out -o=coverage.out
docker stop api-db


view-coverage: ## View the code coverage
@echo "Viewing the code coverage"
go tool cover -html=coverage.out

license: ## Adds a license header to all files. Reference https://github.com/hashicorp/copywrite to learn more.
@echo "Applying license headers..."
copywrite headers
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
![Coverage](https://img.shields.io/badge/Coverage-56.1%25-yellow)

# Hello Universe API

Expand All @@ -21,8 +22,8 @@ A Postman collection is available to help you explore the API. Review the [Postm
The quickest method to start the API server locally is by using the Docker image.

```shell
docker pull ghcr.io/spectrocloud/hello-universe-api:1.0.9
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.0.9
docker pull ghcr.io/spectrocloud/hello-universe-api:1.0.11
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.0.11
```

To start the API server you must have connectivity to a Postgres instance. Use [environment variables](#environment-variables) to customize the API server start parameters.
Expand Down
29 changes: 14 additions & 15 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/**
* Copyright (c) HashiCorp, Inc.
* Copyright (c) Spectro Cloud
* SPDX-License-Identifier: MPL-2.0
*/

module.exports = {
extends: [
'@commitlint/config-conventional'
],
rules: {
'body-max-length': [0, 'always'],
'body-max-line-length': [0, 'always'],
'footer-max-length': [0, 'always'],
'footer-max-line-length': [0, 'always'],
'header-max-length': [0, 'always'],
'scope-max-length': [0, 'always'],
'subject-max-length': [0, 'always'],
'type-max-length': [0, 'always'],
},
}
extends: ["@commitlint/config-conventional"],
rules: {
"body-max-length": [0, "always"],
"body-max-line-length": [0, "always"],
"footer-max-length": [0, "always"],
"footer-max-line-length": [0, "always"],
"header-max-length": [0, "always"],
"scope-max-length": [0, "always"],
"subject-max-length": [0, "always"],
"type-max-length": [0, "always"],
},
};
3 changes: 2 additions & 1 deletion endpoints/counterRoute.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright (c) HashiCorp, Inc.
// Copyright (c) Spectro Cloud
// SPDX-License-Identifier: MPL-2.0

package endpoints

Expand Down
Loading

0 comments on commit 5d35b4b

Please sign in to comment.