1 Commits

Author SHA1 Message Date
c2000c3f4d WIP
All checks were successful
run tests / check (push) Successful in 44s
run tests / release (push) Successful in 16s
2025-12-10 06:06:19 +01:00
20 changed files with 98 additions and 285 deletions

View File

@@ -1 +1 @@
version_descriptor: pyproject.toml
version_descriptor: setup.py

View File

@@ -1,10 +0,0 @@
name: check if project is already released
on:
- pull_request
jobs:
unittest:
runs-on: action-runner
steps:
- uses: actions/checkout@v4
- uses: ./check-is-not-released

View File

@@ -23,32 +23,6 @@ jobs:
- run: set -u; echo "$RELEASE_PROJECT_CURRENT_VERSION"
test-sync-versions:
runs-on: action-runner
steps:
- uses: actions/checkout@v4
# skip login locally
- if: github.repository == 'actions/release'
uses: https://gitea.puzzleyou.net/actions/configure-runner-environment@master
- run: |
echo "1.33.7" > /tmp/version-test.txt
echo "0.0.42" > /tmp/other-version.txt
- uses: ./declare
with:
configure_runner_environment: false
version_descriptor: /tmp/version-test.txt
artefact_type: oci_image
artefact_name: default-image
artefact_version_descriptor: /tmp/other-version.txt
- uses: ./sync-versions
- run: test "$(cat /tmp/version-test.txt)" = "$RELEASE_PROJECT_PLANNED_VERSION"
- run: test "$(cat /tmp/other-version.txt)" = "$RELEASE_PROJECT_PLANNED_VERSION"
test-is-not-yet-released:
runs-on: action-runner
steps:
@@ -67,26 +41,6 @@ jobs:
with:
configure_runner_environment: false
test-skip-release-if-already-released:
runs-on: action-runner
steps:
- uses: actions/checkout@v4
# skip login locally
- if: github.repository == 'actions/release'
uses: https://gitea.puzzleyou.net/actions/configure-runner-environment@master
- uses: ./declare
with:
configure_runner_environment: false
version_descriptor: test-assets/Cargo.toml
- uses: ./release
with:
configure_runner_environment: false
dry_run: true
sync_versions: false
test-declare-with-release-yaml:
runs-on: action-runner
steps:
@@ -100,7 +54,6 @@ jobs:
with:
dry_run: true
configure_runner_environment: false
sync_versions: false
- run: set -u; echo "$RELEASE_PROJECT_CURRENT_VERSION"
@@ -135,7 +88,7 @@ jobs:
- uses: ./add-artefact
with:
type: wheel
filename: "test-assets/wheels/*.whl"
pattern: "test-assets/wheels/*.whl"
- uses: ./add-artefact
with:

View File

@@ -18,7 +18,7 @@ inputs:
filename:
required: false
description: "required for tarball, sdist, wheel"
description: "required for tarball, sdist"
default: ""
package_name:
@@ -26,6 +26,11 @@ inputs:
description: "required for tarball"
default: ""
pattern:
required: false
description: "required for wheel"
default: ""
directory:
required: false
description: "required for npm"
@@ -49,6 +54,7 @@ runs:
--artefact-name "${{ inputs.name }}" \
--artefact-filename "${{ inputs.filename }}" \
--artefact-package-name "${{ inputs.package_name }}" \
--artefact-pattern "${{ inputs.pattern }}" \
--artefact-directory "${{ inputs.directory }}" \
--version-descriptor "${{ inputs.version_descriptor }}" \
--write-env-vars-to-filename "$GITHUB_ENV"

View File

@@ -33,11 +33,15 @@ runs:
run: |
set +e
if [[ "$RELEASE_PROJECT_IS_RELEASED" = "1" ]]; then
nix run ${{ github.action_path }} -- \
dump \
--state "${RELEASE_ACTION_STATEFILE}" \
| grep "is already released: True"
IS_RELEASED_EXIT_CODE=$?
if [[ "$IS_RELEASED_EXIT_CODE" -eq 0 ]]; then
VERSION="$RELEASE_PROJECT_CURRENT_VERSION"
echo "Project is already released with version ${VERSION}."
echo "You should increment the project version."
echo "If you don't, then the project will not be released."
exit -1
else
echo "Project is not yet released."

View File

@@ -41,7 +41,7 @@ inputs:
artefact_filename:
required: false
description: "required for tarball, sdist, wheel"
description: "required for tarball, sdist"
default: ""
artefact_package_name:
@@ -49,6 +49,11 @@ inputs:
description: "required for tarball"
default: ""
artefact_pattern:
required: false
description: "required for wheel"
default: ""
artefact_directory:
required: false
description: "required for npm"
@@ -99,11 +104,6 @@ runs:
- name: declare release project
run: |
if [[ ! -z "${RELEASE_PROJECT_CURRENT_VERSION}" ]]; then
echo "already set up."
exit 0
fi
nix run ${{ github.action_path }} -- \
declare \
--release-yaml-filename "${{ inputs.filename }}" \
@@ -124,6 +124,7 @@ runs:
--artefact-name "${{ inputs.artefact_name }}" \
--artefact-filename "${{ inputs.artefact_filename }}" \
--artefact-package-name "${{ inputs.artefact_package_name }}" \
--artefact-pattern "${{ inputs.artefact_pattern }}" \
--artefact-directory "${{ inputs.artefact_directory }}" \
--version-descriptor "${{ inputs.artefact_version_descriptor }}"
fi

View File

@@ -4,23 +4,6 @@ description: "dump current project description"
runs:
using: composite
steps:
- name: declare project if neccessary
run: |
if [[ ! -z "${RELEASE_PROJECT_CURRENT_VERSION}" ]]; then
echo "already set up."
exit 0
fi
nix run ${{ github.action_path }} -- \
declare \
--release-yaml-filename ".gitea/release.yaml" \
--gitea-instance "https://gitea.puzzleyou.net" \
--release-repository-name "${{ github.repository }}" \
--release-ref-name "${{ github.ref_name }}" \
--release-run-number "${{ github.run_number }}" \
--release-commit-sha "${{ github.sha }}" \
--write-env-vars-to-filename "$GITHUB_ENV"
- name: dump project description
run: |
nix run ${{ github.action_path }} -- \

23
flake.lock generated
View File

@@ -34,31 +34,10 @@
"type": "github"
}
},
"pyproject-nix": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1764134915,
"narHash": "sha256-xaKvtPx6YAnA3HQVp5LwyYG1MaN4LLehpQI8xEdBvBY=",
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"rev": "2c8df1383b32e5443c921f61224b198a2282a657",
"type": "github"
},
"original": {
"owner": "pyproject-nix",
"repo": "pyproject.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-utils": "flake-utils",
"nixpkgs": "nixpkgs",
"pyproject-nix": "pyproject-nix"
"nixpkgs": "nixpkgs"
}
},
"systems": {

View File

@@ -4,41 +4,52 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils";
pyproject-nix = {
url = "github:pyproject-nix/pyproject.nix";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, pyproject-nix }:
outputs = { self, nixpkgs, flake-utils, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };
pythonProject = pyproject-nix.lib.project.loadPyproject {
projectRoot = ./.;
};
python = pkgs.python313.withPackages (ps: with ps; [
isort
flake8
semver
toml
requests
pyyaml
packaging
]);
pythonInterpreter = pkgs.python313;
pythonPackage = pkgs.python3Packages.buildPythonPackage {
name = "release-action";
src = ./.;
};
in
{
devShells.default = pkgs.mkShell {
buildInputs = [
pkgs.envsubst
pkgs.just
pkgs.gitea-actions-runner
(pythonInterpreter.withPackages
(pythonProject.renderers.withPackages {
python = pythonInterpreter;
extraPackages = ps: with ps; [ flake8 isort ];
}))
python
];
};
packages.default = pythonInterpreter.pkgs.buildPythonPackage (
pythonProject.renderers.buildPythonPackage {
python = pythonInterpreter;
});
packages.default = pkgs.writers.writePython3Bin
"release-action"
{
libraries = with pkgs.python3Packages; [
semver # TODO move to setup.py?
toml
requests
pythonPackage
pyyaml
packaging
];
}
(builtins.readFile ./src/main.py)
;
}
);
}

View File

@@ -30,14 +30,5 @@ test-workflows:
--workflows ./.gitea/workflows/check.yaml \
--job test-is-not-yet-released
act_runner exec \
--image "-self-hosted" \
--event pull_request \
--workflows ./.gitea/workflows/check.yaml \
--job test-skip-release-if-already-released
act_runner exec \
--image "-self-hosted" \
--event pull_request \
--workflows ./.gitea/workflows/check.yaml \
--job test-sync-versions
# TODO
# --image "europe-docker.pkg.dev/puzzle-and-play/docker/action-runner-job:latest" \

View File

@@ -1,16 +0,0 @@
[project]
name = "gitea-release-action"
version = "0.0.1"
description = "reusable action for release workflows"
authors = [ ]
requires-python = ">=3.13"
dependencies = [
"semver",
"toml",
"requests",
"pyyaml",
"packaging"
]
[project.scripts]
gitea-release-action = "main:main_cli"

View File

@@ -11,15 +11,6 @@ inputs:
required: false
default: true
build_run:
required: false
description: "commands to run before publishing artefacts"
default: ""
sync_versions:
required: false
default: true
runs:
using: composite
steps:
@@ -43,28 +34,7 @@ runs:
--release-commit-sha "${{ github.sha }}" \
--write-env-vars-to-filename "$GITHUB_ENV"
- name: check if already released
id: check_released
run: |
if [[ "$RELEASE_PROJECT_IS_RELEASED" == "1" ]] && [[ "$RELEASE_IS_PRERELEASE" == "0" ]]; then
echo "is_released=1" >> "$GITHUB_OUTPUT"
else
echo "is_released=0" >> "$GITHUB_OUTPUT"
fi
- name: sync versions
if: ${{ steps.check_released.outputs.is_released == '0' && inputs.sync_versions == 'true' }}
run: |
nix run ${{ github.action_path }} -- \
sync-versions \
--state "${RELEASE_ACTION_STATEFILE}"
- name: run build commands
if: ${{ steps.check_released.outputs.is_released == '0' && inputs.build_run != '' }}
run: ${{ inputs.build_run }}
- name: publish artefacts
if: ${{ steps.check_released.outputs.is_released == '0' }}
run: |
nix run ${{ github.action_path }} -- \
publish-artefacts \
@@ -72,7 +42,6 @@ runs:
--dry-run "${{ inputs.dry_run }}"
- name: update deployments
if: ${{ steps.check_released.outputs.is_released == '0' }}
run: |
nix run ${{ github.action_path }} -- \
update-deployments \
@@ -80,7 +49,6 @@ runs:
--dry-run "${{ inputs.dry_run }}"
- name: create release
if: ${{ steps.check_released.outputs.is_released == '0' }}
run: |
nix run ${{ github.action_path }} -- \
create-release \

6
setup.py Normal file
View File

@@ -0,0 +1,6 @@
from setuptools import setup
setup(
name='release-action',
version='0.0.1.dev0',
)

View File

@@ -82,7 +82,7 @@ def dump_project_description(project_description: ProjectDescription):
print(' release version name: %s' % release_info.version_str)
elif isinstance(generated, Wheel):
print(' - wheel: %s' % generated.filename)
print(' - wheel: %s' % generated.pattern)
print(' repository: %s' % generated.repository)
print(' release version name: %s' % release_info.version_str)
@@ -152,6 +152,7 @@ def make_artefact(type: str,
name: str,
filename: str,
package_name: str,
pattern: str,
directory: str,
version_descriptor) -> ArtefactDescription:
@@ -171,8 +172,8 @@ def make_artefact(type: str,
**maybe_repository)
elif type == 'wheel':
assert filename is not None
generated = Wheel(filename=filename, **maybe_repository)
assert pattern is not None
generated = Wheel(pattern=pattern, **maybe_repository)
elif type == 'sdist':
assert filename is not None
@@ -232,29 +233,14 @@ def make_deployment(type: str,
return DeploymentDescription(deployment=deployment, **maybe_condition)
def sync_versions(project_description: ProjectDescription):
planned_version = project_description.planned_version
def sync(descriptor_filename: str):
v = versioning.use_any(descriptor_filename)
v.version = planned_version
v.store()
sync(project_description.version_descriptor)
for artefact in project_description.artefacts:
if artefact.version_descriptor is not None:
sync(artefact.version_descriptor)
def main_cli():
if __name__ == '__main__':
parser = ArgumentParser()
parser.add_argument('action', choices=[
# TODO missing: adjust version (development)
'declare',
'check',
'add-artefact',
'add-deployment',
'sync-versions',
'publish-artefacts',
'update-deployments',
'create-release',
@@ -296,6 +282,7 @@ def main_cli():
parser.add_argument('--artefact-name', type=nullable_string)
parser.add_argument('--artefact-package-name', type=nullable_string)
parser.add_argument('--artefact-filename', type=nullable_string)
parser.add_argument('--artefact-pattern', type=nullable_string)
parser.add_argument('--artefact-directory', type=nullable_string)
parser.add_argument('--deployment-type',
@@ -357,6 +344,7 @@ def main_cli():
args.artefact_name,
args.artefact_filename,
args.artefact_package_name,
args.artefact_pattern,
args.artefact_directory,
args.version_descriptor)
@@ -382,10 +370,6 @@ def main_cli():
save_project_description(state_file, project_description)
elif args.action == 'sync-versions':
project_description = load_project_description(state_file)
sync_versions(project_description)
elif args.action == 'publish-artefacts':
project_description = load_project_description(state_file)
publish_artefacts(project_description, args.dry_run)

View File

@@ -97,14 +97,14 @@ class Tarball:
@dataclass(frozen=True)
class WheelReleaseInfo:
filename: str
pattern: str
repository: str
version_str: str
@dataclass(frozen=True)
class Wheel:
filename: str
pattern: str
repository: str = DEFAULT_PYPI_REPOSITORY_NAME
def make_environment_variables(self, context, version):
@@ -112,7 +112,7 @@ class Wheel:
def make_release_info(self, context: ReleaseContext, version: Version):
return WheelReleaseInfo(
filename=self.filename,
pattern=self.pattern,
repository=self.repository,
version_str=python_version_str(version))
@@ -262,7 +262,7 @@ class ProjectDescription:
if self.gitea_tool is None:
return None
return self.gitea_tool.is_released(self.project_version)
return self.gitea_tool.is_released(self.planned_version)
@cached_property
def gitea_tool(self):
@@ -302,8 +302,6 @@ class ProjectDescription:
str(self.project_version),
'RELEASE_PROJECT_PLANNED_VERSION':
str(self.planned_version),
'RELEASE_PROJECT_IS_RELEASED':
'1' if self.is_released else '0',
}]
))
@@ -327,8 +325,8 @@ def parse_project_description(obj):
**optional(tar, 'repository'))
def parse_wheel(whl):
assert 'filename' in whl
return Wheel(filename=whl['filename'],
assert 'pattern' in whl
return Wheel(pattern=whl['pattern'],
**optional(whl, 'repository'))
def parse_sdist(sdist):

View File

@@ -9,8 +9,6 @@ from release.project import (DeploymentCondition, HelmRelease, HelmReleaseInfo,
SdistReleaseInfo, Tarball, TarballReleaseInfo,
Wheel, WheelReleaseInfo)
DEFAULT_PACKAGE_OWNER = 'puzzleYOU'
class Cli:
def __init__(self, dry_run: bool):
@@ -68,9 +66,8 @@ def publish_tarball(info: TarballReleaseInfo, cli: Cli):
'--upload-file', info.filename,
'-i',
'-X', 'PUT',
'%s/api/packages/%s/generic/%s/%s/%s' % (
'%s/api/packages/puzzleYOU/generic/%s/%s/%s' % ( # TODO owner
info.repository,
DEFAULT_PACKAGE_OWNER,
info.package_name,
info.version_str,
path.basename(info.filename)))
@@ -84,7 +81,7 @@ def publish_wheel(info: WheelReleaseInfo, cli: Cli):
'upload',
'--verbose',
'--repository', info.repository,
info.filename)
info.pattern)
print()
@@ -150,19 +147,19 @@ def update_helm_release(info: HelmReleaseInfo, cli: Cli):
'--version', chart_version,
'-d', td)
chart_filename = '%s/%s-%s.tgz' % (td, chart_name, chart_version)
chart_filename = '%s/%s-%s.tgz' % (td, chart_name, chart_version)
value_overrides = ','.join(
map(lambda t: '%s=%s' % (t, info.image_tag), info.image_paths))
value_overrides = ','.join(
map(lambda t: '%s=%s' % (t, info.image_tag), info.image_paths))
cli('helm',
'upgrade', info.release_name,
chart_filename,
'--version', chart_version,
'--namespace', info.namespace,
'--reuse-values',
'--set', value_overrides,
'--timeout', info.timeout)
cli('helm',
'upgrade', info.release_name,
chart_filename,
'--version', chart_version,
'--namespace', info.namespace,
'--reuse-values',
'--set', value_overrides,
'--timeout', info.timeout)
def update_deployments(project: ProjectDescription, dry_run: bool = False):

View File

@@ -19,10 +19,10 @@ artefacts:
repository: balls
- type: wheel
filename: './scratch/wheels/*.whl'
pattern: './scratch/wheels/*.whl'
- type: wheel
filename: './scratch/wheels/*.whl'
pattern: './scratch/wheels/*.whl'
repository: other
- type: sdist

View File

@@ -1,6 +1,5 @@
from os import path
from unittest import TestCase
from unittest.mock import patch
import yaml
from semver import Version
@@ -15,14 +14,6 @@ from release.project import (ArtefactDescription, DeploymentCondition,
WheelReleaseInfo, parse_project_description)
class MockGiteaTool:
def __init__(self, *args, **kwargs):
pass
def is_released(self, version):
return False
class TestProjectDescription(TestCase):
def test_can_describe_projects(self):
# resi-lib
@@ -30,7 +21,7 @@ class TestProjectDescription(TestCase):
version_descriptor='src/python/Cargo.toml',
artefacts=[
ArtefactDescription(
generated=Wheel(filename='./scratch/wheels/*.whl'))
generated=Wheel(pattern='./scratch/wheels/*.whl'))
])
# productdesignerd
@@ -55,7 +46,7 @@ class TestProjectDescription(TestCase):
ArtefactDescription(
generated=OciImage(name='masa-images')),
ArtefactDescription(
generated=Wheel(filename='./scratch/wheels/*.whl'))
generated=Wheel(pattern='./scratch/wheels/*.whl'))
],
deployments=[
DeploymentDescription(
@@ -134,7 +125,7 @@ class TestProjectDescription(TestCase):
artefacts=[
ArtefactDescription(
version_descriptor='src/python/pyproject.toml',
generated=Wheel(filename='./scratch/wheels/*.whl')),
generated=Wheel(pattern='./scratch/wheels/*.whl')),
ArtefactDescription(generated=OciImage(name='prngl')),
],
deployments=[
@@ -145,7 +136,6 @@ class TestProjectDescription(TestCase):
namespace='prngl-testing'))
])
@patch('release.project.toolkit.Gitea', MockGiteaTool)
def test_environment_variables(self):
# motacilla
desc = ProjectDescription(
@@ -194,7 +184,6 @@ class TestProjectDescription(TestCase):
'RELEASE_IMAGE_LOCAL_NAME_MOTACILLA_CDN':
'motacilla-cdn:0AB123',
'RELEASE_IS_PRERELEASE': '1',
'RELEASE_PROJECT_IS_RELEASED': '0',
'RELEASE_PROJECT_CURRENT_VERSION': '2.10.4',
'RELEASE_PROJECT_PLANNED_VERSION': '2.10.4-dev42'
}
@@ -211,9 +200,9 @@ class TestProjectDescription(TestCase):
tarball.make_release_info(None, Version(1, 2, 3, 'dev4')))
def test_wheel_release_info(self):
wheel = Wheel(filename='dist/wheels/*')
wheel = Wheel(pattern='dist/wheels/*')
self.assertEqual(
WheelReleaseInfo(filename='dist/wheels/*',
WheelReleaseInfo(pattern='dist/wheels/*',
repository='gitea',
version_str='1.2.3.dev4'),
wheel.make_release_info(None, Version(1, 2, 3, 'dev4')))
@@ -366,9 +355,9 @@ class TestProjectDescription(TestCase):
repository='balls')),
ArtefactDescription(generated=Wheel(
filename='./scratch/wheels/*.whl')),
pattern='./scratch/wheels/*.whl')),
ArtefactDescription(generated=Wheel(
filename='./scratch/wheels/*.whl', repository='other')),
pattern='./scratch/wheels/*.whl', repository='other')),
ArtefactDescription(generated=Sdist(
filename='./dist/papyru-0.0.1.tar.gz')),

View File

@@ -47,7 +47,6 @@ class Structured:
for part in item_path:
cur = cur[part]
self.filename = filename
self.format = format
self.item_path = item_path
self.content = obj

View File

@@ -1,30 +0,0 @@
name: "sync version descriptors"
description: "update all version descriptors to the planned version."
inputs: {}
runs:
using: composite
steps:
- name: declare project if neccessary
run: |
if [[ ! -z "${RELEASE_PROJECT_CURRENT_VERSION}" ]]; then
echo "already set up."
exit 0
fi
nix run ${{ github.action_path }} -- \
declare \
--release-yaml-filename ".gitea/release.yaml" \
--gitea-instance "https://gitea.puzzleyou.net" \
--release-repository-name "${{ github.repository }}" \
--release-ref-name "${{ github.ref_name }}" \
--release-run-number "${{ github.run_number }}" \
--release-commit-sha "${{ github.sha }}" \
--write-env-vars-to-filename "$GITHUB_ENV"
- name: sync versions
run: |
nix run ${{ github.action_path }} -- \
sync-versions \
--state "${RELEASE_ACTION_STATEFILE}"