Skip to content

Commit 5d35b4b

Browse files
fix: updated dependencies
* 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]>
1 parent 4d3aea0 commit 5d35b4b

23 files changed

+874
-103
lines changed

.copywrite.hcl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
schema_version = 1
2+
3+
project {
4+
copyright_holder = "Spectro Cloud"
5+
license = "MPL-2.0"
6+
copyright_year = 2024
7+
8+
# (OPTIONAL) A list of globs that should not have copyright/license headers.
9+
# Supports doublestar glob patterns for more flexibility in defining which
10+
# files or folders should be ignored
11+
header_ignore = [
12+
# "vendors/**",
13+
# "**autogen**",
14+
]
15+
}

.github/workflows/release.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
steps:
1717
- id: checkout
1818
name: Checkout Repository
19-
uses: actions/checkout@v3
19+
uses: actions/checkout@v4
2020

2121
- name: Setup Nodejs
2222
uses: actions/setup-node@v3
@@ -86,7 +86,7 @@ jobs:
8686
steps:
8787
- id: checkout
8888
name: Checkout Repository
89-
uses: actions/checkout@v3
89+
uses: actions/checkout@v4
9090

9191
- name: Retrieve Credentials
9292
id: import-secrets

.github/workflows/test.yaml

Lines changed: 94 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: Pull Request
22

33
on:
44
pull_request:
5-
types: ['synchronize', 'opened', 'reopened', 'ready_for_review']
5+
types: ["synchronize", "opened", "reopened", "ready_for_review"]
66
branches:
7-
- main
7+
- main
88

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

2929
Docker:
3030
needs: [run-ci]
3131
runs-on: ubuntu-latest
3232
steps:
33-
- name: Checkout
34-
uses: actions/checkout@v3
33+
- name: Checkout
34+
uses: actions/checkout@v4
3535

36-
- uses: actions/setup-go@v3.1.0
37-
with:
38-
go-version: '1.20'
39-
check-latest: true
36+
- uses: actions/setup-go@v5
37+
with:
38+
go-version: "1.21"
39+
check-latest: true
4040

41-
- name: Build
42-
run: |
43-
docker system prune -a -f
44-
docker build --no-cache -t api-server:test .
41+
- name: Build
42+
run: |
43+
docker system prune -a -f
44+
docker build --no-cache -t api-server:test .
4545
4646
Linting:
4747
needs: [run-ci]
4848
runs-on: ubuntu-latest
4949
steps:
50-
- name: Checkout
51-
uses: actions/checkout@v3
50+
- name: Checkout
51+
uses: actions/checkout@v4
5252

53-
- uses: actions/setup-go@v3.1.0
54-
with:
55-
go-version: '1.20'
56-
check-latest: true
53+
- uses: actions/setup-go@v5
54+
with:
55+
go-version: "1.21"
56+
check-latest: true
5757

58-
- name: Lint Internal Package
59-
uses: golangci/[email protected]
60-
with:
61-
args: --verbose --timeout 5m
58+
- name: Lint Internal Package
59+
uses: golangci/[email protected]
60+
with:
61+
args: --verbose --timeout 5m
6262

63-
API-Test:
63+
Tests:
6464
runs-on: ubuntu-latest
6565
needs: [run-ci]
66+
permissions:
67+
contents: write
68+
pull-requests: write
6669
steps:
67-
- name: Checkout
68-
uses: actions/checkout@v3
70+
- name: Retrieve Credentials
71+
id: import-secrets
72+
uses: hashicorp/vault-action@v2
73+
with:
74+
url: https://vault.prism.spectrocloud.com
75+
method: approle
76+
roleId: ${{ secrets.VAULT_ROLE_ID }}
77+
secretId: ${{ secrets.VAULT_SECRET_ID }}
78+
secrets: /providers/github/organizations/spectrocloud/token?org_name=spectrocloud token | VAULT_GITHUB_TOKEN
79+
80+
- name: Checkout
81+
uses: actions/checkout@v4
82+
with:
83+
ref: ${{ github.head_ref }}
84+
fetch-depth: 0
85+
token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }}
86+
87+
- name: Setup Nodejs
88+
uses: actions/setup-node@v3
89+
with:
90+
node-version: 18
91+
92+
- name: Install Dependencies
93+
run: make tests
94+
95+
- name: Go Coverage Badge
96+
uses: tj-actions/coverage-badge-go@v2
97+
with:
98+
filename: coverage.out
99+
100+
- name: Verify Changed files
101+
uses: tj-actions/verify-changed-files@v18
102+
id: verify-changed-files
103+
with:
104+
files: README.md
69105

70-
- name: Setup Nodejs
71-
uses: actions/setup-node@v3
72-
with:
73-
node-version: 18
106+
- name: Commit changes
107+
if: steps.verify-changed-files.outputs.files_changed == 'true'
108+
run: |
109+
git config --local user.email "[email protected]"
110+
git config --local user.name "GitHub Action"
111+
git add README.md
112+
git commit -m "chore: Updated coverage badge."
113+
114+
- name: Push changes
115+
if: steps.verify-changed-files.outputs.files_changed == 'true'
116+
uses: ad-m/github-push-action@master
117+
with:
118+
github_token: ${{ steps.import-secrets.outputs.VAULT_GITHUB_TOKEN }}
119+
branch: ${{ github.GITHUB_REF }} # This also worked with GITHUB_BASE_REF
120+
repository: ${{ github.repository }}
121+
force_with_lease: true
122+
123+
API-Test:
124+
runs-on: ubuntu-latest
125+
needs: [run-ci]
126+
steps:
127+
- name: Checkout
128+
uses: actions/checkout@v4
74129

75-
- name: API Test
76-
run: |
77-
make ci-tests
130+
- uses: actions/setup-go@v5
131+
with:
132+
go-version: "1.21"
133+
check-latest: true
78134

135+
- name: API Test
136+
run: |
137+
make ci-tests

.releaserc.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
# Copyright (c) HashiCorp, Inc.
1+
# Copyright (c) Spectro Cloud
2+
# SPDX-License-Identifier: MPL-2.0
23

34
branches: [main]
45
repositoryUrl: https://github.com/spectrocloud/hello-universe-api

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Copyright (c) HashiCorp, Inc.
1+
# Copyright (c) Spectro Cloud
2+
# SPDX-License-Identifier: MPL-2.0
23

3-
FROM golang:1.20.2-alpine3.17 as builder
4+
FROM golang:1.21.7-alpine3.19 as builder
45
WORKDIR /go/src/app
56
COPY . .
67
RUN go build -o /go/bin/app && \

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ docker-pull-db:
1515
docker-run-db:
1616
docker run --detach -p 5432:5432 --rm --name api-db ghcr.io/spectrocloud/hello-universe-db:$(VERSION)
1717

18+
19+
stop-db:
20+
docker stop api-db
21+
docker rm api-db
22+
1823
ci-tests: build docker-pull-db docker-run-db
1924
sleep 3
2025
./hello-universe-api 2>&1 &
@@ -26,6 +31,17 @@ start-server: build docker-pull-db docker-run-db
2631
./hello-universe-api
2732

2833

34+
tests: docker-run-db
35+
sleep 3
36+
go test ./... -covermode=count -coverprofile=coverage.out
37+
go tool cover -func=coverage.out -o=coverage.out
38+
docker stop api-db
39+
40+
41+
view-coverage: ## View the code coverage
42+
@echo "Viewing the code coverage"
43+
go tool cover -html=coverage.out
44+
2945
license: ## Adds a license header to all files. Reference https://github.com/hashicorp/copywrite to learn more.
3046
@echo "Applying license headers..."
3147
copywrite headers

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
[![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release)
2+
![Coverage](https://img.shields.io/badge/Coverage-56.1%25-yellow)
23

34
# Hello Universe API
45

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

2324
```shell
24-
docker pull ghcr.io/spectrocloud/hello-universe-api:1.0.9
25-
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.0.9
25+
docker pull ghcr.io/spectrocloud/hello-universe-api:1.0.11
26+
docker run -p 3000:3000 ghcr.io/spectrocloud/hello-universe-api:1.0.11
2627
```
2728

2829
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.

commitlint.config.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
/**
2-
* Copyright (c) HashiCorp, Inc.
2+
* Copyright (c) Spectro Cloud
3+
* SPDX-License-Identifier: MPL-2.0
34
*/
45

56
module.exports = {
6-
extends: [
7-
'@commitlint/config-conventional'
8-
],
9-
rules: {
10-
'body-max-length': [0, 'always'],
11-
'body-max-line-length': [0, 'always'],
12-
'footer-max-length': [0, 'always'],
13-
'footer-max-line-length': [0, 'always'],
14-
'header-max-length': [0, 'always'],
15-
'scope-max-length': [0, 'always'],
16-
'subject-max-length': [0, 'always'],
17-
'type-max-length': [0, 'always'],
18-
},
19-
}
7+
extends: ["@commitlint/config-conventional"],
8+
rules: {
9+
"body-max-length": [0, "always"],
10+
"body-max-line-length": [0, "always"],
11+
"footer-max-length": [0, "always"],
12+
"footer-max-line-length": [0, "always"],
13+
"header-max-length": [0, "always"],
14+
"scope-max-length": [0, "always"],
15+
"subject-max-length": [0, "always"],
16+
"type-max-length": [0, "always"],
17+
},
18+
};

endpoints/counterRoute.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) HashiCorp, Inc.
1+
// Copyright (c) Spectro Cloud
2+
// SPDX-License-Identifier: MPL-2.0
23

34
package endpoints
45

0 commit comments

Comments
 (0)