Skip to content

Commit

Permalink
ci: add conventional commit tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
roshbhatia committed Feb 28, 2025
1 parent 99535d3 commit 0903726
Show file tree
Hide file tree
Showing 11 changed files with 195 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ jobs:
- name: Build (Docker)
run: make docker-build

- name: Test (Chainsaw)
run: make kind-setup chainsaw-test
# - name: Test (Chainsaw)
# run: make kind-setup chainsaw-test

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/pr-validation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: PR Validation

on:
pull_request:
branches:
- main

jobs:
lint-commits:
name: Lint Commits
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: npm

- name: Install dependencies
run: npm install --no-package-lock

- name: Validate all commits
run: npx commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
88 changes: 88 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
name: Release

on:
push:
branches:
- main

jobs:
release:
name: Release
runs-on: ubuntu-latest
permissions:
contents: write
issues: write
pull-requests: write
packages: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"

- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.12.3

- name: Login to GitHub Container Registry
uses: docker/#-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "lts/*"
cache: npm

- name: Install dependencies
run: npm install -g semantic-release @semantic-release/exec @semantic-release/github @semantic-release/npm

- name: Create package directory
run: mkdir -p charts/dist

- name: Run semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release

- name: Package Helm chart
if: ${{ env.RELEASE_VERSION != '' }}
run: mkdir -p charts/dist && helm package charts/kubanana -d ./charts/dist

- name: Set version from package.json
id: get_version
run: |
PKG_VERSION=$(node -p "require('./package.json').version")
echo "VERSION=v$PKG_VERSION" >> $GITHUB_OUTPUT
echo "VERSION_NO_V=$PKG_VERSION" >> $GITHUB_OUTPUT
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: build/Dockerfile
push: true
tags: |
ghcr.io/${{ github.repository }}/controller:${{ steps.get_version.outputs.VERSION }}
ghcr.io/${{ github.repository }}/controller:latest
- name: Push Helm chart to GHCR
run: |
# Get packaged chart file
CHART_PACKAGE=$(ls ./charts/dist/kubanana-*.tgz | head -n 1)
# Push Helm chart to GHCR
helm push ${CHART_PACKAGE} oci://ghcr.io/${{ github.repository }}/charts
# Output success message
echo "Successfully pushed Helm chart to ghcr.io/${{ github.repository }}/charts"
4 changes: 4 additions & 0 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npx --no -- commitlint --edit ${1}
5 changes: 5 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

# Run Go linting
make analyze
23 changes: 23 additions & 0 deletions .releaserc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"branches": ["main"],
"plugins": [
"@semantic-release/commit-analyzer",
"@semantic-release/release-notes-generator",
"@semantic-release/npm",
[
"@semantic-release/exec",
{
"prepareCmd": "VERSION=v${nextRelease.version} VERSION_NO_V=${nextRelease.version} sed -i.bak -e \"s/appVersion: \\\".*\\\"/appVersion: \\\"v${nextRelease.version}\\\"/ ; s/version: .*/version: ${nextRelease.version}/\" charts/kubanana/Chart.yaml && sed -i.bak \"s/tag: \\\".*\\\"/tag: \\\"v${nextRelease.version}\\\"/\" charts/kubanana/values.yaml && rm -f charts/kubanana/Chart.yaml.bak charts/kubanana/values.yaml.bak",
"publishCmd": "echo 'Version v${nextRelease.version} has been released'"
}
],
[
"@semantic-release/github",
{
"assets": [
{"path": "charts/dist/*.tgz", "label": "Helm Chart"}
]
}
]
]
}
14 changes: 9 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ kind-helm-test: ## Test Helm chart in kind
kind-logs: ## View controller logs
./hack/kind/view-logs.sh controller --follow

helm-update: ## Update Helm chart version from VERSION file
@VERSION=$$(cat VERSION); \
sed -i '' "s/appVersion: \".*\"/appVersion: \"$$VERSION\"/" charts/kubanana/Chart.yaml

helm-package: helm-update ## Package Helm chart
helm-update: ## Update Helm chart version from package.json
@PKG_VERSION=$$(node -p "require('./package.json').version"); \
VERSION="v$$PKG_VERSION"; \
sed -i '' "s/appVersion: \".*\"/appVersion: \"$$VERSION\"/" charts/kubanana/Chart.yaml; \
sed -i '' "s/version: .*/version: $$PKG_VERSION/" charts/kubanana/Chart.yaml; \
sed -i '' "s/tag: \".*\"/tag: \"$$VERSION\"/" charts/kubanana/values.yaml

helm-package: ## Package Helm chart
mkdir -p charts/dist
helm package charts/kubanana -d ./charts/dist

helm-deploy: ## Deploy Helm chart to kind cluster
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ The Kubanana controller image is also available on GHCR:
docker pull ghcr.io/roshbhatia/kubanana/controller:latest

# Or use a specific version
docker pull ghcr.io/roshbhatia/kubanana/controller:v0.1.0
docker pull ghcr.io/roshbhatia/kubanana/controller:v1.0.0
```

## Local Development
Expand Down
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

7 changes: 7 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'body-max-line-length': [0, 'always'],
'footer-max-line-length': [0, 'always']
}
};
28 changes: 28 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "kubanana",
"private": true,
"version": "0.0.0-alpha",
"description": "A Kubernetes controller that triggers jobs based on Kubernetes events",
"repository": {
"type": "git",
"url": "git+https://github.com/roshbhatia/kubanana.git"
},
"author": "Roshan Bhatia",
"license": "MIT",
"bugs": {
"url": "https://github.com/roshbhatia/kubanana/issues"
},
"homepage": "https://github.com/roshbhatia/kubanana#readme",
"devDependencies": {
"@commitlint/cli": "^18.4.3",
"@commitlint/config-conventional": "^18.4.3",
"@semantic-release/exec": "^6.0.3",
"@semantic-release/github": "^9.2.3",
"@semantic-release/npm": "^11.0.2",
"husky": "^8.0.3",
"semantic-release": "^22.0.8"
},
"scripts": {
"prepare": "husky install"
}
}

0 comments on commit 0903726

Please # to comment.