diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index fe67065..9130f1a 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -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' diff --git a/.github/workflows/pr-validation.yml b/.github/workflows/pr-validation.yml new file mode 100644 index 0000000..6b7130f --- /dev/null +++ b/.github/workflows/pr-validation.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..f982b82 --- /dev/null +++ b/.github/workflows/release.yml @@ -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/login-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" \ No newline at end of file diff --git a/.husky/commit-msg b/.husky/commit-msg new file mode 100755 index 0000000..2981178 --- /dev/null +++ b/.husky/commit-msg @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +npx --no -- commitlint --edit ${1} \ No newline at end of file diff --git a/.husky/pre-commit b/.husky/pre-commit new file mode 100755 index 0000000..de1819b --- /dev/null +++ b/.husky/pre-commit @@ -0,0 +1,5 @@ +#!/usr/bin/env sh +. "$(dirname -- "$0")/_/husky.sh" + +# Run Go linting +make analyze \ No newline at end of file diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..fb80716 --- /dev/null +++ b/.releaserc.json @@ -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"} + ] + } + ] + ] +} \ No newline at end of file diff --git a/Makefile b/Makefile index 36f1bb0..58dc522 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 4e0a4a6..0f3a463 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/VERSION b/VERSION deleted file mode 100644 index 987b91b..0000000 --- a/VERSION +++ /dev/null @@ -1 +0,0 @@ -v0.0.0-alpha \ No newline at end of file diff --git a/commitlint.config.js b/commitlint.config.js new file mode 100644 index 0000000..811d353 --- /dev/null +++ b/commitlint.config.js @@ -0,0 +1,7 @@ +module.exports = { + extends: ['@commitlint/config-conventional'], + rules: { + 'body-max-line-length': [0, 'always'], + 'footer-max-line-length': [0, 'always'] + } +}; \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..0049d01 --- /dev/null +++ b/package.json @@ -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" + } +} \ No newline at end of file