Commit 13a723fd authored by Adrian DC's avatar Adrian DC
Browse files

feat(gitlab-projects-settings): initial sources implementation

Signed-off-by: default avatarAdrian DC <radian.dc@gmail.com>
parents
Loading
Loading
Loading
Loading
Loading
+30 −0
Changes for .chglog/CHANGELOG.tpl.md: 30 added lines, 0 removed lines.
Original line number Diff line number Diff line
{{ range .Versions }}
<a name="{{ .Tag.Name }}"></a>
## {{ if .Tag.Previous }}[{{ .Tag.Name }}]({{ $.Info.RepositoryURL }}/compare/{{ .Tag.Previous.Name }}...{{ .Tag.Name }}){{ else }}{{ .Tag.Name }}{{ end }} ({{ datetime "2006-01-02" .Tag.Date }})

{{ range .CommitGroups -}}
### {{ .Title }}

{{ range .Commits -}}
* {{ if .Scope }}**{{ .Scope }}:** {{ end }}{{ .Subject }}
{{ end }}
{{ end -}}

{{- if .RevertCommits -}}
### Reverts

{{ range .RevertCommits -}}
* {{ .Revert.Header }}
{{ end }}
{{ end -}}

{{- if .NoteGroups -}}
{{ range .NoteGroups -}}
### {{ .Title }}

{{ range .Notes }}
{{ .Body }}
{{ end }}
{{ end -}}
{{ end -}}
{{ end -}}
 No newline at end of file

.chglog/changelog.sh

0 → 100644
+50 −0
Changes for .chglog/changelog.sh: 50 added lines, 0 removed lines.
Original line number Diff line number Diff line
#!/bin/sh

# Arguments
MODE=${1:-${VERSION}}

# Cleanup changelog file
if [ "${MODE}" = '--clean' ]; then

  # Iterate through changelog commits
  echo '
  changelog: regenerate release tag changes history
  regenerate release tag changes history
  ' | while read -r commit; do
    if [ ! -z "${commit}" ]; then
      sed -i "/* ${commit}/d" ./CHANGELOG.md
    fi
  done

  # Strip empty sections
  sed -i "/^### .*/{
    N;
    N;
    /^### .*\n\n$/{
      d;
    };
  }" ./CHANGELOG.md

# Extract version changelog
else
  sed -n "/^## \[${MODE}\]/,/^## \[/{
    n;
    :a;
    n;
    h;
    /^$/{
      n;
      H;
      /^$/{
        n;
        H;
        /^<a name=/{
          q;
        };
      };
      g;
    };
    p;
    ba;
  }" ./CHANGELOG.md
fi

.chglog/config.yml

0 → 100755
+34 −0
Changes for .chglog/config.yml: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
style: gitlab
template: CHANGELOG.tpl.md
info:
  title: CHANGELOG
  repository_url: https://gitlab.com/AdrianDC/gitlab-projects-settings
options:
  commits:
    filters:
      # Type:
      #   - chore
      #   - docs
      #   - feat
      #   - fix
      #   - perf
      #   - refactor
      #   - test
  commit_groups:
    title_maps:
      chore: Cleanups
      docs: Documentation
      feat: Features
      fix: Bug Fixes
      perf: Performance Improvements
      refactor: Code Refactoring
      test: Test
  header:
    pattern: "^(\\w*)(?:\\(([\\w\\$\\.\\-\\*\\s]*)\\))?\\:\\s(.*)$"
    pattern_maps:
      - Type
      - Scope
      - Subject
  notes:
    keywords:
      - BREAKING CHANGE

.gitignore

0 → 100644
+15 −0
Changes for .gitignore: 15 added lines, 0 removed lines.
Original line number Diff line number Diff line
# Build files
build/

# Compiled files
*.pyc
__pycache__/

# Distribution files
.eggs/
*.egg-info/
dist/

# Temporary files
.tmp/
.tmp.*

.gitlab-ci.yml

0 → 100644
+189 −0
Changes for .gitlab-ci.yml: 189 added lines, 0 removed lines.
Original line number Diff line number Diff line
image: registry.gitlab.com/adriandc/gitlabci-local/python:3.11-alpine

stages:
  - development
  - prepare
  - build
  - deploy

.local:
  engine: docker,auto
  real_paths: true
  version: 9.0

# =============================================================================
# Stage: development

clean:
  stage: development
  image: local
  script:
    - sudo rm -rf ./build ./dist ./*.egg-info ./.eggs
  rules:
    - if: $CI_LOCAL

changelog:
  stage: development
  image: local:silent
  script:
    - mkdir -p ./.tmp/
    - |
      if ! ls ./.tmp/git-chglog.tar.gz >/dev/null 2>&1; then
        wget -O ./.tmp/git-chglog.tar.gz -q https://github.com/git-chglog/git-chglog/releases/download/v0.15.4/git-chglog_0.15.4_linux_amd64.tar.gz
        tar -xzf ./.tmp/git-chglog.tar.gz -C ./.tmp/
        rm -f ./.tmp/git-chglog.tar.gz
        chmod +x ./.tmp/git-chglog
      fi
    - 'echo -n " > Current commit : "'
    - git describe --always
    - echo ''
    - 'read -p " > Release tag : " -r tag'
    - echo ''
    - git tag -f -m '' "${tag}"
    - ./.tmp/git-chglog -o ./CHANGELOG.md
    - sed -i "s#raw/[^/]*/docs#raw/${tag}/docs#g" ./README.md
    - git add -v ./CHANGELOG.md ./README.md
    - 'git commit -m "docs(changelog): regenerate release tag changes history" -s'
    - git tag -f -m '' "${tag}"
    - ./.tmp/git-chglog -o ./CHANGELOG.md
    - sh ./.chglog/changelog.sh --clean
    - git add -v ./CHANGELOG.md
    - git commit --amend --no-edit
    - git tag -f -m '' "${tag}"
  rules:
    - if: $CI_LOCAL

# =============================================================================
# Stage: prepare

codestyle:
  stage: prepare
  image: registry.gitlab.com/adriandc/gitlabci-local/gitlabci-local:codestyle
  script:
    - yapf -i ./gitlab_projects_settings/*.py ./gitlab_projects_settings/*/*.py ./setup.py
    - unify -i --quote "'" ./gitlab_projects_settings/*.py ./gitlab_projects_settings/*/*.py ./setup.py
    - echo '' && git diff --name-status
    - git diff --quiet
  rules:
    - if: $CI_COMMIT_REF_NAME == "develop"
      changes:
        - 'CHANGELOG.md'
        - 'gitlab_projects_settings/**/*'
        - 'requirements/**/*'
        - 'setup.py'
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != "develop"
      when: on_success
  allow_failure: true

lint:
  stage: prepare
  image: registry.gitlab.com/adriandc/gitlabci-local/gitlabci-local:codestyle
  variables:
    PIP_DISABLE_PIP_VERSION_CHECK: 1
  before_script:
    - pip3 install -q -r ./requirements/runtime.txt --upgrade
  script:
    - pylint --errors-only ./gitlab_projects_settings/ ./setup.py
    - pylint --disable=missing-docstring --load-plugins=pylint.extensions.no_self_use ./gitlab_projects_settings/ ./setup.py
  rules:
    - if: $CI_COMMIT_REF_NAME == "develop"
      changes:
        - 'CHANGELOG.md'
        - 'gitlab_projects_settings/**/*'
        - 'requirements/**/*'
        - 'setup.py'
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != "develop"
      when: on_success
  allow_failure: true

typings:
  stage: prepare
  image: registry.gitlab.com/adriandc/gitlabci-local/gitlabci-local:codestyle
  variables:
    MYPY_FORCE_COLOR: 1
    TERM: ansi
  script:
    - set +x
    - |
      if [ $(git rev-list --count HEAD) -gt 1 ]; then
        mypy --follow-imports silent --pretty $(git diff --name-only $(git diff --exit-code >/dev/null && echo 'HEAD^' || echo 'HEAD') ./gitlab_projects_settings/ ./setup.py) 2>/dev/null || true
      fi
    - sleep 1
    - mypy --follow-imports silent --pretty ./gitlab_projects_settings/ ./setup.py
  rules:
    - if: $CI_COMMIT_REF_NAME == "develop"
      changes:
        - 'CHANGELOG.md'
        - 'gitlab_projects_settings/**/*'
        - 'requirements/**/*'
        - 'setup.py'
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != "develop"
      when: on_success
  allow_failure: true

# =============================================================================
# Stage: build

build:
  stage: build
  image: registry.gitlab.com/adriandc/gitlabci-local/gitlabci-local:build
  needs: []
  script:
    - rm -rf ./build ./dist ./*.egg-info ./.eggs
    - python3 -m build
  after_script:
    - rm -rf ./build ./*.egg-info ./.eggs
  rules:
    - if: $CI_COMMIT_REF_NAME == "develop"
      changes:
        - 'CHANGELOG.md'
        - 'gitlab_projects_settings/**/*'
        - 'requirements/**/*'
    - if: $CI_COMMIT_TAG || $CI_PIPELINE_SOURCE == "trigger" || $CI_PIPELINE_SOURCE == "web" || $CI_COMMIT_REF_NAME != "develop"
      when: on_success
  artifacts:
    paths:
      - dist/

install:
  stage: build
  image: local:quiet
  script:
    - pipx uninstall $(ls -1 ./dist/*.whl | cut -d'/' -f3 | cut -d'-' -f1) || true
    - pipx install --force ./dist/*.whl
  rules:
    - if: $CI_LOCAL

# =============================================================================
# Stage: deploy

deploy:release:
  stage: deploy
  image: registry.gitlab.com/adriandc/gitlabci-local/gitlabci-local:deploy
  needs:
    - job: build
  variables:
    TWINE_PASSWORD: ${TWINE_PASSWORD}
  before_script:
    - if [ ! "${CI_COMMIT_REF_PROTECTED}" = 'true' ]; then echo '[ERROR] Please protect this tag...'; exit 1; fi
  script:
    - tag=${CI_COMMIT_REF_NAME:-$(git describe --always --abbrev=0)}
    - description=$(sh ./.chglog/changelog.sh "${tag}" | sed -z 's/"/\\"/g')
    - description="${description}"$'\n\n''### Download'$'\n'
    - gitlab-release --description "${description}" --link-prefix '* ' ./dist/*
    - twine upload -u '__token__' -p "${TWINE_PASSWORD}" ./dist/*
  rules:
    - if: $CI_COMMIT_TAG

deploy:trial:
  stage: deploy
  image: registry.gitlab.com/adriandc/gitlabci-local/gitlabci-local:deploy
  needs:
    - job: build
  variables:
    TWINE_PASSWORD_TEST: ${TWINE_PASSWORD_TEST}
  script:
    - twine upload -u '__token__' -p "${TWINE_PASSWORD_TEST}" --repository testpypi ./dist/*
  rules:
    - if: $CI_LOCAL
  when: manual
Loading