diff --git a/.github/utils/requirements_ci.txt b/.github/utils/requirements_ci.txt new file mode 100644 index 0000000..379c222 --- /dev/null +++ b/.github/utils/requirements_ci.txt @@ -0,0 +1 @@ +pre-commit ~=4.5 diff --git a/.github/utils/update_version.sh b/.github/utils/update_version.sh index ec7e2c6..39b2a6a 100755 --- a/.github/utils/update_version.sh +++ b/.github/utils/update_version.sh @@ -5,19 +5,21 @@ echo -e "\n### Setting commit user ###" git config --global user.email "${GIT_USER_EMAIL}" git config --global user.name "${GIT_USER_NAME}" -echo -e "\n### Update version in README ###" -invoke update-version --version="${GITHUB_REF#refs/tags/}" +ref=${GITHUB_REF#refs/tags/} + +echo -e "\n### Update version to ${ref} ###" +invoke update-version --version="${ref}" echo -e "\n### Commit update ###" git add push_action/__init__.py git add CHANGELOG.md -git commit -m "Release ${GITHUB_REF#refs/tags/}" +git commit -m "Release ${ref}" echo -e "\n### Create new full version (v..) tag ###" TAG_MSG=.github/utils/release_tag_msg.txt -sed -i "s|TAG_NAME|${GITHUB_REF#refs/tags/}|g" "${TAG_MSG}" +sed -i "s|TAG_NAME|${ref}|g" "${TAG_MSG}" -git tag -af -F "${TAG_MSG}" ${GITHUB_REF#refs/tags/} +git tag -af -F "${TAG_MSG}" ${ref} echo -e "\n### Move/update v tag ###" MAJOR_VERSION=$( echo ${GITHUB_REF#refs/tags/v} | cut -d "." -f 1 ) diff --git a/.github/workflows/cd_release.yml b/.github/workflows/cd_release.yml index a463dcb..7d5a9ec 100644 --- a/.github/workflows/cd_release.yml +++ b/.github/workflows/cd_release.yml @@ -9,6 +9,7 @@ env: PUBLISH_UPDATE_BRANCH: main GIT_USER_NAME: CasperWA GIT_USER_EMAIL: "casper+github@welzel.nu" + EXCLUDE_TAGS_REGEX: "^(ci_test|master|v[0-9]+)$" jobs: update-repo-and-release: @@ -18,27 +19,26 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v4 + uses: actions/checkout@v6 with: fetch-depth: 0 - - name: Set up Python 3.11 - uses: actions/setup-python@v5 + - name: Set up Python 3.12 + uses: actions/setup-python@v6 with: - python-version: '3.11' + python-version: '3.12' - name: Install Python dependencies run: | python -m pip install -U pip pip install -U setuptools wheel - pip install -U -e .[dev] + pip install .[dev] + pip install flit - name: Update changelog - uses: CharMixer/auto-changelog-action@v1 + uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2 with: - token: ${{ secrets.GITHUB_TOKEN }} - release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }} - exclude_tags_regex: "^(ci_test|master|v[0-9]+)$" + args: --user "CasperWA" --project push-protected --token "${{ secrets.GITHUB_TOKEN }}" --release-branch "${{ env.PUBLISH_UPDATE_BRANCH }}" --exclude-tags-regex "${{ env.EXCLUDE_TAGS_REGEX }}" - name: Update version and tags run: .github/utils/update_version.sh @@ -54,16 +54,16 @@ jobs: tags: true - name: Get tagged versions - run: echo "PREVIOUS_VERSION=$(git tag -l --sort -version:refname | sed -n 2p)" >> $GITHUB_ENV + id: tagged_versions + run: | + PREVIOUS_VERSION="$(git tag -l --sort -version:refname | grep -v -e "${{ env.EXCLUDE_TAGS_REGEX }}" | sed -n 2p)" + + echo "since_previous_version=--since-tag=${PREVIOUS_VERSION}" >> $GITHUB_OUTPUT - name: Create release-specific changelog - uses: CharMixer/auto-changelog-action@v1 + uses: docker://githubchangeloggenerator/github-changelog-generator:1.16.2 with: - token: ${{ secrets.GITHUB_TOKEN }} - release_branch: ${{ env.PUBLISH_UPDATE_BRANCH }} - since_tag: "${{ env.PREVIOUS_VERSION }}" - output: "release_changelog.md" - exclude_tags_regex: "^(ci_test|master|v[0-9]+)$" + args: --user "CasperWA" --project push-protected --token "${{ secrets.GITHUB_TOKEN }}" --release-branch "${{ env.PUBLISH_UPDATE_BRANCH }}" ${{ steps.tagged_versions.outputs.since_previous_version }} --output release_changelog.md --usernames-as-github-logins --exclude-tags-regex "${{ env.EXCLUDE_TAGS_REGEX }}" - name: Append changelog to release body run: | diff --git a/.github/workflows/ci_dependabot.yml b/.github/workflows/ci_dependabot.yml index 7c9d270..60fb4f6 100644 --- a/.github/workflows/ci_dependabot.yml +++ b/.github/workflows/ci_dependabot.yml @@ -23,23 +23,16 @@ jobs: with: ref: main - - name: Set up Python 3.11 + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Install `pre-commit` run: | python -m pip install -U pip pip install -U setuptools wheel - - while IFS="" read -r line || [ -n "${line}" ]; do - if [[ "${line}" =~ ^pre-commit.*$ ]]; then - pre_commit="${line}" - fi - done < requirements_dev.txt - - pip install ${pre_commit} + pip install -r .github/utils/requirements_ci.txt - name: Set up git user info run: | diff --git a/.github/workflows/ci_tests.yml b/.github/workflows/ci_tests.yml index fd27e8c..62a0d12 100644 --- a/.github/workflows/ci_tests.yml +++ b/.github/workflows/ci_tests.yml @@ -20,10 +20,10 @@ jobs: token: ${{ secrets.CI_RESET_TEST_BRANCHES }} fetch-depth: 0 - - name: Set up Python 3.11 + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Reset branches run: | @@ -292,54 +292,16 @@ jobs: - name: Checkout repository uses: actions/checkout@v4 - - name: Set up Python 3.11 + - name: Set up Python 3.12 uses: actions/setup-python@v5 with: - python-version: '3.11' + python-version: '3.12' - name: Install dependencies run: | python -m pip install --upgrade pip pip install -U setuptools wheel - - while IFS="" read -r line || [ -n "${line}" ]; do - if [[ "${line}" =~ ^pre-commit.*$ ]]; then - pre_commit="${line}" - fi - done < requirements_dev.txt - - pip install ${pre_commit} + pip install -r .github/utils/requirements_ci.txt - name: Test with pre-commit - run: SKIP=pylint pre-commit run --all-files --show-diff-on-failure - - pylint-safety: - runs-on: ubuntu-latest - - steps: - - name: Checkout repository - uses: actions/checkout@v4 - with: - fetch-depth: 2 - - - name: Set up Python 3.11 - uses: actions/setup-python@v5 - with: - python-version: '3.11' - - - name: Install dependencies - run: | - python -m pip install -U pip - pip install -U setuptools wheel - pip install -U -r requirements.txt -r requirements_dev.txt - pip install safety - - - name: Run pylint - run: pylint --rcfile=pyproject.toml *.py push_action - - # ID: 70612 - # Package: Jinja2 - # Has been disputed by the maintainer and multiple third parties. - # For more information see: https://github.com/advisories/GHSA-f6pv-j8mr-w6rr - - name: Run safety - run: pip freeze | safety check --stdin --ignore=70612 + run: pre-commit run --all-files --show-diff-on-failure diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f96fb1b..7f6a89c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,5 +1,5 @@ default_language_version: - python: python3.11 + python: python3.12 repos: - repo: https://github.com/pre-commit/pre-commit-hooks @@ -20,7 +20,7 @@ repos: rev: v3.20.0 hooks: - id: pyupgrade - args: [--py311-plus] + args: [--py312-plus] - repo: https://github.com/ambv/black rev: 25.1.0 @@ -41,13 +41,3 @@ repos: additional_dependencies: - "types-requests" - "types-simplejson" - - - repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - language: python - types: [python] - require_serial: true - exclude: ^tests/.*$ diff --git a/Dockerfile b/Dockerfile index cd2e1a7..982983c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ -FROM python:3.11-alpine +FROM python:3.12-alpine -COPY README.md setup.py requirements*.txt ./ +COPY LICENSE README.md pyproject.toml ./ COPY push_action ./push_action RUN apk update \ diff --git a/LICENSE b/LICENSE index 36f5cf9..6a38a64 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020-2021 Casper Welzel Andersen +Copyright (c) 2020-2025 Casper Welzel Andersen Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/pyproject.toml b/pyproject.toml index 493d83e..e06e9bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,14 +1,44 @@ +[build-system] +requires = ["flit-core>=3.11,<4"] +build-backend = "flit_core.buildapi" + +[project] +name="push-action" +dynamic = ["version"] +authors = [{name = "Casper Welzel Andersen", email = "casper+github@welzel.nu"}] +description = "Push local workflow commit(s) to protected branches with required status checks." +readme = "README.md" +license = {file = "LICENSE"} +classifiers = [ + "Programming Language :: Python :: 3.12", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Development Status :: 5 - Production/Stable", + "Intended Audience :: Developers", +] +requires-python = ">=3.12,<3.13" + +dependencies = [ + "requests ~=2.32", +] + +[project.optional-dependencies] +dev = [ + "invoke ~=2.2", + "pre-commit ~=4.2", + "pylint ~=3.3", +] + +[project.scripts] +push-action = "push_action.run:main" + +[tool.flit.module] +name = "push_action" + [tool.mypy] -python_version = "3.11" +python_version = "3.12" ignore_missing_imports = true scripts_are_modules = true warn_unused_configs = true show_error_codes = true allow_redefinition = true - -[tool.pylint.messages_control] -max-line-length = 90 -disable = [ - # "duplicate-code", - # "no-name-in-module" -] diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index fb1be95..0000000 --- a/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -requests~=2.32 diff --git a/requirements_dev.txt b/requirements_dev.txt deleted file mode 100644 index 88771e1..0000000 --- a/requirements_dev.txt +++ /dev/null @@ -1,3 +0,0 @@ -invoke~=2.2 -pre-commit~=4.2 -pylint~=3.3 diff --git a/setup.py b/setup.py deleted file mode 100644 index 0466ee6..0000000 --- a/setup.py +++ /dev/null @@ -1,50 +0,0 @@ -"""Setup file for installing the `push-action` package. - -Install the action by running: - -```console -/path/to/push-protected$ pip install . -``` - -""" - -from pathlib import Path -import re -from setuptools import setup, find_packages - - -TOP_DIR = Path(__file__).parent.resolve() - -with open(TOP_DIR / "push_action" / "__init__.py", encoding="utf8") as handle: - for line in handle.readlines(): - version = re.findall(r'__version__ = "(.*)"', line) - if version: - break - else: - raise RuntimeError("Could not determine version from push_action/__init__.py") - - -setup( - name="push-action", - version=version[0], - url="https://github.com/CasperWA/push-protected", - license="MIT", - author="Casper Welzel Andersen", - author_email="casper+github@welzel.nu", - description=( - "Push local workflow commit(s) to protected branches with required status " - "checks." - ), - long_description=(TOP_DIR / "README.md").read_text(), - long_description_content_type="text/markdown", - packages=find_packages(), - classifiers=[ - "Development Status :: 5 - Production/Stable", - "Programming Language :: Python :: 3.11", - "Intended Audience :: Developers", - ], - python_requires=">=3.11,<3.12", - install_requires=(TOP_DIR / "requirements.txt").read_text(), - extras_require={"dev": (TOP_DIR / "requirements_dev.txt").read_text()}, - entry_points={"console_scripts": ["push-action=push_action.run:main"]}, -)