Repository navigation
Expand file tree
/
Copy pathaction.yml
More file actions
155 lines (143 loc) · 5.89 KB
/
Copy pathaction.yml
File metadata and controls
155 lines (143 loc) · 5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
---
# Author: Felix Fontein <felix@fontein.de>
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or
# https://www.gnu.org/licenses/gpl-3.0.txt)
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2025, Ansible Project
name: Run Antsibull Nox
description: |-
Install Python versions, nox, antsibull-nox, and runs nox.
inputs:
python-version:
description: |-
Python-version to use. We recommend to stick to the default.
required: false
default: "3.14"
extra-python-versions:
description: |-
Newline-separated list of Python versions to install as well.
Should be used if other Python versions are needed.
required: false
default: ""
extra-args:
description: |-
Additional arguments to pass to the nox run after `--`.
required: false
default: ""
sessions:
description: |-
Nox sessions to run. By default, all sessions are run.
required: false
default: ""
working-directory:
description: |-
The directory where to run the nox sessions in.
Should be the directory where the collection's `galaxy.yml` is in, and where the `noxfile.py` is in.
required: false
default: .
change-detection:
description: |-
Whether to enable change detection.
Set to `true` to enable it.
Note that this requires the VCS configuration in `antsibull-nox.toml`,
and is not available for all kind of tests.
default: "false"
change-detection-base-branch:
description: |-
Allows to explicitly set the base branch for change detection.
default: ""
allow-unstable-changed:
description: |-
Whether the `--allow-unstable-changed` flag is passed to ansible-test integration tests.
required: false
default: "false"
output-bot-directory:
description: |-
Directory into which [ansibullbot](https://github.com/ansible-community/collection_bot/) JSON files are written.
This is passed to antsibull-nox through the `ANTSIBULL_NOX_OUTPUT_BOT_DIRECTORY` environment variable.
required: false
default: ""
output-junit-xml-path:
description: |-
Path to which a JUnit XML file is written.
This is passed to antsibull-nox through the `ANTSIBULL_NOX_OUTPUT_JUNIT_XML_PATH` environment variable.
required: false
default: ""
outputs:
run-nox:
description: Output of the 'run nox' step.
value: ${{ toJSON(steps.run-nox.outputs) }}
runs:
using: composite
steps:
- name: "Install Python ${{ inputs.python-version }}"
uses: actions/setup-python@6d4fd22b20465ccc0f7354476588e8df7c9ca0e0 # v7.1.0
id: python
with:
python-version: |-
${{ inputs.extra-python-versions }}
${{ inputs.python-version }}
- name: "Determine Python restrictions"
id: python-restrictions
env:
ANTSIBULL_NOX_EXTRA_PYTHON_VERSIONS: ${{ inputs.extra-python-versions }}
ANTSIBULL_NOX_PYTHON_VERSION: ${{ inputs.python-version }}
run: |
# Determine Python restrictions
import os
import pathlib
import shlex
FILE_APPEND_MODE = "a"
OUTPUTS_FILE_PATH = pathlib.Path(os.environ["GITHUB_OUTPUT"])
def set_output(name, value, empty_placeholder="(empty)"):
with OUTPUTS_FILE_PATH.open(FILE_APPEND_MODE) as outputs_file:
outputs_file.writelines(f"{name}={value}{os.linesep}")
print(f"Setting {name} to {value or empty_placeholder}")
python_versions = (
[version for version in os.environ["ANTSIBULL_NOX_EXTRA_PYTHON_VERSIONS"].splitlines() if version]
+ [os.environ["ANTSIBULL_NOX_PYTHON_VERSION"]]
)
python_major_version_tuples = {
tuple([int(part) for part in version.split(".", 2)[:2]]) for version in python_versions
}
# Python verions for which there are special requirements/action-X.Y.txt files
special_requirements = [
(3, 8),
]
requirements_postfix = ""
for version in special_requirements:
if any(v <= version for v in python_major_version_tuples):
requirements_postfix = f"-{version[0]}.{version[1]}"
break
set_output("requirements_file", f"requirements/action{requirements_postfix}.txt")
shell: python
- name: "Install nox and antsibull-nox"
run: | # zizmor: ignore[template-injection]
"${PYTHON_PATH}" -m pip install --disable-pip-version-check -r "${REQUIREMENTS_FILE}"
env:
PYTHON_PATH: ${{ steps.python.outputs.python-path }}
REQUIREMENTS_FILE: ${{ steps.python-restrictions.outputs.requirements_file }}
shell: bash
working-directory: ${{ github.action_path }}
- name: "Set up nox environments"
run: | # zizmor: ignore[template-injection]
nox --verbose --install-only${{ inputs.sessions && ' --sessions ' || '' }}${{ inputs.sessions }} 2>&1
env:
FORCE_COLOR: "1"
ANTSIBULL_NOX_IGNORE_INSTALLED_COLLECTIONS: "true"
shell: bash
working-directory: "${{ inputs.working-directory }}"
- name: "Run nox"
id: run-nox
run: | # zizmor: ignore[template-injection]
nox --verbose --reuse-existing-virtualenvs --no-install${{ inputs.sessions && ' --sessions ' || '' }}${{ inputs.sessions }}${{ inputs.extra-args && ' -- ' || '' }}${{ inputs.extra-args }} 2>&1
env:
FORCE_COLOR: "1"
ANTSIBULL_NOX_IGNORE_INSTALLED_COLLECTIONS: "true"
ANTSIBULL_CHANGE_DETECTION: "${{ inputs.change-detection }}"
ANTSIBULL_BASE_BRANCH: "${{ inputs.change-detection-base-branch }}"
ANTSIBULL_NOX_INTEGRATION_ALLOW_UNSTABLE_CHANGED: "${{ inputs.allow-unstable-changed }}"
ANTSIBULL_NOX_OUTPUT_BOT_DIRECTORY: "${{ inputs.output-bot-directory }}"
ANTSIBULL_NOX_OUTPUT_JUNIT_XML_PATH: "${{ inputs.output-junit-xml-path }}"
shell: bash
working-directory: "${{ inputs.working-directory }}"