Skip to content

Release and Publish Ansible Collection #8

Release and Publish Ansible Collection

Release and Publish Ansible Collection #8

name: Release and Publish Ansible Collection
on:
workflow_dispatch:
jobs:
release:
runs-on: ubuntu-latest
steps:
- name: Checkout stable-10 Branch
uses: actions/checkout@v4
with:
ref: stable-10
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.x'
- name: Install Dependencies
run: |
pip install ansible antsibull-changelog
- name: Extract Collection Version
id: extract_version
run: |
# Extract the version from galaxy.yml (assumes the line "version: <value>" exists)
version=$(grep "^version:" galaxy.yml | awk '{print $2}')
echo "Collection version: $version"
echo "version=$version" >> $GITHUB_OUTPUT
- name: Create GitHub Release
id: create_release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.extract_version.outputs.version }}
name: ${{ steps.extract_version.outputs.version }}
body_path: CHANGELOG.md
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Build Ansible Collection
run: ansible-galaxy collection build --force
- name: Publish to Ansible Galaxy
run: |
# The tarball name follows the <namespace>-<collection>-<version>.tar.gz convention.
tarball=$(find . -maxdepth 1 -name '*.tar.gz' | head -n 1)
echo "Publishing collection tarball: $tarball"
ansible-galaxy collection publish "$tarball" --api-key $ANSIBLE_GALAXY_API_KEY
env:
ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }}