generated from ansible-collections/collection_template
-
Notifications
You must be signed in to change notification settings - Fork 130
130 lines (111 loc) · 4.17 KB
/
import-galaxy.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
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
---
# 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: import-galaxy
'on':
# Run CI against all pushes (direct commits, also merged PRs) to main, and all Pull Requests
push:
branches:
- main
- stable-*
pull_request:
jobs:
build-collection:
name: Build collection artifact
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v4
with:
path: ./checkout
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install ansible-core devel
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
- name: Make sure galaxy.yml has version entry
shell: python
id: collection-metadata
run: |
import os
import yaml
def set_output(name, value):
with open(os.environ['GITHUB_OUTPUT'], 'a', encoding='utf-8') as f:
f.write(f'{name}={value}{os.linesep}')
# Make sure galaxy.yml contains a version
with open('galaxy.yml', 'rb') as f:
data = yaml.safe_load(f) ;
data['version'] = data.get('version') or '0.0.1'
with open('galaxy.yml', 'w', encoding='utf-8') as f:
f.write(yaml.dump(data))
# Create Galaxy requirements file
if data.get('dependencies'):
reqs = dict(collections=[])
for collection, version in sorted(data['dependencies'].items()):
reqs['collections'].append(dict(
name=collection,
source='https://galaxy.ansible.com',
version=version,
))
with open('../requirements.yml', 'w', encoding='utf-8') as f:
f.write(yaml.dump(reqs))
# Extract namespace and collection name
set_output('name', data['name'])
set_output('namespace', data['namespace'])
set_output('version', data['version'])
set_output('filename', f"{data['namespace']}-{data['name']}-{data['version']}.tar.gz")
working-directory: ./checkout
- name: Build collection
run: ansible-galaxy collection build
working-directory: ./checkout
- name: Copy artifact into subdirectory
shell: bash
run: |
set -e
mkdir artifact
mv checkout/${{ steps.collection-metadata.outputs.filename }} artifact/
if [ -f requirements.yml ]; then
mv requirements.yml artifact/
fi
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: collection-build-${{ github.sha }}
path: ./artifact/
import-galaxy:
name: Import artifact with Galaxy importer
runs-on: ubuntu-latest
needs:
- build-collection
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
# Currently requirements-parser is incompatible with Python 3.12
# (https://github.com/madpah/requirements-parser/issues/88), so we
# have to stick to Python 3.11 for now...
python-version: '3.11'
- name: Install ansible-core devel
run: pip install https://github.com/ansible/ansible/archive/devel.tar.gz --disable-pip-version-check
- name: Install galaxy-importer
run: pip install galaxy-importer --disable-pip-version-check
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: collection-build-${{ github.sha }}
- name: List files
shell: bash
run: |
ls -la
- name: Install collection dependencies
shell: bash
run: |
if [ -f requirements.yml ]; then
ansible-galaxy collection install --pre --requirements-file requirements.yml
else
echo "Collection has no dependencies."
fi
- name: Run Galaxy importer
run: python -m galaxy_importer.main *-*-*.tar.gz