Merge pull request #1 from lfkdev/develop #22
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Create config file | |
run: | | |
echo "playbook_dir: ./test_playbooks" > ansible_link/config.yml | |
echo "inventory_file: ./test_inventory.ini" >> ansible_link/config.yml | |
echo "job_storage_dir: ./test_job_storage" >> ansible_link/config.yml | |
mkdir -p test_playbooks test_job_storage | |
touch test_inventory.ini | |
- name: Create test playbook | |
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: Set PYTHONPATH and ANSIBLE_API_CONFIG | |
run: | | |
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> $GITHUB_ENV | |
echo "ANSIBLE_API_CONFIG=$GITHUB_WORKSPACE/ansible_link/config.yml" >> $GITHUB_ENV | |
- name: Show structure and environment | |
run: | | |
ls -R | |
echo "PYTHONPATH: $PYTHONPATH" | |
echo "ANSIBLE_API_CONFIG: $ANSIBLE_API_CONFIG" | |
pip list | |
cat test_playbooks/test_playbook.yml | |
- name: Update import in ansible_link.py | |
run: | | |
sed -i 's/from webhook import WebhookSender/from ansible_link.webhook import WebhookSender/' ansible_link/ansible_link.py | |
sed -i 's/from version import VERSION/from ansible_link.version import VERSION/' ansible_link/ansible_link.py | |
- name: Run tests | |
run: | | |
python -m unittest discover tests | |
build-artifact: | |
needs: ansible-link-ci | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.8' | |
- name: Get version | |
id: get_version | |
run: | | |
echo "VERSION=$(python -c "from ansible_link.version import VERSION; print(VERSION)")" >> $GITHUB_ENV | |
- name: Create zip artifact | |
run: | | |
zip -r ansible-link-${{ env.VERSION }}.zip ansible_link -x "*.pyc" "*__pycache__*" | |
- name: Create hash file | |
run: | | |
sha256sum ansible-link-${{ env.VERSION }}.zip > ansible-link-${{ env.VERSION }}.sha256 | |
- name: Upload artifact | |
uses: actions/upload-artifact@v2 | |
with: | |
name: ansible-link-${{ env.VERSION }} | |
path: | | |
ansible-link-${{ env.VERSION }}.zip | |
ansible-link-${{ env.VERSION }}.sha256 | |
- name: Create GitHub Release | |
id: create_release | |
uses: actions/create-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: v${{ env.VERSION }} | |
release_name: Release ${{ env.VERSION }} | |
draft: false | |
prerelease: false | |
- name: Upload Release Asset | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./ansible-link-${{ env.VERSION }}.zip | |
asset_name: ansible-link-${{ env.VERSION }}.zip | |
asset_content_type: application/zip | |
- name: Upload Hash File | |
uses: actions/upload-release-asset@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
upload_url: ${{ steps.create_release.outputs.upload_url }} | |
asset_path: ./ansible-link-${{ env.VERSION }}.sha256 | |
asset_name: ansible-link-${{ env.VERSION }}.sha256 | |
asset_content_type: text/plain |