-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathbuild-collection
executable file
·52 lines (40 loc) · 1.63 KB
/
build-collection
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
#!/bin/bash
set -eux
# Construct our Ansible Collection in a temporary "_build" directory.
TOPDIR=$(dirname "$(readlink -f "$0")")
cd $TOPDIR
rm -rf _build
mkdir _build
cd _build
mkdir plugins
cp $TOPDIR/COPYING .
cp -r $TOPDIR/meta/ .
cp -r $TOPDIR/library/ plugins/modules
cp -r $TOPDIR/module_utils/ plugins/module_utils/
# Make our common_koji imports compatible with Ansible Collections.
sed -i \
-e 's/from ansible.module_utils import common_koji/from ansible_collections.ktdreyer.koji_ansible.plugins.module_utils import common_koji/' \
-e 's/from ansible.module_utils.common_koji import /from ansible_collections.ktdreyer.koji_ansible.plugins.module_utils.common_koji import /' \
plugins/modules/*.py
# Sanity-check that we converted everything:
set +x
IMPORTS=$(grep "import " plugins/modules/*.py)
COMMON_KOJI_IMPORTS=$(echo $IMPORTS | grep common_koji)
MISSED_IMPORTS=$(echo $COMMON_KOJI_IMPORTS | grep -v ansible_collections || :)
set -x
if [[ ! -z $MISSED_IMPORTS ]]; then
echo Failed to convert some files for ansible_collections:
echo $MISSED_IMPORTS
exit 1
fi
# Convert README from reStructuredText to Markdown.
# Ansible Galaxy's Markdown engine plays best with markdown_strict.
pandoc $TOPDIR/README.rst -f rst -t markdown_strict -o README.md
# Determine our semver-compatible version number from Git.
BASE_REF="${GITHUB_BASE_REF:-HEAD}"
BASE_COMMIT=$(git rev-list --max-parents=0 $BASE_REF)
COMMIT_COUNT=$(($(git rev-list --count $BASE_COMMIT..HEAD) - 1))
# Versions will always be 0.0.XXX.
VERSION="0.0.${COMMIT_COUNT}"
sed $TOPDIR/galaxy.yml -e "s/{{ version }}/$VERSION/" > galaxy.yml
ansible-galaxy collection build