-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
99 lines (87 loc) · 3.36 KB
/
action.yml
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
---
# Copyright (c) Ansible Project
# 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
name: Test to import an Ansible collection with the Galaxy importer
description: >-
This action tries to import a built Ansible collection artifact with the Ansible Galaxy importer.
author: "Felix Fontein (@felixfontein)"
inputs:
artifact-path:
description: >-
Path to the collection's build artifact (tarball).
required: true
python-version:
description: >-
The Python version to use.
default: '3.13'
ansible-core-version:
description: >-
The branch of tag name of ansible-core to install.
This is assumed to exist in https://github.com/ansible/ansible.
default: 'stable-2.18'
collection-requirements-path:
description: >-
Path to a Galaxy requirements file. If present, these collections will be installed.
importer-config-path:
description: >-
Path to a Galaxy importer configuration file.
See https://github.com/ansible/galaxy-importer#configuration for more information.
runs:
using: composite
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ inputs.python-version }}
- name: Install ansible-core
shell: bash
env:
ANSIBLE_CORE_VERSION: ${{ inputs.ansible-core-version }}
run: pip install "https://github.com/ansible/ansible/archive/${ANSIBLE_CORE_VERSION}.tar.gz" --disable-pip-version-check
- name: Install galaxy-importer
shell: bash
run: pip install galaxy-importer --disable-pip-version-check
- name: Install collection dependencies
if: >-
!!inputs.collection-requirements-path
shell: bash
env:
COLLECTION_REQUIREMENTS_PATH: ${{ inputs.collection-requirements-path }}
run: |
ansible-galaxy collection install --pre --requirements-file "${COLLECTION_REQUIREMENTS_PATH}"
- name: Preparations
id: preparations
env:
ARTIFACT_PATH: ${{ inputs.artifact-path }}
IMPORTER_CONFIG_PATH: ${{ inputs.importer-config-path }}
shell: python
run: |
# Preparations
import os
import shlex
def set_output(name, value):
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as f:
f.write(f'{name}={value}{os.linesep}')
artifact_path = os.environ['ARTIFACT_PATH']
importer_config_path = os.environ['IMPORTER_CONFIG_PATH']
command = ['python', '-m', 'galaxy_importer.main', artifact_path]
if importer_config_path:
command.insert(0, f'GALAXY_IMPORTER_CONFIG={importer_config_path}')
set_output('command', shlex.join(command))
- name: Run Galaxy importer
shell: bash
env:
ARTIFACT_PATH: ${{ inputs.artifact-path }}
run: |
${{ steps.preparations.outputs.command }} | tee import.log
- name: Analyze result
shell: python
run: |
# Analyze result
error_prefix = 'ERROR:'
with open('import.log', 'r', encoding='utf-8') as f:
for line in f:
if line.startswith(error_prefix):
msg = line[len(error_prefix):].strip()
print(f"::warning::Galaxy importer emitted the following non-fatal error: {msg}")