Release to Ansible Galaxy #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: Release on Ansible Galaxy | |
on: | |
workflow_dispatch: | |
jobs: | |
readme: | |
runs-on: ubuntu-latest | |
name: Update Versions | |
if: github.repository == 'mozebaltyk/rkub' | |
permissions: | |
actions: write | |
checks: write | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Update Readme and changelog | |
uses: ./.github/actions/update-readme | |
release: | |
runs-on: ubuntu-latest | |
name: Release to Galaxy | |
if: github.repository == 'mozebaltyk/rkub' | |
permissions: | |
actions: write | |
checks: write | |
contents: write | |
deployments: write | |
packages: write | |
pages: write | |
outputs: | |
tag_version: ${{ steps.get_version.outputs.TAG_VERSION }} | |
steps: | |
# Release | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- run: git pull | |
- name: Set up Python | |
uses: actions/setup-python@v5 | |
with: | |
python-version: "3.10" | |
cache: 'pip' | |
cache-dependency-path: '**/ee-requirements.txt' | |
- name: Get current version | |
id: get_version | |
run: echo "TAG_VERSION=$(yq -r .version galaxy.yml)" >> $GITHUB_OUTPUT | |
- name: Check if tag exists | |
id: check_tag | |
run: echo "TAG_EXISTS=$(git tag | grep ${{ steps.get_version.outputs.TAG_VERSION }})" >> $GITHUB_OUTPUT | |
- name: Fail if tag exists | |
env: | |
tag_version: ${{ steps.get_version.outputs.TAG_VERSION }} | |
tag_exists: ${{ steps.check_tag.outputs.TAG_EXISTS }} | |
if: ${{ steps.get_version.outputs.TAG_VERSION == steps.check_tag.outputs.TAG_EXISTS }} | |
uses: actions/github-script@v3 | |
with: | |
script: | | |
core.setFailed('Release tag already exists in git (tag_exists var: ${tag_exists} and tag_version: ${tag_version})') | |
# Build and push to Galaxy | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install ansible-core antsibull | |
sudo apt --fix-missing update | |
sudo apt install -y sed hub | |
- name: Build collection | |
run: | | |
ansible-galaxy collection build . | |
- name: Publish collection | |
env: | |
ANSIBLE_GALAXY_API_KEY: ${{ secrets.ANSIBLE_GALAXY_API_KEY }} | |
run: | | |
ansible-galaxy collection publish *.tar.gz --api-key $ANSIBLE_GALAXY_API_KEY | |
# GH tag and release | |
- name: Create release tag | |
run: | | |
git config user.name github-actions | |
git config user.email [email protected] | |
git tag -a ${{ steps.get_version.outputs.TAG_VERSION }} -m "$(cat CHANGELOG.md)" || echo "No changes to commit" | |
git push origin --tags | |
- name: Publish Release | |
uses: softprops/action-gh-release@v1 | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
tag_name: ${{ steps.get_version.outputs.TAG_VERSION }} | |
files: "*.tar.gz" | |
body_path: CHANGELOG.md |