Compare commits
2 Commits
v0.0.1-dev
...
v0.0.1-dev
| Author | SHA1 | Date | |
|---|---|---|---|
| f0c94b62bf | |||
| c33b8aae0c |
@@ -1 +1 @@
|
||||
version_descriptor: setup.py
|
||||
version_descriptor: pyproject.toml
|
||||
|
||||
10
.gitea/workflows/check-is-not-released.yaml
Normal file
10
.gitea/workflows/check-is-not-released.yaml
Normal file
@@ -0,0 +1,10 @@
|
||||
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
|
||||
@@ -67,6 +67,26 @@ 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:
|
||||
@@ -80,6 +100,7 @@ jobs:
|
||||
with:
|
||||
dry_run: true
|
||||
configure_runner_environment: false
|
||||
sync_versions: false
|
||||
|
||||
- run: set -u; echo "$RELEASE_PROJECT_CURRENT_VERSION"
|
||||
|
||||
|
||||
@@ -33,15 +33,11 @@ runs:
|
||||
run: |
|
||||
set +e
|
||||
|
||||
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
|
||||
if [[ "$RELEASE_PROJECT_IS_RELEASED" = "1" ]]; 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."
|
||||
|
||||
@@ -104,6 +104,11 @@ 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 }}" \
|
||||
|
||||
23
flake.lock
generated
23
flake.lock
generated
@@ -34,10 +34,31 @@
|
||||
"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"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"pyproject-nix": "pyproject-nix"
|
||||
}
|
||||
},
|
||||
"systems": {
|
||||
|
||||
49
flake.nix
49
flake.nix
@@ -4,52 +4,41 @@
|
||||
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, ... }:
|
||||
outputs = { self, nixpkgs, flake-utils, pyproject-nix }:
|
||||
flake-utils.lib.eachDefaultSystem (system:
|
||||
let
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
|
||||
python = pkgs.python313.withPackages (ps: with ps; [
|
||||
isort
|
||||
flake8
|
||||
semver
|
||||
toml
|
||||
requests
|
||||
pyyaml
|
||||
packaging
|
||||
]);
|
||||
|
||||
pythonPackage = pkgs.python3Packages.buildPythonPackage {
|
||||
name = "release-action";
|
||||
src = ./.;
|
||||
pythonProject = pyproject-nix.lib.project.loadPyproject {
|
||||
projectRoot = ./.;
|
||||
};
|
||||
|
||||
pythonInterpreter = pkgs.python313;
|
||||
in
|
||||
{
|
||||
devShells.default = pkgs.mkShell {
|
||||
buildInputs = [
|
||||
pkgs.envsubst
|
||||
pkgs.just
|
||||
pkgs.gitea-actions-runner
|
||||
python
|
||||
(pythonInterpreter.withPackages
|
||||
(pythonProject.renderers.withPackages {
|
||||
python = pythonInterpreter;
|
||||
extraPackages = ps: with ps; [ flake8 isort ];
|
||||
}))
|
||||
];
|
||||
};
|
||||
|
||||
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)
|
||||
;
|
||||
packages.default = pythonInterpreter.pkgs.buildPythonPackage (
|
||||
pythonProject.renderers.buildPythonPackage {
|
||||
python = pythonInterpreter;
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
9
justfile
9
justfile
@@ -34,7 +34,10 @@ test-workflows:
|
||||
--image "-self-hosted" \
|
||||
--event pull_request \
|
||||
--workflows ./.gitea/workflows/check.yaml \
|
||||
--job test-sync-versions
|
||||
--job test-skip-release-if-already-released
|
||||
|
||||
# TODO
|
||||
# --image "europe-docker.pkg.dev/puzzle-and-play/docker/action-runner-job:latest" \
|
||||
act_runner exec \
|
||||
--image "-self-hosted" \
|
||||
--event pull_request \
|
||||
--workflows ./.gitea/workflows/check.yaml \
|
||||
--job test-sync-versions
|
||||
|
||||
16
pyproject.toml
Normal file
16
pyproject.toml
Normal file
@@ -0,0 +1,16 @@
|
||||
[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"
|
||||
@@ -18,7 +18,7 @@ inputs:
|
||||
|
||||
sync_versions:
|
||||
required: false
|
||||
default: false
|
||||
default: true
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
@@ -43,18 +43,28 @@ 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: inputs.sync_versions == 'true'
|
||||
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: inputs.build_run != ''
|
||||
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 \
|
||||
@@ -62,6 +72,7 @@ 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 \
|
||||
@@ -69,6 +80,7 @@ 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
6
setup.py
@@ -1,6 +0,0 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='release-action',
|
||||
version='0.0.1.dev0',
|
||||
)
|
||||
@@ -248,7 +248,7 @@ def sync_versions(project_description: ProjectDescription):
|
||||
sync(artefact.version_descriptor)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
def main_cli():
|
||||
parser = ArgumentParser()
|
||||
parser.add_argument('action', choices=[
|
||||
'declare',
|
||||
|
||||
@@ -262,7 +262,7 @@ class ProjectDescription:
|
||||
if self.gitea_tool is None:
|
||||
return None
|
||||
|
||||
return self.gitea_tool.is_released(self.planned_version)
|
||||
return self.gitea_tool.is_released(self.project_version)
|
||||
|
||||
@cached_property
|
||||
def gitea_tool(self):
|
||||
@@ -302,6 +302,8 @@ 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',
|
||||
}]
|
||||
))
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from os import path
|
||||
from unittest import TestCase
|
||||
from unittest.mock import patch
|
||||
|
||||
import yaml
|
||||
from semver import Version
|
||||
@@ -14,6 +15,14 @@ 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
|
||||
@@ -136,6 +145,7 @@ class TestProjectDescription(TestCase):
|
||||
namespace='prngl-testing'))
|
||||
])
|
||||
|
||||
@patch('release.project.toolkit.Gitea', MockGiteaTool)
|
||||
def test_environment_variables(self):
|
||||
# motacilla
|
||||
desc = ProjectDescription(
|
||||
@@ -184,6 +194,7 @@ 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'
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ class Structured:
|
||||
for part in item_path:
|
||||
cur = cur[part]
|
||||
|
||||
self.filename = filename
|
||||
self.format = format
|
||||
self.item_path = item_path
|
||||
self.content = obj
|
||||
|
||||
Reference in New Issue
Block a user