1 Commits

Author SHA1 Message Date
27857def4b WIP
All checks were successful
run tests / check (push) Successful in 24s
run tests / release (push) Successful in 15s
2025-12-10 06:42:53 +01:00
16 changed files with 60 additions and 150 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

@@ -67,26 +67,6 @@ jobs:
with: with:
configure_runner_environment: false 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: test-declare-with-release-yaml:
runs-on: action-runner runs-on: action-runner
steps: steps:
@@ -100,7 +80,6 @@ jobs:
with: with:
dry_run: true dry_run: true
configure_runner_environment: false configure_runner_environment: false
sync_versions: false
- run: set -u; echo "$RELEASE_PROJECT_CURRENT_VERSION" - run: set -u; echo "$RELEASE_PROJECT_CURRENT_VERSION"

View File

@@ -33,11 +33,15 @@ runs:
run: | run: |
set +e 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" VERSION="$RELEASE_PROJECT_CURRENT_VERSION"
echo "Project is already released with version ${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 exit -1
else else
echo "Project is not yet released." echo "Project is not yet released."

View File

@@ -104,11 +104,6 @@ runs:
- name: declare release project - name: declare release project
run: | run: |
if [[ ! -z "${RELEASE_PROJECT_CURRENT_VERSION}" ]]; then
echo "already set up."
exit 0
fi
nix run ${{ github.action_path }} -- \ nix run ${{ github.action_path }} -- \
declare \ declare \
--release-yaml-filename "${{ inputs.filename }}" \ --release-yaml-filename "${{ inputs.filename }}" \

23
flake.lock generated
View File

@@ -34,31 +34,10 @@
"type": "github" "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": { "root": {
"inputs": { "inputs": {
"flake-utils": "flake-utils", "flake-utils": "flake-utils",
"nixpkgs": "nixpkgs", "nixpkgs": "nixpkgs"
"pyproject-nix": "pyproject-nix"
} }
}, },
"systems": { "systems": {

View File

@@ -4,23 +4,22 @@
inputs = { inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05"; nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
flake-utils.url = "github:numtide/flake-utils"; 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: flake-utils.lib.eachDefaultSystem (system:
let let
pkgs = import nixpkgs { inherit system; }; pkgs = import nixpkgs { inherit system; };
pythonProject = pyproject-nix.lib.project.loadPyproject { python = pkgs.python313.withPackages (ps: with ps; [
projectRoot = ./.; isort
}; flake8
semver
pythonInterpreter = pkgs.python313; toml
requests
pyyaml
packaging
]);
pythonPackage = pkgs.python3Packages.buildPythonPackage { pythonPackage = pkgs.python3Packages.buildPythonPackage {
name = "release-action"; name = "release-action";
@@ -33,18 +32,24 @@
pkgs.envsubst pkgs.envsubst
pkgs.just pkgs.just
pkgs.gitea-actions-runner pkgs.gitea-actions-runner
(pythonInterpreter.withPackages python
(pythonProject.renderers.withPackages {
python = pythonInterpreter;
extraPackages = ps: with ps; [ flake8 isort ];
}))
]; ];
}; };
packages.default = pythonInterpreter.pkgs.buildPythonPackage ( packages.default = pkgs.writers.writePython3Bin
pythonProject.renderers.buildPythonPackage { "release-action"
python = pythonInterpreter; {
}); 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,11 @@ test-workflows:
--workflows ./.gitea/workflows/check.yaml \ --workflows ./.gitea/workflows/check.yaml \
--job test-is-not-yet-released --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 \ act_runner exec \
--image "-self-hosted" \ --image "-self-hosted" \
--event pull_request \ --event pull_request \
--workflows ./.gitea/workflows/check.yaml \ --workflows ./.gitea/workflows/check.yaml \
--job test-sync-versions --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

@@ -18,7 +18,7 @@ inputs:
sync_versions: sync_versions:
required: false required: false
default: true default: false
runs: runs:
using: composite using: composite
@@ -43,28 +43,18 @@ runs:
--release-commit-sha "${{ github.sha }}" \ --release-commit-sha "${{ github.sha }}" \
--write-env-vars-to-filename "$GITHUB_ENV" --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 - name: sync versions
if: ${{ steps.check_released.outputs.is_released == '0' && inputs.sync_versions == 'true' }} if: inputs.sync_versions == 'true'
run: | run: |
nix run ${{ github.action_path }} -- \ nix run ${{ github.action_path }} -- \
sync-versions \ sync-versions \
--state "${RELEASE_ACTION_STATEFILE}" --state "${RELEASE_ACTION_STATEFILE}"
- name: run build commands - name: run build commands
if: ${{ steps.check_released.outputs.is_released == '0' && inputs.build_run != '' }} if: inputs.build_run != ''
run: ${{ inputs.build_run }} run: ${{ inputs.build_run }}
- name: publish artefacts - name: publish artefacts
if: ${{ steps.check_released.outputs.is_released == '0' }}
run: | run: |
nix run ${{ github.action_path }} -- \ nix run ${{ github.action_path }} -- \
publish-artefacts \ publish-artefacts \
@@ -72,7 +62,6 @@ runs:
--dry-run "${{ inputs.dry_run }}" --dry-run "${{ inputs.dry_run }}"
- name: update deployments - name: update deployments
if: ${{ steps.check_released.outputs.is_released == '0' }}
run: | run: |
nix run ${{ github.action_path }} -- \ nix run ${{ github.action_path }} -- \
update-deployments \ update-deployments \
@@ -80,7 +69,6 @@ runs:
--dry-run "${{ inputs.dry_run }}" --dry-run "${{ inputs.dry_run }}"
- name: create release - name: create release
if: ${{ steps.check_released.outputs.is_released == '0' }}
run: | run: |
nix run ${{ github.action_path }} -- \ nix run ${{ github.action_path }} -- \
create-release \ 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

@@ -248,7 +248,7 @@ def sync_versions(project_description: ProjectDescription):
sync(artefact.version_descriptor) sync(artefact.version_descriptor)
def main_cli(): if __name__ == '__main__':
parser = ArgumentParser() parser = ArgumentParser()
parser.add_argument('action', choices=[ parser.add_argument('action', choices=[
'declare', 'declare',

View File

@@ -262,7 +262,7 @@ class ProjectDescription:
if self.gitea_tool is None: if self.gitea_tool is None:
return None return None
return self.gitea_tool.is_released(self.project_version) return self.gitea_tool.is_released(self.planned_version)
@cached_property @cached_property
def gitea_tool(self): def gitea_tool(self):
@@ -302,8 +302,6 @@ class ProjectDescription:
str(self.project_version), str(self.project_version),
'RELEASE_PROJECT_PLANNED_VERSION': 'RELEASE_PROJECT_PLANNED_VERSION':
str(self.planned_version), str(self.planned_version),
'RELEASE_PROJECT_IS_RELEASED':
'1' if self.is_released else '0',
}] }]
)) ))

View File

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

View File

@@ -1,6 +1,5 @@
from os import path from os import path
from unittest import TestCase from unittest import TestCase
from unittest.mock import patch
import yaml import yaml
from semver import Version from semver import Version
@@ -15,14 +14,6 @@ from release.project import (ArtefactDescription, DeploymentCondition,
WheelReleaseInfo, parse_project_description) WheelReleaseInfo, parse_project_description)
class MockGiteaTool:
def __init__(self, *args, **kwargs):
pass
def is_released(self, version):
return False
class TestProjectDescription(TestCase): class TestProjectDescription(TestCase):
def test_can_describe_projects(self): def test_can_describe_projects(self):
# resi-lib # resi-lib
@@ -145,7 +136,6 @@ class TestProjectDescription(TestCase):
namespace='prngl-testing')) namespace='prngl-testing'))
]) ])
@patch('release.project.toolkit.Gitea', MockGiteaTool)
def test_environment_variables(self): def test_environment_variables(self):
# motacilla # motacilla
desc = ProjectDescription( desc = ProjectDescription(
@@ -194,7 +184,6 @@ class TestProjectDescription(TestCase):
'RELEASE_IMAGE_LOCAL_NAME_MOTACILLA_CDN': 'RELEASE_IMAGE_LOCAL_NAME_MOTACILLA_CDN':
'motacilla-cdn:0AB123', 'motacilla-cdn:0AB123',
'RELEASE_IS_PRERELEASE': '1', 'RELEASE_IS_PRERELEASE': '1',
'RELEASE_PROJECT_IS_RELEASED': '0',
'RELEASE_PROJECT_CURRENT_VERSION': '2.10.4', 'RELEASE_PROJECT_CURRENT_VERSION': '2.10.4',
'RELEASE_PROJECT_PLANNED_VERSION': '2.10.4-dev42' 'RELEASE_PROJECT_PLANNED_VERSION': '2.10.4-dev42'
} }

View File

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