-
Notifications
You must be signed in to change notification settings - Fork 0
110 lines (106 loc) · 3.75 KB
/
ci.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
name: Ansible-Link CI/CD
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
ansible-link-ci:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: set up python
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Update configuration
working-directory: ${{ github.workspace }}/src
run: |
sed -i '/^playbook_dir:/d' config.yml
sed -i '/^inventory_file:/d' config.yml
sed -i '/^job_storage_dir:/d' config.yml
sed -i '/^log_level:/d' config.yml
sed -i '/^playbook_whitelist:/d' config.yml
echo "playbook_dir: './test_playbooks'" >> config.yml
echo "inventory_file: './test_inventory.ini'" >> config.yml
echo "job_storage_dir: './test_job_storage'" >> config.yml
echo "log_level: 'DEBUG'" >> config.yml
echo "playbook_whitelist:" >> config.yml
echo " - test_.+\.yml$" >> config.yml
- name: Create test files/folders
working-directory: ${{ github.workspace }}/src
run: |
mkdir -p test_playbooks test_job_storage
touch test_inventory.ini
- name: Create test playbook
working-directory: ${{ github.workspace }}/src
run: |
cat << EOF > test_playbooks/test_playbook.yml
---
- name: Test Playbook
hosts: localhost
connection: local
tasks:
- name: Print a message
debug:
msg: "This is a test playbook"
EOF
- name: Show structure and files
working-directory: ${{ github.workspace }}/src
run: |
pwd
echo "LS --------------------"
ls -R
echo "CONFIG --------------------"
cat config.yml
echo "PLAYBOOK --------------------"
cat test_playbooks/test_playbook.yml
- name: Run tests
run: |
python -m unittest discover src
create-tag-and-release:
needs: ansible-link-ci
runs-on: ubuntu-latest
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.8'
- name: Get version
id: get_version
run: |
echo "VERSION=$(python -c "from src.version import VERSION; print(VERSION)")" >> $GITHUB_OUTPUT
- name: Create tag
run: |
git config user.name github-actions
git config user.email [email protected]
git tag -a v${{ steps.get_version.outputs.VERSION }} -m "Release version ${{ steps.get_version.outputs.VERSION }}"
git push origin v${{ steps.get_version.outputs.VERSION }}
- name: Create zip artifact
run: |
(cd src && zip -r ../ansible-link-${{ steps.get_version.outputs.VERSION }}.zip . -x "*.pyc" "*__pycache__*" "*test_*")
zip -j ansible-link-${{ steps.get_version.outputs.VERSION }}.zip requirements.txt
- name: Create hash file
run: |
find src -type f -exec sha256sum {} + > ansible-link-${{ steps.get_version.outputs.VERSION }}.sha256
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: v${{ steps.get_version.outputs.VERSION }}
name: Release ${{ steps.get_version.outputs.VERSION }}
body_path: ${{ github.workspace }}/CHANGELOG.md
files: |
ansible-link-${{ steps.get_version.outputs.VERSION }}.zip
ansible-link-${{ steps.get_version.outputs.VERSION }}.sha256
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}