commit b4003384922cb7e62872331d43a00e22753cb081 Author: Artifacts <> Date: Sun Mar 1 07:25:37 2026 -0800 Initial commit diff --git a/.gitea/PULL_REQUEST_TEMPLATE.md b/.gitea/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..5536ee7 --- /dev/null +++ b/.gitea/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,15 @@ +### Summary :memo: +_Write an overview about it._ + +### Details +_Describe more what you did on changes._ +1. (...) +2. (...) + +### Bugfixes :bug: (delete if dind't have any) +- + +### Checks +- [ ] Closed #798 +- [ ] Tested Changes +- [ ] Stakeholder Approval \ No newline at end of file diff --git a/.gitea/conventional_commits/commit-msg b/.gitea/conventional_commits/commit-msg new file mode 100755 index 0000000..335984a --- /dev/null +++ b/.gitea/conventional_commits/commit-msg @@ -0,0 +1,47 @@ +#!/usr/bin/env sh +echo "Running commit message checks..." + +. "$(dirname -- "$0")/../../.gitea/conventional_commits/hooks/text-styles.sh" + + +# Get the commit message +commit="$(cat .git/COMMIT_EDITMSG)" +# Define the conventional commit regex +regex='^((build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\(.+\))?(!?):\s([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE))))|(release: .*)$' + +# Check if the commit message matches the conventional commit format +if ! echo "$commit" | grep -Pq "$regex" +then + echo + colorPrint red "❌ Failed to create commit. Your commit message does not follow the conventional commit format." + colorPrint red "Please use the following format: $(colorPrint brightRed 'type(scope)?: description')" + colorPrint red "Available types are listed below. Scope is optional. Use ! after type to indicate breaking change." + echo + colorPrint brightWhite "Quick examples:" + echo "feat: add email notifications on new direct messages refs ABC-1213" + echo "feat(shopping cart): add the amazing button ref: DEFG-23" + echo "feat!: remove ticket list endpoint ref DADA-109" + echo "fix(api): handle empty message in request body refs: MINE-82" + echo "chore(deps): bump some-package-name to version 2.0.0 refs ASDF-12" + echo + colorPrint brightWhite "Commit types:" + colorPrint brightCyan "build: $(colorPrint white "Changes that affect the build system or external dependencies (example scopes: gulp, broccoli, npm)" -n)" + colorPrint brightCyan "ci: $(colorPrint white "Changes to CI configuration files and scripts (example scopes: Travis, Circle, BrowserStack, SauceLabs)" -n)" + colorPrint brightCyan "chore: $(colorPrint white "Changes which doesn't change source code or tests e.g. changes to the build process, auxiliary tools, libraries" -n)" + colorPrint brightCyan "docs: $(colorPrint white "Documentation only changes" -n)" + colorPrint brightCyan "feat: $(colorPrint white "A new feature" -n)" + colorPrint brightCyan "fix: $(colorPrint white "A bug fix" -n)" + colorPrint brightCyan "perf: $(colorPrint white "A code change that improves performance" -n)" + colorPrint brightCyan "refactor: $(colorPrint white "A code change that neither fixes a bug nor adds a feature" -n)" + colorPrint brightCyan "revert: $(colorPrint white "Revert a change previously introduced" -n)" + colorPrint brightCyan "test: $(colorPrint white "Adding missing tests or correcting existing tests" -n)" + echo + + colorPrint brightWhite "Reminders" + echo "Put newline before extended commit body" + echo "More details at $(underline "http://www.conventionalcommits.org")" + echo + echo "The commit message you attempted was: $commit" + echo + exit 1 +fi \ No newline at end of file diff --git a/.gitea/conventional_commits/generate-version.sh b/.gitea/conventional_commits/generate-version.sh new file mode 100755 index 0000000..7321f6b --- /dev/null +++ b/.gitea/conventional_commits/generate-version.sh @@ -0,0 +1,105 @@ +#!/bin/bash + +# Rules for generating semantic versioning +# major: breaking change +# minor: feat, style +# patch: build, fix, perf, refactor, revert + +PREVENT_REMOVE_FILE=$1 +TEMP_FILE_PATH=.gitea/conventional_commits/tmp + +LAST_TAG=$(git describe --tags --abbrev=0 --always) +echo "Last tag: #$LAST_TAG#" +PATTERN="^[0-9]+\.[0-9]+\.[0-9]+$" + +increment_version() { + local version=$1 + local increment=$2 + local major=$(echo $version | cut -d. -f1) + local minor=$(echo $version | cut -d. -f2) + local patch=$(echo $version | cut -d. -f3) + + if [ "$increment" == "major" ]; then + major=$((major + 1)) + minor=0 + patch=0 + elif [ "$increment" == "minor" ]; then + minor=$((minor + 1)) + patch=0 + elif [ "$increment" == "patch" ]; then + patch=$((patch + 1)) + fi + + echo "${major}.${minor}.${patch}" +} + +create_file() { + local with_range=$1 + if [ -s $TEMP_FILE_PATH/messages.txt ]; then + return 1 + fi + if [ "$with_range" == "true" ]; then + git log $LAST_TAG..HEAD --no-decorate --pretty=format:"%s" > $TEMP_FILE_PATH/messages.txt + else + git log --no-decorate --pretty=format:"%s" > $TEMP_FILE_PATH/messages.txt + fi +} + +get_commit_range() { + rm $TEMP_FILE_PATH/messages.txt + if [[ $LAST_TAG =~ $PATTERN ]]; then + create_file true + else + create_file + LAST_TAG="0.0.0" + fi + echo " " >> $TEMP_FILE_PATH/messages.txt +} + +start() { + mkdir -p $TEMP_FILE_PATH + get_commit_range + new_version=$LAST_TAG + increment_type="" + + while read message; do + echo $message + if echo $message | grep -Pq '(feat|style)(\([\w]+\))?!:([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE)))'; then + increment_type="major" + echo "a" + break + elif echo $message | grep -Pq '(feat|style)(\([\w]+\))?:([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE)))'; then + if [ -z "$increment_type" ] || [ "$increment_type" == "patch" ]; then + increment_type="minor" + echo "b" + fi + elif echo $message | grep -Pq '(build|fix|perf|refactor|revert)(\(.+\))?:\s([a-zA-Z0-9-_!\&\.\%\(\)\=\w\s]+)\s?(,?\s?)((ref(s?):?\s?)(([A-Z0-9]+\-[0-9]+)|(NOISSUE)))'; then + if [ -z "$increment_type" ]; then + increment_type="patch" + echo "c" + fi + fi + done < $TEMP_FILE_PATH/messages.txt + + if [ -n "$increment_type" ]; then + new_version=$(increment_version $LAST_TAG $increment_type) + echo "New version: $new_version" + + gitchangelog | grep -v "[rR]elease:" > HISTORY.md + echo $new_version > project_name/VERSION + git add project_name/VERSION HISTORY.md + git commit -m "release: version $new_version 🚀" + echo "creating git tag : $new_version" + git tag $new_version + git push -u origin HEAD --tags + echo "Gitea Actions will detect the new tag and release the new version." + else + echo "No changes requiring a version increment." + fi +} + +start + +if [ -z "$PREVENT_REMOVE_FILE" ]; then + rm -f $TEMP_FILE_PATH/messages.txt +fi diff --git a/.gitea/conventional_commits/hooks/text-styles.sh b/.gitea/conventional_commits/hooks/text-styles.sh new file mode 100755 index 0000000..c03c8c9 --- /dev/null +++ b/.gitea/conventional_commits/hooks/text-styles.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +colorPrint() { + local color=$1 + local text=$2 + shift 2 + local newline="\n" + local tab="" + + for arg in "$@" + do + if [ "$arg" = "-t" ]; then + tab="\t" + elif [ "$arg" = "-n" ]; then + newline="" + fi + done + + case $color in + black) color_code="30" ;; + red) color_code="31" ;; + green) color_code="32" ;; + yellow) color_code="33" ;; + blue) color_code="34" ;; + magenta) color_code="35" ;; + cyan) color_code="36" ;; + white) color_code="37" ;; + brightBlack) color_code="90" ;; + brightRed) color_code="91" ;; + brightGreen) color_code="92" ;; + brightYellow) color_code="93" ;; + brightBlue) color_code="94" ;; + brightMagenta) color_code="95" ;; + brightCyan) color_code="96" ;; + brightWhite) color_code="97" ;; + *) echo "Invalid color"; return ;; + esac + + printf "\e[${color_code}m${tab}%s\e[0m${newline}" "$text" +} + +underline () { + printf "\033[4m%s\033[24m" "$1" +} diff --git a/.gitea/release_message.sh b/.gitea/release_message.sh new file mode 100755 index 0000000..f5a9062 --- /dev/null +++ b/.gitea/release_message.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +previous_tag=$(git tag --sort=-creatordate | sed -n 2p) +git shortlog "${previous_tag}.." | sed 's/^./ &/' diff --git a/.gitea/rename_project.sh b/.gitea/rename_project.sh new file mode 100755 index 0000000..52f1ee5 --- /dev/null +++ b/.gitea/rename_project.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +while getopts a:n:u:d: flag +do + case "${flag}" in + a) author=${OPTARG};; + n) name=${OPTARG};; + u) urlname=${OPTARG};; + d) description=${OPTARG};; + esac +done + +echo "Author: $author"; +echo "Project Name: $name"; +echo "Project URL name: $urlname"; +echo "Description: $description"; + +echo "Renaming project..." + +original_author="author_name" +original_name="project_name" +original_urlname="project_urlname" +original_description="project_description" +# for filename in $(find . -name "*.*") +for filename in $(git ls-files) +do + sed -i "s/$original_author/$author/g" $filename + sed -i "s/$original_name/$name/g" $filename + sed -i "s/$original_urlname/$urlname/g" $filename + sed -i "s/$original_description/$description/g" $filename + echo "Renamed $filename" +done + +mv project_name $name + +# This command runs only once on GHA! +rm -rf .gitea/template.yml +rm -rf project_name +rm -rf project_name.Tests \ No newline at end of file diff --git a/.gitea/workflows/release.yml b/.gitea/workflows/release.yml new file mode 100644 index 0000000..78eae2e --- /dev/null +++ b/.gitea/workflows/release.yml @@ -0,0 +1,61 @@ +name: Upload Python Package +permissions: + contents: write + +env: + SKIP_MAKE_SETUP_CHECK: 'true' + +on: + push: + # Sequence of patterns matched against refs/tags + tags: + - '*' # Push events to matching v*, i.e. v1.0, v20.15.10 + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +jobs: + release: + name: Create Release + runs-on: ubuntu-latest + permissions: + contents: write + steps: + - uses: actions/checkout@v3 + with: + # by default, it uses a depth of 1 + # this fetches all history so that we can read each commit + fetch-depth: 0 + - name: Generate Changelog + run: .gitea/release_message.sh > release_message.md + - name: Release + uses: softprops/action-gh-release@v1 + with: + body_path: release_message.md + + deploy: + needs: release + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v5 + - name: Check version match + run: | + REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_') + if [ "$(cat project_name/VERSION)" = "${GITHUB_REF_NAME}" ] ; then + echo "Version matches successfully!" + else + echo "Version must match!" + exit -1 + fi + - name: Login to Gitea container registry + uses: docker/login-action@v3 + with: + username: gitearobot + password: ${{ secrets.PACKAGE_GITEA_PAT }} + registry: git.disi.dev + - name: Build and publish + run: | + REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $1}' | tr '[:upper:]' '[:lower:]') + REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_') + docker build -t "git.disi.dev/$REPOSITORY_OWNER/project_name:$(cat project_name/VERSION)" -f Containerfile ./ + docker push "git.disi.dev/$REPOSITORY_OWNER/project_name:$(cat project_name/VERSION)" \ No newline at end of file diff --git a/.gitea/workflows/rename_project.yml b/.gitea/workflows/rename_project.yml new file mode 100644 index 0000000..ca77350 --- /dev/null +++ b/.gitea/workflows/rename_project.yml @@ -0,0 +1,48 @@ +name: Rename the project from template + +on: [push] + +permissions: write-all + +jobs: + rename-project: + if: ${{ !endsWith (gitea.repository, 'Templates/Docker_Image') }} + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + # by default, it uses a depth of 1 + # this fetches all history so that we can read each commit + fetch-depth: 0 + ref: ${{ gitea.head_ref }} + + - run: echo "REPOSITORY_NAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}' | tr '-' '_')" >> $GITHUB_ENV + shell: bash + + - run: echo "REPOSITORY_URLNAME=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $2}')" >> $GITHUB_ENV + shell: bash + + - run: echo "REPOSITORY_OWNER=$(echo "$GITHUB_REPOSITORY" | awk -F '/' '{print $1}')" >> $GITHUB_ENV + shell: bash + + - name: Is this still a template + id: is_template + run: echo "::set-output name=is_template::$(ls .gitea/template.yml &> /dev/null && echo true || echo false)" + + - name: Rename the project + if: steps.is_template.outputs.is_template == 'true' + run: | + echo "Renaming the project with -a(author) ${{ env.REPOSITORY_OWNER }} -n(name) ${{ env.REPOSITORY_NAME }} -u(urlname) ${{ env.REPOSITORY_URLNAME }}" + .gitea/rename_project.sh -a ${{ env.REPOSITORY_OWNER }} -n ${{ env.REPOSITORY_NAME }} -u ${{ env.REPOSITORY_URLNAME }} -d "Awesome ${{ env.REPOSITORY_NAME }} created by ${{ env.REPOSITORY_OWNER }}" + + - name: Remove renaming workflow + if: steps.is_template.outputs.is_template == 'true' + run: | + rm .gitea/workflows/rename_project.yml + rm .gitea/rename_project.sh + + - uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "✅ Ready to clone and code." + # commit_options: '--amend --no-edit' + push_options: --force \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..32a72f1 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,82 @@ +# How to develop on this project + +project_name welcomes contributions from the community. + +This instructions are for linux base systems. (Linux, MacOS, BSD, etc.) + +## Setting up your own fork of this repo. + +- On gitea interface click on `Fork` button. +- Clone your fork of this repo. `git clone git@git.disi.dev:YOUR_GIT_USERNAME/project_urlname.git` +- Enter the directory `cd project_urlname` +- Add upstream repo `git remote add upstream https://git.disi.dev/author_name/project_urlname` +- initialize repository for use `make setup` + +## Install the project in develop mode + +Run `make install` to install the project in develop mode. + +## Create a new branch to work on your contribution + +Run `git checkout -b my_contribution` + +## Make your changes + +Edit the files using your preferred editor. (we recommend VIM or VSCode) + +## Format the code + +Run `make fmt` to format the code. + +## Run the linter + +Run `make lint` to run the linter. + +## Commit your changes + +This project uses [conventional git commit messages](https://www.conventionalcommits.org/en/v1.0.0/). + +Example: `fix(package): update setup.py arguments 🎉` (emojis are fine too) + +## Push your changes to your fork + +Run `git push origin my_contribution` + +## Submit a pull request + +On gitea interface, click on `Pull Request` button. + +## Makefile utilities + +This project comes with a `Makefile` that contains a number of useful utility. + +```bash +❯ make +Usage: make + +Targets: +help: ## Show the help. +setup: ## Perform initial repository setup after cloning. +fmt: ## Format code. +lint: ## Run linters. +clean: ## Clean unused files. +virtualenv: ## Create a virtual environment. +release: ## Create a new tag for release. +init: ## Initialize the project based on an application template. +``` + +## Making a new release + +This project uses [semantic versioning](https://semver.org/) and tags releases with `X.Y.Z` +Every time a new tag is created and pushed to the remote repo, gitea actions will +automatically create a new release on gitea. + +To trigger a new release all you need to do is. + +1. If you have changes to add to the repo + * Make your changes following the steps described above. + * Commit your changes following the [conventional git commit messages](https://www.conventionalcommits.org/en/v1.0.0/). +2. Run the tests to ensure everything is working. +4. Run `make release` to create a new tag and push it to the remote repo. + +> **CAUTION**: The make release will change local changelog files and commit all the unstaged changes you have. diff --git a/Containerfile b/Containerfile new file mode 100644 index 0000000..e996a1a --- /dev/null +++ b/Containerfile @@ -0,0 +1,6 @@ +FROM alpine + +WORKDIR /app +COPY ./project_name/* /app + +CMD ["sh", "/app/hello_world.sh"] \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0587870 --- /dev/null +++ b/Makefile @@ -0,0 +1,53 @@ +.ONESHELL: +ENV_PREFIX=$(shell python -c "if __import__('pathlib').Path('.venv/bin/pip').exists(): print('.venv/bin/')") +USING_POETRY=$(shell grep "tool.poetry" pyproject.toml && echo "yes") + +.PHONY: issetup +issetup: + @[ -f .git/hooks/commit-msg ] || [ -z ${SKIP_MAKE_SETUP_CHECK+x} ] || (echo "You must run 'make setup' first to initialize the repo!" && exit 1) + +.PHONY: setup +setup: + @cp .gitea/conventional_commits/commit-msg .git/hooks/ + +.PHONY: help +help: ## Show the help. + @echo "Usage: make " + @echo "" + @echo "Targets:" + @fgrep "##" Makefile | fgrep -v fgrep + +.PHONY: fmt +fmt: issetup ## Format code using black & isort. + $(ENV_PREFIX)isort project_name/ + $(ENV_PREFIX)black -l 79 project_name/ + $(ENV_PREFIX)black -l 79 tests/ + +.PHONY: lint +lint: issetup ## Run pep8, black, mypy linters. + $(ENV_PREFIX)flake8 project_name/ + $(ENV_PREFIX)black -l 79 --check project_name/ + $(ENV_PREFIX)black -l 79 --check tests/ + $(ENV_PREFIX)mypy --ignore-missing-imports project_name/ + +.PHONY: release +release: issetup ## Create a new tag for release. + @echo "WARNING: This operation will create a version tag and push to gitea" + @read -p "Version? (provide the next x.y.z semver) : " TAG + @echo "$${TAG}" > project_name/VERSION + @$(ENV_PREFIX)gitchangelog > HISTORY.md + @git add project_name/VERSION HISTORY.md + @git commit -m "release: version $${TAG} 🚀" + @echo "creating git tag : $${TAG}" + @git tag $${TAG} + @git push -u origin HEAD --tags + @echo "Gitea Actions will detect the new tag and release the new version." + +.PHONY: build +build: issetup ## Create a new tag for release. + @docker build -t project_name:$(cat project_name/VERSION) -f Containerfile . + +# This project has been generated from rochacbruno/python-project-template +# __author__ = 'rochacbruno' +# __repo__ = https://github.com/rochacbruno/python-project-template +# __sponsor__ = https://github.com/sponsors/rochacbruno/ \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..c239fb0 --- /dev/null +++ b/README.md @@ -0,0 +1,43 @@ +# Docker Image Project Template + +A low dependency and really simple to start project template for Docker Images. + +Partly based on/see also +- [Flask-Project-Template](https://git.disi.dev/Templates/Flask/) for a full feature Flask project including database, API, admin interface, etc. + +### HOW TO USE THIS TEMPLATE + +1. Create a new repository from this template and choose a name for your project + (e.g. `my_awesome_project` - recommendation is to use all lowercase and underscores separation for repo names.) +2. Wait until the first run of CI finishes (Gitea Actions will process the template and commit to your new repo) +3. Read the file [CONTRIBUTING.md](CONTRIBUTING.md) +4. Then clone your new project and happy coding! + +> **NOTE**: **WAIT** until first CI run on gitea actions before cloning your new project. + +### What is included on this template? + +- 🖼️ Templates for starting multiple application types: + **Run `make init` after cloning to generate a new project based on a template.** +- 🤖 A [Makefile](Makefile) with the most useful commands to install, test, lint, format and release your project. +- 💬 Auto generation of change log using **gitchangelog** to keep a HISTORY.md file automatically based on your commit history on every release. +- 🐋 A simple [Containerfile](Containerfile) to build a container image for your project. + `Containerfile` is a more open standard for building container images than Dockerfile, you can use buildah or docker with this file. +- 🔄 Continuous integration using [Gitea Actions](.gitea/workflows/) with jobs to lint, test and release your project on Linux, Mac and Windows environments. + + + +--- +# project_name + +project_description + +## Usage + +```bash +$ docker build -t -f Containerfile . +``` + +## Development + +Read the [CONTRIBUTING.md](CONTRIBUTING.md) file. \ No newline at end of file diff --git a/project_name/hello_world.sh b/project_name/hello_world.sh new file mode 100755 index 0000000..27071b2 --- /dev/null +++ b/project_name/hello_world.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "Hello world" \ No newline at end of file