mirror of
https://github.com/saltstack/salt.git
synced 2025-04-15 09:10:20 +00:00
Add, and use, the setup-salt-version
action
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
a9c2dc5dd9
commit
4315342238
5 changed files with 128 additions and 8 deletions
21
.github/actions/setup-salt-version/action.yml
vendored
Normal file
21
.github/actions/setup-salt-version/action.yml
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
name: setup-salt-version
|
||||
description: Setup Salt Version
|
||||
inputs:
|
||||
salt-version:
|
||||
type: string
|
||||
default: ""
|
||||
description: >
|
||||
The Salt version to set prior to running tests or building packages.
|
||||
If not set, it is discover at run time, like, for example, capturing
|
||||
the output of running `python3 salt/version.py`
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
|
||||
steps:
|
||||
|
||||
- name: Setup Salt Version
|
||||
shell: bash
|
||||
run: |
|
||||
tools pkg set-salt-version ${{ inputs.salt-version }}
|
28
.github/workflows/ci.yml
vendored
28
.github/workflows/ci.yml
vendored
|
@ -8,6 +8,13 @@ on:
|
|||
- cron: '0 */8 * * *' # Run every 8 hours
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
salt-version:
|
||||
type: string
|
||||
default: ""
|
||||
description: >
|
||||
The Salt version to set prior to running tests or building packages.
|
||||
If not set, it is discover at run time, like, for example, capturing
|
||||
the output of running `python3 salt/version.py`
|
||||
testrun-type:
|
||||
description: Type of test run
|
||||
required: true
|
||||
|
@ -94,14 +101,6 @@ jobs:
|
|||
- *salt_added_modified
|
||||
- *tests_added_modified
|
||||
|
||||
- name: Write Changed Files To A Local File
|
||||
run:
|
||||
echo '${{ toJSON(steps.changed-files.outputs) }}' > changed-files.json
|
||||
|
||||
- name: Check Local Changed Files Contents
|
||||
run:
|
||||
cat changed-files.json
|
||||
|
||||
- name: Set up Python 3.10
|
||||
uses: actions/setup-python@v4
|
||||
with:
|
||||
|
@ -110,6 +109,19 @@ jobs:
|
|||
- name: Setup Python Tools Scripts
|
||||
uses: ./.github/actions/setup-python-tools-scripts
|
||||
|
||||
- name: Setup Salt Version
|
||||
uses: ./.github/actions/setup-salt-version
|
||||
with:
|
||||
salt-version: "${{ inputs.salt-version }}"
|
||||
|
||||
- name: Write Changed Files To A Local File
|
||||
run:
|
||||
echo '${{ toJSON(steps.changed-files.outputs) }}' > changed-files.json
|
||||
|
||||
- name: Check Local Changed Files Contents
|
||||
run:
|
||||
cat changed-files.json
|
||||
|
||||
- name: Process Changed Files
|
||||
id: process-changed-files
|
||||
run:
|
||||
|
|
5
setup.py
5
setup.py
|
@ -233,6 +233,11 @@ class WriteSaltVersion(Command):
|
|||
salt_version = SaltStackVersion.parse(
|
||||
self.distribution.with_salt_version
|
||||
)
|
||||
if os.path.exists(self.distribution.salt_version_hardcoded_path):
|
||||
log.warn(
|
||||
"The 'salt/_version.txt' file already exists. Not overwriting it."
|
||||
)
|
||||
return
|
||||
|
||||
with open(
|
||||
self.distribution.salt_version_hardcoded_path, "w", encoding="utf-8"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import logging
|
||||
|
||||
import tools.ci
|
||||
import tools.pkg
|
||||
import tools.vm
|
||||
|
||||
for name in ("boto3", "botocore", "urllib3"):
|
||||
|
|
81
tools/pkg.py
Normal file
81
tools/pkg.py
Normal file
|
@ -0,0 +1,81 @@
|
|||
"""
|
||||
These commands are used to build Salt packages.
|
||||
"""
|
||||
# pylint: disable=resource-leakage,broad-except
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import pathlib
|
||||
import shutil
|
||||
|
||||
from ptscripts import Context, command_group
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
REPO_ROOT = pathlib.Path(__file__).resolve().parent.parent
|
||||
|
||||
# Define the command group
|
||||
pkg = command_group(name="pkg", help="Packaging Related Commands", description=__doc__)
|
||||
|
||||
|
||||
@pkg.command(
|
||||
name="set-salt-version",
|
||||
arguments={
|
||||
"salt_version": {
|
||||
"help": (
|
||||
"The salt version to write to 'salt/_version.txt'. If not passed "
|
||||
"it will be discovered by running 'python3 salt/version.py'."
|
||||
),
|
||||
"nargs": "?",
|
||||
"default": None,
|
||||
},
|
||||
"overwrite": {
|
||||
"help": "Overwrite 'salt/_version.txt' if it already exists",
|
||||
},
|
||||
},
|
||||
)
|
||||
def set_salt_version(ctx: Context, salt_version: str, overwrite: bool = False):
|
||||
"""
|
||||
Write the Salt version to 'salt/_version.txt'
|
||||
"""
|
||||
salt_version_file = REPO_ROOT / "salt" / "_version.txt"
|
||||
if salt_version_file.exists():
|
||||
if not overwrite:
|
||||
ctx.error("The 'salt/_version.txt' file already exists")
|
||||
ctx.exit(1)
|
||||
salt_version_file.unlink()
|
||||
if salt_version is None:
|
||||
if not REPO_ROOT.joinpath(".git").exists():
|
||||
ctx.error(
|
||||
"Apparently not running from a Salt repository checkout. "
|
||||
"Unable to discover the Salt version."
|
||||
)
|
||||
ctx.exit(1)
|
||||
ctx.info("Discovering the Salt version...")
|
||||
ret = ctx.run(shutil.which("python3"), "salt/version.py", capture=True)
|
||||
salt_version = ret.stdout.strip().decode()
|
||||
ctx.info(f"Discovered Salt version: {salt_version!r}")
|
||||
|
||||
if not REPO_ROOT.joinpath("salt").is_dir():
|
||||
ctx.error(
|
||||
"The path 'salt/' is not a directory. Unable to write 'salt/_version.txt'"
|
||||
)
|
||||
ctx.exit(1)
|
||||
|
||||
try:
|
||||
REPO_ROOT.joinpath("salt/_version.txt").write_text(salt_version)
|
||||
except Exception as exc:
|
||||
ctx.error(f"Unable to write 'salt/_version.txt': {exc}")
|
||||
ctx.exit(1)
|
||||
|
||||
ctx.info(f"Successfuly wrote {salt_version!r} to 'salt/_version.txt'")
|
||||
|
||||
gh_env_file = os.environ.get("GITHUB_ENV", None)
|
||||
if gh_env_file is not None:
|
||||
variable_text = f"SALT_VERSION={salt_version}"
|
||||
ctx.info(f"Writing '{variable_text}' to '$GITHUB_ENV' file:", gh_env_file)
|
||||
with open(gh_env_file, "w", encoding="utf-8") as wfh:
|
||||
wfh.write(f"{variable_text}\n")
|
||||
|
||||
ctx.exit(0)
|
Loading…
Add table
Reference in a new issue