Skip to content

Commit

Permalink
feat/code_update
Browse files Browse the repository at this point in the history
* fix(init): fix issues, refactor

* feat: refactor

* feat: init

* refactor: all

* refactor

* new changelog

* test

* refactor(cmd/gommitizen): Separate version management between main and internal package

- Move version import to internal/version
- Update the version number in main.go by calling GetVersion() function from internal/version
- This change will make the codebase more modular and easier to maintain

* docs(README.md): Update project version files structure according to Gommitizen convention

* refactor(internal/version/version.go): Initialize new version file for better version management

- Creation of a new go file for handling version information
- This commit does not include any functionality yet, it's just an initial setup for better code organization

* refactor(Dockerfile): Update build environment and user management

- Switch to Alpine Linux 3.20.3 as base image
- Add OpenSSH client, git and bash packages
- Create gommitizen group and user
- Modify the work directory structure for improved organization
- Set up environment variables in .bashrc file for git
- Update the entrypoint to start the SSH agent before running gommitizen
- Improve image description, source and license information in metadata

* build(.goreleaser.yaml): Initialize goreleaser configuration file

* feat(.gitignore): Extend ignore rules - Add 'playground' and 'Build' directories

* build(Makefile): Update Makefile for gommitizen integration, Sonarqube management and release process improvements

- Add gommitizen binary to /usr/local/bin
- Remove stop-sonar command
- Add uninstall command for gommitizen
- Incorporate bump command for versioning using commitizen
- Implement release command for new versions
- Introduce test-release command for snapshot testing of releases
- Update clean command for cleanup
- Remove mocks and regenerate_mocks commands
- Modify start-sonar, stop-sonar and test commands accordingly

* fix: Dependency updates in go.sum

   - Update ngolang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 to latest version
   - Remove old versions of gopkg.in/check.v1 from the dependency list
   - Update gopkg.in/warnings.v0, gopkg.in/yaml.v2 and gopkg.in/yaml.v3 to latest versions

* ci(.github/workflows/release.yaml): Update release workflow to use GoReleaser and GitHub Package Registry (ghcr.io)

- Remove custom script for creating GitHub releases
- Implement GoReleaser action for building, packaging, and publishing binaries
- Update workflow to use GitHub Package Authentication Token (GH_PAT) instead of Github Token
- Set version to latest in GoReleaser configuration

* ci(.github/workflows/release.yaml): Update Docker Login credentials from GH_PAT to GITHUB_TOKEN in release workflow

* docs(README.md): Update project version and generate changelog

- Updated version files to reflect new version 0.18.2
- Generated a new changelog containing changes since last release
- Run gommitizen bump -c or npm run bump to automate this process

* feat(scripts/get-gommitizen.sh): Initialize shell script for automated Gommitizen usage

---------

Co-authored-by: Jaime Pérez Halcón <[email protected]>
  • Loading branch information
sergiotejon and jaimeph authored Oct 30, 2024
1 parent f761f89 commit 8a0e5b5
Show file tree
Hide file tree
Showing 48 changed files with 1,530 additions and 3,149 deletions.
56 changes: 0 additions & 56 deletions .github/workflows/docker.yml

This file was deleted.

89 changes: 25 additions & 64 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -1,78 +1,39 @@
name: Run tests, build and create a new GitHub release
# .github/workflows/release.yml
name: Make Release on Tag Push

on:
push:
tags: '[0-9].[0-9].[0-9]'
tags:
- '*.*.*' # Simple semantic version v1.2.3

jobs:
test:
name: Run tests for binaries
release:
name: Publish Release
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Checkout
uses: actions/checkout@v3

- name: Set up Go
- name: Go configuration
uses: actions/setup-go@v4
with:
go-version: '1.21.4'

- name: Test
run: |
git config --global user.email "gommitizen@localhost"
git config --global user.name "gommitizen"
go test -v ./...
release:
name: Create release
runs-on: ubuntu-latest
needs: test
steps:
- name: Determine tag
run: |
echo "RELEASE_TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
go-version: '1.22'

- name: Create release
uses: actions/github-script@v6
- name: Docker Login
uses: docker/login-action@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
const response = await github.rest.repos.createRelease({
draft: false,
generate_release_notes: true,
name: process.env.RELEASE_TAG,
owner: context.repo.owner,
prerelease: false,
repo: context.repo.repo,
tag_name: process.env.RELEASE_TAG,
});
core.exportVariable('RELEASE_ID', response.data.id);
core.exportVariable('RELEASE_UPLOAD_URL', response.data.upload_url);
} catch (error) {
core.setFailed(error.message);
}
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

build-matrix:
name: Build Binaries
runs-on: ubuntu-latest
needs: release
strategy:
matrix:
# build and publish in parallel: linux/amd64, linux/arm64, windows/amd64, darwin/amd64, darwin/arm64
goos: [ linux, windows, darwin ]
goarch: [ amd64, arm64 ]
exclude:
- goarch: arm64
goos: windows
steps:
- uses: actions/checkout@v3
- uses: wangyoucao577/go-release-action@v1
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
goos: ${{ matrix.goos }}
goarch: ${{ matrix.goarch }}
release_tag: ${{ env.RELEASE_TAG }}
goversion: "1.21.4"
binary_name: "gommitizen-${{ matrix.goos }}-${{ matrix.goarch }}"
extra_files: LICENSE README.md
version: latest
distribution: goreleaser
workdir: .
install-only: false
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ bin/

# sonnarqube
.scannerwork/

# playground
playground/

# Build
bin/
dist/

46 changes: 46 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- id: gommitizen
binary: gommitizen
main: ./cmd/gommitizen
ldflags:
- "-X github.com/freepikcompany/gommitizen/internal/version.version={{.Version}}"
env:
- CGO_ENABLED=0
goos:
- linux
- darwin
- windows

archives:
- format: binary
name_template: "{{ .ProjectName }}_{{ .Version }}_{{ .Os }}_{{ .Arch }}"
builds:
- ai-commit

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
github:
owner: freepikcommpany
name: gommitizen
draft: false
prerelease: false

dockers:
- image_templates:
- "ghcr.io/freepikcompany/gommitizen:{{ .Version }}"
- "ghcr.io/freepikcompany/gommitizen:latest"
dockerfile: build/gommitizen/Dockerfile
build_flag_templates:
- "--build-arg=APP_VERSION={{.Version}}"
33 changes: 0 additions & 33 deletions Dockerfile

This file was deleted.

81 changes: 26 additions & 55 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,66 +1,37 @@
BINARY_NAME=gommitizen
TAG=$(shell git describe --tags --always --dirty)
.PHONY: help bin install uninstall release test-release git-add-extension new-version clean

all: build install
CURRENT_VERSION := $(shell git describe --tags --abbrev=0)

build:
@echo "Building..."
@go build -o bin/$(BINARY_NAME) -v
help:
@echo "Usage: make [target]"
@echo ""
@echo "Common targets:"
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

docker:
@echo "Building docker image..."
@docker build -t $(BINARY_NAME):$(TAG) .
@echo
@echo "Done!"
@echo "May the docker be with you..."
@echo
@echo " # docker run -it $(BINARY_NAME):$(TAG) help"
@echo
bin: ./bin/gommitizen ## Build go application

install: build
@echo "Installing..."
@go install
@echo
@echo "Done!"
./bin/gommitizen: ./cmd/gommitizen/main.go
go build \
-ldflags "-X github.com/freepikcompany/gommitizen/internal/version.version=${CURRENT_VERSION}" \
-o $@ $<

scan: start-sonar
@echo "Scanning..."
@curl -X POST -u admin:admin 'http://localhost:9000/api/users/create?login=user&password=password&name=user'
@sonar-scanner \
-Dsonar.projectKey=${BINARY_NAME} \
-Dsonar.sources=. \
-Dsonar.host.url=http://localhost:9000 \
-Dsonar.login=user \
-Dsonar.password=password
@golangci-lint run
@echo
@echo "Done!"
install: bin /usr/local/bin/gommitizen ## Install gommitizen

start-sonar:
@docker-compose up -d --wait sonarqube
/usr/local/bin/gommitizen:
cp ./bin/gommitizen /usr/local/bin/gommitizen

stop-sonar:
@docker-compose down
uninstall: ## Uninstall gommitizen
rm /usr/local/bin/gommitizen

mocks: regenerate_mocks
regenerate_mocks:
mockgen -package mockGit -destination git/mockGit/mock_interface.go gommitizen/git GitI
bump: ## Bump version using commitizen
cz bump

test: tests
tests:
@echo "Running tests..."
@go test -v ./...
@echo
@echo "Done!"
release: ## Release new version
goreleaser release

coverage:
@echo "Running tests..."
@go test -v ./... --cover --coverprofile=coverage.out
@echo
@echo "Done!"
test-release: ## Test release new version
goreleaser release --snapshot

clean: stop-sonar
@echo "Cleaning..."
@rm -rf bin/*
@echo
@echo "Done!"
clean: ## Clean up
rm -rf ./bin
rm -rf ./dist
Loading

0 comments on commit 8a0e5b5

Please sign in to comment.