-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (100 loc) · 4.07 KB
/
main.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
name: CI
on:
push:
jobs:
build:
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION="$(echo $GITHUB_REF | sed -e 's:refs/tags/::')"
else
VERSION=0.0.0
fi &&\
echo VERSION=$VERSION &&\
sudo apt-get install -y python3-setuptools &&\
python3 -m pip install ansible &&\
TEMPDIR=`mktemp -d` &&\
cp -r plugins LICENSE README.md $TEMPDIR/ &&\
sed "s/0.0.0/${VERSION}/" galaxy.yml > $TEMPDIR/galaxy.yml &&\
ansible-galaxy collection build --output-path output $TEMPDIR &&\
rm -rf $TEMPDIR &&\
tar -tzvf output/kamatera-kamatera-$VERSION.tar.gz
- uses: actions/upload-artifact@v1
with:
name: build
path: output
tests:
runs-on: ${{ matrix.os }}
needs: build
strategy:
matrix:
os: [ubuntu-16.04, ubuntu-18.04]
install_type: [package, pip2, pip3, pip2-dev, pip3-dev]
steps:
- uses: actions/checkout@v2
- uses: actions/download-artifact@v1
with:
name: build
- env:
KAMATERA_API_CLIENT_ID: ${{ secrets.KAMATERA_API_CLIENT_ID }}
KAMATERA_API_SECRET: ${{ secrets.KAMATERA_API_SECRET }}
INSTALL_TYPE: ${{ matrix.install_type }}
OS: ${{ matrix.os }}
run: |
if [ "${INSTALL_TYPE}" == "package" ]; then
sudo apt update && sudo apt install -y software-properties-common &&\
sudo apt-add-repository --yes --update ppa:ansible/ansible &&\
sudo apt install -y ansible
elif [ "${INSTALL_TYPE}" == "pip2" ]; then
sudo apt-get install -y python-setuptools python-wheel &&\
python2 -m pip install ansible
elif [ "${INSTALL_TYPE}" == "pip3" ]; then
sudo apt-get install -y python3-setuptools python3-wheel &&\
python3 -m pip install ansible
elif [ "${INSTALL_TYPE}" == "pip2-dev" ]; then
sudo apt-get install -y python-setuptools python-wheel &&\
python2 -m pip install git+https://github.com/ansible/ansible.git@devel
elif [ "${INSTALL_TYPE}" == "pip3-dev" ]; then
sudo apt-get install -y python3-setuptools python3-wheel &&\
python3 -m pip install git+https://github.com/ansible/ansible.git@devel
fi &&\
ansible-galaxy collection install `ls build/kamatera-kamatera-*.tar.gz` &&\
if [ "${OS}" == "ubuntu-18.04" ] && [ "${INSTALL_TYPE}" == "package" ]; then
tests/test_compute.sh test_ansible
else
tests/test_compute.sh
fi
publish:
runs-on: ubuntu-18.04
needs: tests
steps:
- uses: actions/download-artifact@v1
with:
name: build
- env:
KAMATERA_MACHINE_USER_TOKEN: ${{ secrets.KAMATERA_MACHINE_USER_TOKEN }}
GALAXY_SERVER_API_KEY: ${{ secrets.GALAXY_SERVER_API_KEY }}
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
sudo apt-get install -y python3-setuptools &&\
python3 -m pip install ansible &&\
echo GITHUB_REF=$GITHUB_REF &&\
VERSION="$(echo $GITHUB_REF | sed -e 's:refs/tags/::')" &&\
echo VERSION=$VERSION &&\
FILE="build/kamatera-kamatera-${VERSION}.tar.gz" &&\
echo FILE=$FILE &&\
ansible-galaxy collection publish --api-key $GALAXY_SERVER_API_KEY $FILE &&\
RELEASE_ID="$(curl -sL https://api.github.com/repos/Kamatera/ansible-collection-kamatera/releases/tags/${VERSION} | jq -r .id)" &&\
echo RELEASE_ID=$RELEASE_ID &&\
if [ "$(curl -H "Authorization: token $KAMATERA_MACHINE_USER_TOKEN" \
-H "Content-Type: $(file -b --mime-type $FILE)" \
--data-binary @$FILE \
"https://uploads.github.com/repos/Kamatera/ansible-collection-kamatera/releases/${RELEASE_ID}/assets?name=$(basename $FILE)" | tee /dev/stderr | jq -r .state)" == "uploaded" ]; then
echo Release asset uploaded successfuly
else
echo Failed to upload release asset
exit 1
fi
fi